CLI—Command Line Interface—provides a toolkit for rapidly building command line applications in JavaScript. It has a fully-featured command line arguments (opts/args) parser, supports plugins for adding common options and switches, offers helper methods for working with input/output and spawning child processes, and can output styled or colored messages including progress bars and spinners.
To start using CLI, first install it via NPM using the command npm install cli
. CLI can be used to process input, sort and output data, handle command line arguments, and more. Here are some code examples:
For basic usage:
#!/usr/bin/env node
require('cli').withStdinLines(function(lines, newline) {
this.output(lines.sort().join(newline));
});
To use with command line arguments:
var cli = require('cli'), options = cli.parse();
cli.withStdinLines(function(lines, newline) {
lines.sort(!options.n ? null : function(a, b) {
return parseInt(a) > parseInt(b);
});
if (options.r) lines.reverse();
this.output(lines.join(newline));
});
For parsing command line arguments:
cli.parse({
file: [ 'f', 'A file to process', 'file', 'temp.log' ],
time: [ 't', 'An access time', 'time', false],
work: [ false, 'What kind of work to do', 'string', 'sleep' ]
});
For progress handling:
cli.progress(progress); //Where 0 <= progress <= 1
To use built-in plugins:
cli.enable(plugin1, [plugin2, ...]);
The CLI documentation is contained within the readme of the GitHub repository. You can access it by navigating to the repository at git+ssh://git@github.com/node-js-libs/cli.git
. You'll find a detailed explanation of the library's functionality, as well as a guide on how to utilize its methods and examples of usage. For any updates and advancements in the package, the GitHub repository will be the source of truth.