1.8.2
Represents a program and all it's arguments and subcommands.
(string)
The filepath to your project's package.json file.
Whether this Program has any global arguments or not.
Boolean
:
The max length - in characters - of all arguments (both global and subcommand-local). Useful for lining everything up neatly :P
number
:
The name of the program. This is taken from the name field of your package.json automatically.
Type: string
The version of the program. This is taken from the version field of your package.json automatically.
Type: string
The name of the author that wrote the program. Appears on the second printed line of the help. This is taken from the author field of your package.json automatically.
Type: string
The description that appears next to the progrram name on the first line. This is taken from the description field in your package.json automatically.
Type: string
The extended description that appears below the author name.
Type: string
Global argument definitions.
Subcommand definitions.
Type: Array<Subcommand>
Extra args we found while parsing.
Adds an argument to the program.
(string)
The name of the argument
(string)
A description of the argument
(any)
The default value of the argument
((string | Function)
= "string"
)
The type of this argument. Set to "boolean" for flags that have no value. Possible values:
new Date(value)
For custom types, pass a function instead. Said function will be called with a single argument: The value to parse as a string. The return value will be treated as the parsed value.
Appending "_multi" (without quotes) to the type will cause applause-cli to allow multiple values for that parameter. In this case, the argument's parsed value will be an array of items.
this
:
The current Program instance for daisy-chaining
A string argument
let program = new Program("path/to/package.json");
program.argument("food", "Specifies the food to find.", "apple");
program.parse(process.argv.slice(2)); // Might return { food: "banana" }
A boolean argument
let program = new Program("path/to/package.json");
program.argument("with-lemonade", "Whether to include lemonade with your order", false, "boolean");
program.parse(process.argv.slice(2)); // Might return { with_lemonade: true }
Multiple integers
let program = new Program("path/to/package.json");
program.argument("package-number", "The number of the package(s) to ship. Maybe specified multiple times.", null, "integer_multi");
program.parse(process.argv.slice(2)); // Might return { package_number: [ 4, 5, 6 ] }
Using a custom function
let program = new Program("path/to/package.json");
program.argument("items", "A comma-separated list of items to put in the box.", null, (value) => {
return value.split(",").map((item) => item.trim());
});
program.parse(process.argv.slice(2)); // Might return { items: [ "banana", "orange", "raspberry" ] }
Adds a subcommand to the program.
Subcommand
:
The subcommand instance. Useful for specifying subcommand-specific arguments.
Parses the given argument set. Note that the returned object will also include all the default values of all relevant arguments (i.e. argument specific to the subcommand specified, but not other subcommands).
Object
:
The parsed arguments.
let program = new Program("path/to/package.json");
// ....
program.parse(process.argv.slice(2)); // Strip the first 2 argument, since they are the path to the Node.js binary and the script being executed respectively
Writes the program version to the standard output and then exits.
n/a
:
This method does not return (the process exits before this method does).
Displays auto-generated help text and then terminates the Node.js process
n/a
:
This method does not return (the process exits before this method does).
Represents a single command-line argument. You probably won't interact with this class directly - it's safe to ignore it until you need it.
(any)
(any)
(any)
(any)
The name that this argument should have in the final output object. Useful to make argument names more easily accessible (e.g. min-value → min_value).
string
:
The name this argument should have in the final output object.
Whether this argument supports multiple values or not.
boolean
:
Parses a value according to the type of this argument.
(any)
The value to parse.
any
:
The parsed value
Represents a subcommand on the CLI. Example call on the command line:
In the above, "foo" (without quotes) is the subcommand. Arguments can be attached either to the global Program instance, or to a specific Subcommand instance.
(string)
The name of the subcommand
(string)
The human-readable description of the subcommand (displayed in the help text)
Whether this Subcommand instance has any arguments or not.
Boolean
:
Adds a new argument to this Subcommand instance. Note that the new argument will be specific to this subcommand - and will not work globally (only when this subcommand is called). For that, you probably want Program.argument() instead.
(string)
The name of the argument. Dashes are automatically converted to underscores in the parsing process.
(string)
The human-readable description of the argument. Displayed in the help text.
(any)
The default value of this argument.
(String
= "string"
)
The type of this argument. See Program.argument() for more information.
this
:
The current Subcommand. Useful for daisy-chaining.