A mature, feature-complete library to parse command-line options.
Library rewritten using ECMAScript Modules to facilitate use with rollup and --experimental-modules
. Fixes https://github.com/75lb/command-line-args/issues/99. This is a non-functional change - the library API and functionality has not changed.
UNKNOWN_VALUE
) by default in the same way unknown options do. Command-line-args is now strict by default - all options and values must be accounted for in the option definitions.
5
in the command --verbose 5
where verbose is defined as a Boolean
.partial
or stopAtFIrstUnknown
parse options.--help --help
) now throws an ALREADY_SET
exception.NAME_MISSING
, INVALID_TYPE
etc) thrown by commandLineArgs in the case of an invalid definition have been consolidated to just one error name: INVALID_DEFINITIONS
. Given broken option definitions are a programmer error they'd never be handled anyway, making the various names pointless.UNKNOWN_OPTION
exception now has a optionName
property containing the arg that specified an unknown option, e.g. --one
ALREADY_SET
exception has a optionName
property containing the option name that has already been set, e.g. one
UNKNOWN_VALUE
exception has a value
property containing the unknown value, e.g. 5
No API changes were introduced in v5.0.0 - it is backward-compatible. If you're comfortable with the new version throwing exceptions on unknown values, you are safe to upgrade without code change.
Removed support for node versions less than v4.0.0
The method signature changed. If you're passing a custom argv
you now do it this way:
const argv = [ '--log-level', 'info' ]
commandLineArgs(optionDefinitions, { argv })
Previously, it was done this way:
const argv = [ '--log-level', 'info' ]
commandLineArgs(optionDefinitions, argv)
String
is the new default type
function.
If all the following are true then no changes are required to your code
argv
type
specified
The command-line-usage library evolved recently, it is now more flexible with a new API. As its API changed i found myself needing to update the .getUsage()
method of this library, causing a breaking change. Rather than update this library each time command-line-usage changes, i separated them completely. Therefore, the .getUsage()
method has been removed and the .parse()
method is now exported directly.
So, the API has changed from
const commandLineArgs = require('command-line-args')
const cli = commandLineArgs([ { name: 'version' } ])
const options = cli.parse()
to the more concise
const commandLineArgs = require('command-line-args')
const options = commandLineArgs([ { name: 'version' } ])
The data you previously passed to .getUsage()
you should pass to command-line-usage v2, like so:
const commandLineUsage = require('command-line-usage')
const usage = commandLineUsage(templateData)
For details about command-line-usage, including the new v3, see the project page.
new features
.getUsage
to use command-line-usage v2.0.0, which features column-layout, the header
field and other template improvementscommandLineArgs(definitions)
will now throw if you added defaultOption
to more than one definitionBreaking change since v1.0.0
-1
could be interpreted as both minus 1 and option 1.Other changes
--один
) are now valid