
Security News
Open Source Maintainers Feeling the Weight of the EU’s Cyber Resilience Act
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
cli-define
Advanced tools
Chainable argument builder for a command line interface.
npm install cli-define
npm test
var path = require('path');
var cli = require('cli-define')(path.join(__dirname, 'package.json'));
cli
.option('-f --file <file...>', 'files to copy')
.option('-v --verbose', 'print more information')
.version()
.help()
cli.command('cp')
.description('copy files')
.action(function(cmd, options, raw) {
// execute copy logic here, scope is the program instance
console.dir(this.file);
})
The recommended way to define options is to use the self-documenting name
convention:
-v // => flag
--verbose // => flag
-v --verbose // => flag
-v, --verbose // => flag
-v | --verbose // => flag
--option [value] // => option (optional)
--option <value> // => option (required)
--option [value...] // => option (optional, repeatable)
--option <value...> // => option (required, repeatable)
Initialize the program.
package
: Path to the module package.json
used to extract default program version and description.name
: Specific name for the program, overrides package.json
.description
: Specific description for the program, overrides package.json
.Returns a Program
instance.
The root of the definition hierarchy, Program
extends Command
.
A function used to coerce the value of unparsed arguments.
fn
: A function used to coerce type or validate it's value.Get or set the program description.
Get or set the program name.
Represents a command option.
Get or set a callback function for the command.
fn
: The callback function.cli.command('install', 'install a package')
cli.command('install')
.description('install a package')
.action(function(cmd, args){})
Adds a command option.
name
: The name of the command.description
: The command description.options
: The argument options.If description
is specified returns the Program
otherwise the Command
instance.
Get a map of the defined commands.
Get or set the description for the command.
description
: The argument description.cli.flag('-v --verbose', 'print more information')
cli.flag('-v, --verbose', 'print more information')
cli.flag('-v | --verbose', 'print more information')
Explicitly adds a flag option to the command.
name
: The name of the flag.description
: The flag description.options
: The argument options.Returns the parent Command
for chaining.
Get or set the key
for the command automatically generated based on the command name
.
Get or set the full string name of the command.
Array of name components (read only).
cli.option('-d', 'debug') // => Flag
cli.option('--debug', 'debug') // => Flag
cli.option('-v --verbose', 'verbose') // => Flag
cli.option('--port [n]', 'port') // => Optional option
cli.option('--port [n]', 'port', 8080) // => Optional option w/default
cli.option('--port <n>', 'port', parseInt) // => Required option w/coercion
cli.option('--port [n]', 'port', 8080, parseInt) // => Optional option w/default+coercion
cli.option('--port [n]', 'port', parseInt, 8080) // => Optional option w/coercion+default
Adds an option to the command.
name
: The name of the option.description
: The option description.options
: The argument options.Returns the parent Command
for chaining.
Get a map of the defined options.
Represents an option that expects a value, shares all the functionality of the Argument
super class.
Represents an option that does not expect a value and is treated as a boolean
, shares all the functionality of the Argument
super class.
Abstract super class for all argument definition classes.
You may specify any of the fields below on the options object and they will be transferred to the instance provided they are writable.
Get or set a callback function for the argument, this is typically used by Command
arguments but can also be specified for other arguments.
fn
: The callback function.A function used to coerce the argument value.
fn
: A function used to coerce the arguments type or validate it's value.Get or set the description for the argument.
description
: The argument description.A string representing the remainder of an argument name, given a name
of -i --integer <n>
, extra
will equal <n>
.
Get or set the key
for the argument automatically generated based on the argument name
.
-v // => v
-v --verbose // => verbose
-p --port <n> // => port
A boolean
indicating that the argument may be repated, default is false
.
Get or set the full string name of the argument.
-v
-v --verbose
-v, --verbose
-v | --verbose
-p --port <n>
Array of name components, does not include the extra()
value (read only).
A boolean
indicating that the argument is optional, default is true
.
Get or set the value assigned to the instance after argument parsing, this may be used to set the default value for an argument.
FAQs
Chainable argument builder for a command line interface
We found that cli-define demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.