cli is a toolkit for rapidly building command line apps - it includes:
npm install cli or just bundle cli.js with your app.
Try it out
$ ./sort.js < input.txt
Let's add support for an
-n switch to use a numeric sort, and a
-r switch to reverse output - only 5 extra lines of code (!)
var cli = options = cli;cli;
cli takes an object as a map for the arguments you wish to parse.
Each property/key in the object is the long version of the argument i.e. --file
The array associated with it is the options to apply to that argument.
cli has methods that collect stdin (newline is auto-detected as \n or \r\n)
cli; //callback receives stdin as a stringcli; //callback receives stdin split into an array of lines (lines, newline)
cli also has a lower level method for working with input line by line (see ./examples/cat.js for an example).
file can be omitted if you want to work with stdin
//cli.toType(object); If a Built-in type, returns the name of the type as a lower cased Stringcli; // 'array'cli; // 'date'cli; // 'integer'cli; // 'float'cli; // 'math'cli; // 'regex'cli; // 'json'
To output a progress bar, call
cli; //Where 0 <= progress <= 1
To spawn a child process, use
cli; //callback receives the output of the process (split into lines)
Plugins are a way of adding common opts and can be enabled using
cli; //To disable, use the equivalent disable() method
help - enabled by default
-h,--help to output auto-generated usage information
-v,--version to output version information for the app. cli will attempt to locate and parse a nearby package.json
To set your own app name and version, use
Adds options to show/hide the stylized status messages that are output to the console when using one of these methods
cli; //Only shown when using --debugcli;cli; //Exits the process after outputting msgcli;cli;
-k,--no-color will omit ANSI color escapes from the output
glob - requires
npm install glob
Enables glob matching of arguments
-t,--timeout N to exit the process after N seconds with an error
-c,--catch to catch and output uncaughtExceptions and resume execution
Note: Plugins are automatically disabled if an option or switch of the same name is already defined
Copyright (c) 2010 Chris O'Hara email@example.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.