- AbstractCLI
Defines the shape of the root CLI including title, description, usage, help, and options/switches. Additionally this contains all of the functionality of running a CLI such as init, parseOptions, and run methods.
This class is the base class for
AwesomeCLI.CLI
andAwesomeCLI.CommandCLI
.- AbstractCommand ⇐
AbstractCLI
Defines the shape of a command, be it a sub-command, or the root command overloaded from
AwesomeCLI.CLI
orAwesomeCLI.CommandCLI
. While root commands should inherit fromAwesomeCLI.CLI
orAwesomeCLI.CommandCLI
any sub-commands below those would inherit directly fromAbstractCommand
.AbstractCommand inherits from AbstractCLI and thus has access to all of its methods such as title, usage, desriptino, addOption, addOptionShortcut, etc.
- BadCommandError ⇐
Error
Thrown when a command fails to compile or execute properly.
- CLI ⇐
AbstractCLI
The root command for a singular CLI that is not using sub-commands.
- CLIUtils
A selection of utilities to speed CLI development.
- CommandCLI ⇐
AbstractCommand
THe root command for a command based CLI that uses sub-commands.
- InvalidCommandError ⇐
Error
Thrown if a command that is being added is not a Function, AbstractCommand, or filename string.
- InvalidOptionError ⇐
Error
Thrown when an option is used when executing the CLI but that option does not exist or is otherwise not allowed.
- InvalidOptionValueError ⇐
Error
Thrown when a user of the CLI passes in a value to the CLI that does not match the given type for the option, for example passing a string when a number is required.
- InvalidTypeError ⇐
Error
Thrown when an option is being added but the given type is not "*" or "string" or "number" or "boolean".
- MissingCommandError ⇐
Error
Thrown when a command CLI gets a command it does not have a command mapped to.
- MissingOptionValueError ⇐
Error
Thrown when a user of the CLI gives a specific option but does not follow it with a required argument.
- AbstractCLI
Defines the AwesomeCLI main object, whcih returns pointer to the various AwesomeCLI classes.
Defines the shape of the root CLI including title, description, usage, help, and options/switches. Additionally this contains all of the functionality of running a CLI such as init, parseOptions, and run methods.
This class is the base class for AwesomeCLI.CLI
and AwesomeCLI.CommandCLI
.
Kind: global class
- AbstractCLI
- new AbstractCLI()
- .title ⇒
string
- .description ⇒
string
- .usage ⇒
string
- .help() ⇒
void
- .init(command, parsed) ⇒
Object
- .run(command, parsed) ⇒
Promise
- .getOption(optionName) ⇒
Object
- .getOptions() ⇒
Array.<string>
- .addOption(optionName, [type], [defaultValue], [description])
- .removeOption(optionName) ⇒
void
- .getOptionShortcut(shortcut) ⇒
string
- .getOptionShortcuts() ⇒
Array.<string>
- .addOptionShortcut(shortcut, optionName)
- .removeOptionShortcut(shortcut) ⇒
void
- .parseOptions(command, initialOptions) ⇒
Object
Constructs a new CLI.
Returns the title of this root CLI. Should be overloaded by extending classes.
Kind: instance property of AbstractCLI
Returns the description of this root CLI. Should be overloaded by extending classes.
Kind: instance property of AbstractCLI
Returns the usage of this root CLI. Should be overloaded by sxtending classes.
Kind: instance property of AbstractCLI
The default help implementation for a root CLI. Overload this if you want to customize your help display.
Kind: instance method of AbstractCLI
Called by the run()
method to initiate the root command and
option parsing. Generally this doesn't need to be overloaded.
Kind: instance method of AbstractCLI
Returns: Object
- the parsed arguments and options.
Param | Type | Description |
---|---|---|
command | Array |
line arguments. |
parsed | Object |
options and their values. |
Called when you start your CLI, this takes care of initializing, parsing arguments, and ensuring everything is run smoothly.
By and large there is zero reason to overload this. You should overload
execute(args,options)
, before(args,options)
, or after(args,options)
instead.
Kind: instance method of AbstractCLI
Param | Type | Description |
---|---|---|
command | Array |
line arguments. |
parsed | Object |
options and their values. |
Returns the object used to describe an option after it has been added.
Kind: instance method of AbstractCLI
Param | Type |
---|---|
optionName | string |
Returns an array of all the option names that have been added.
Kind: instance method of AbstractCLI
Adds a new options.
optionName must be unique to this command and any descendant commands.
type can be "*", "boolean", "number", or "string".
defaultvalue is the value used if the option is not prvided.
description is the help description for this option.
Kind: instance method of AbstractCLI
Param | Type | Default |
---|---|---|
optionName | string |
|
[type] | string |
""*"" |
[defaultValue] | * |
|
[description] | string |
"""" |
Removes a given option.
Kind: instance method of AbstractCLI
Param | Type |
---|---|
optionName | string |
Returns the Shortcut object for a given shortcut.
Kind: instance method of AbstractCLI
Param | Type |
---|---|
shortcut | string |
Returns an array of all the shortcut names added.
Kind: instance method of AbstractCLI
Adds a new option shortcut which maps the shortcut
to a
specific optionName
.
Kind: instance method of AbstractCLI
Param | Type |
---|---|
shortcut | string |
optionName | string |
Removes an option shortcut.
Kind: instance method of AbstractCLI
Param | Type |
---|---|
shortcut | string |
Responsible for parsing the command line arguments and determining what is an option and what is an argument.
Generally there is no reason to overload this.
Kind: instance method of AbstractCLI
Param | Type | Description |
---|---|---|
command | Array |
line arguments. |
initialOptions | Object |
AbstractCommand ⇐ AbstractCLI
Defines the shape of a command, be it a sub-command, or the root command
overloaded from AwesomeCLI.CLI
or AwesomeCLI.CommandCLI
. While
root commands should inherit from AwesomeCLI.CLI
or AwesomeCLI.CommandCLI
any sub-commands below those would inherit directly from AbstractCommand
.
AbstractCommand inherits from AbstractCLI and thus has access to all of its methods such as title, usage, desriptino, addOption, addOptionShortcut, etc.
Kind: global class
Extends: AbstractCLI
- AbstractCommand ⇐
AbstractCLI
- new AbstractCommand()
- .title ⇒
string
- .description ⇒
string
- .usage ⇒
string
- .help() ⇒
void
- .addCommand(name, command, description)
- .removeCommand(name) ⇒
void
- .getCommand(name) ⇒
Object
- .getCommands() ⇒
Array.<string>
- .run(args, options) ⇒
Promise
- .init(command, parsed) ⇒
Object
- .getOption(optionName) ⇒
Object
- .getOptions() ⇒
Array.<string>
- .addOption(optionName, [type], [defaultValue], [description])
- .removeOption(optionName) ⇒
void
- .getOptionShortcut(shortcut) ⇒
string
- .getOptionShortcuts() ⇒
Array.<string>
- .addOptionShortcut(shortcut, optionName)
- .removeOptionShortcut(shortcut) ⇒
void
- .parseOptions(command, initialOptions) ⇒
Object
Constructs a new AbstractCommand.
Returns the title of this AbstractCommand. Should be overloaded by extending classes.
Kind: instance property of AbstractCommand
Overrides: title
Returns the description of this AbstractCommand. Should be overloaded by extending classes.
Kind: instance property of AbstractCommand
Overrides: description
Returns the usage of this AbstractCommand. Should be overloaded by extending classes.
Kind: instance property of AbstractCommand
Overrides: usage
The default help implementation for a AbstractCommand. Overload this if you want to customize your help display.
Kind: instance method of AbstractCommand
Overrides: help
Add a new sub-command to this command.
name the name of the command, as it would be used.
command the command itself, which can be the following:
-
function commands, are simple functions that get passed the signature
(args,options)
when the command is executed. This approach is great for very simple "command CLIs". -
filenane commands will, if the file exists and exports a sub-class of the
AwesomeCLI.AbstractCommand
class, load it as javascript, and create an instance of it. This lets you write sub-commands in their own class space and easily load them into AwesomeCLI. This is the best approach to doing commands and highly recommended.- AbstractCommmand commands, are similar to filename commands, but they dont do the loading as you are already providing the loaded instance to AwesomeCLI.
description Help descriptive text for this command.
Kind: instance method of AbstractCommand
Param | Type |
---|---|
name | string |
command | function | AbstractCommand | string |
description | string |
Remove a command by name.
Kind: instance method of AbstractCommand
Param | Type |
---|---|
name | string |
Get the command object for a given command name.
Kind: instance method of AbstractCommand
Param | Type |
---|---|
name | string |
Returns an array of all command names for this particular command. Does not return commands defined by ancestor commands.
Kind: instance method of AbstractCommand
Executes the given command. Generally speaking you should not
overload this function but instead overload execute(args,options)
or
before(args,options)
or after(args,options)
.
Kind: instance method of AbstractCommand
Overrides: run
Param | Type |
---|---|
args | Array |
options | Object |
Called by the run()
method to initiate the root command and
option parsing. Generally this doesn't need to be overloaded.
Kind: instance method of AbstractCommand
Returns: Object
- the parsed arguments and options.
Param | Type | Description |
---|---|---|
command | Array |
line arguments. |
parsed | Object |
options and their values. |
Returns the object used to describe an option after it has been added.
Kind: instance method of AbstractCommand
Param | Type |
---|---|
optionName | string |
Returns an array of all the option names that have been added.
Kind: instance method of AbstractCommand
Adds a new options.
optionName must be unique to this command and any descendant commands.
type can be "*", "boolean", "number", or "string".
defaultvalue is the value used if the option is not prvided.
description is the help description for this option.
Kind: instance method of AbstractCommand
Param | Type | Default |
---|---|---|
optionName | string |
|
[type] | string |
""*"" |
[defaultValue] | * |
|
[description] | string |
"""" |
Removes a given option.
Kind: instance method of AbstractCommand
Param | Type |
---|---|
optionName | string |
Returns the Shortcut object for a given shortcut.
Kind: instance method of AbstractCommand
Param | Type |
---|---|
shortcut | string |
Returns an array of all the shortcut names added.
Kind: instance method of AbstractCommand
Adds a new option shortcut which maps the shortcut
to a
specific optionName
.
Kind: instance method of AbstractCommand
Param | Type |
---|---|
shortcut | string |
optionName | string |
Removes an option shortcut.
Kind: instance method of AbstractCommand
Param | Type |
---|---|
shortcut | string |
Responsible for parsing the command line arguments and determining what is an option and what is an argument.
Generally there is no reason to overload this.
Kind: instance method of AbstractCommand
Param | Type | Description |
---|---|---|
command | Array |
line arguments. |
initialOptions | Object |
Thrown when a command fails to compile or execute properly.
Kind: global class
Extends: Error
CLI ⇐ AbstractCLI
The root command for a singular CLI that is not using sub-commands.
Kind: global class
Extends: AbstractCLI
- CLI ⇐
AbstractCLI
- new CLI()
- .title ⇒
string
- .description ⇒
string
- .usage ⇒
string
- .execute(args, options) ⇒
void
|Promise
- .help() ⇒
void
- .init(command, parsed) ⇒
Object
- .run(command, parsed) ⇒
Promise
- .getOption(optionName) ⇒
Object
- .getOptions() ⇒
Array.<string>
- .addOption(optionName, [type], [defaultValue], [description])
- .removeOption(optionName) ⇒
void
- .getOptionShortcut(shortcut) ⇒
string
- .getOptionShortcuts() ⇒
Array.<string>
- .addOptionShortcut(shortcut, optionName)
- .removeOptionShortcut(shortcut) ⇒
void
- .parseOptions(command, initialOptions) ⇒
Object
Constructs a new CLI.
Returns the title of this root CLI. Should be overloaded by extending classes.
Kind: instance property of CLI
Overrides: title
Returns the description of this root CLI. Should be overloaded by extending classes.
Kind: instance property of CLI
Overrides: description
Returns the usage of this root CLI. Should be overloaded by sxtending classes.
Kind: instance property of CLI
Overrides: usage
Overload execute(args,options)
to do your work.
Kind: instance method of CLI
Param | Type |
---|---|
args | Array |
options | Object |
The default help implementation for a root CLI. Overload this if you want to customize your help display.
Kind: instance method of CLI
Called by the run()
method to initiate the root command and
option parsing. Generally this doesn't need to be overloaded.
Kind: instance method of CLI
Returns: Object
- the parsed arguments and options.
Param | Type | Description |
---|---|---|
command | Array |
line arguments. |
parsed | Object |
options and their values. |
Called when you start your CLI, this takes care of initializing, parsing arguments, and ensuring everything is run smoothly.
By and large there is zero reason to overload this. You should overload
execute(args,options)
, before(args,options)
, or after(args,options)
instead.
Kind: instance method of CLI
Param | Type | Description |
---|---|---|
command | Array |
line arguments. |
parsed | Object |
options and their values. |
Returns the object used to describe an option after it has been added.
Kind: instance method of CLI
Param | Type |
---|---|
optionName | string |
Returns an array of all the option names that have been added.
Kind: instance method of CLI
Adds a new options.
optionName must be unique to this command and any descendant commands.
type can be "*", "boolean", "number", or "string".
defaultvalue is the value used if the option is not prvided.
description is the help description for this option.
Kind: instance method of CLI
Param | Type | Default |
---|---|---|
optionName | string |
|
[type] | string |
""*"" |
[defaultValue] | * |
|
[description] | string |
"""" |
Removes a given option.
Kind: instance method of CLI
Param | Type |
---|---|
optionName | string |
Returns the Shortcut object for a given shortcut.
Kind: instance method of CLI
Param | Type |
---|---|
shortcut | string |
Returns an array of all the shortcut names added.
Kind: instance method of CLI
Adds a new option shortcut which maps the shortcut
to a
specific optionName
.
Kind: instance method of CLI
Param | Type |
---|---|
shortcut | string |
optionName | string |
Removes an option shortcut.
Kind: instance method of CLI
Param | Type |
---|---|
shortcut | string |
Responsible for parsing the command line arguments and determining what is an option and what is an argument.
Generally there is no reason to overload this.
Kind: instance method of CLI
Param | Type | Description |
---|---|---|
command | Array |
line arguments. |
initialOptions | Object |
A selection of utilities to speed CLI development.
Kind: global class
- CLIUtils
- .resolve(filename) ⇒
string
- .readFile(filename, [encoding]) ⇒
string
- .readSTDIN([encoding]) ⇒
string
- .resolve(filename) ⇒
Given some filename, resolve that filename relative to your current working directory, or if that fails, against the directory of the calling module.
Kind: instance method of CLIUtils
Param | Type |
---|---|
filename | string |
Given some filename, read the contents of that file from the file system and return it as a string.
Kind: instance method of CLIUtils
Param | Type | Default |
---|---|---|
filename | string |
|
[encoding] | string |
""utf-8"" |
If your CLI had data piped to it, this command will read that data from the stdin pipe and return it as a string. Subsequent calls to this function will return a cached copy of the stdin data.
Note, that this command is not intended to be used to read user
input from stdin. Please use node.js' readline
library.
Kind: instance method of CLIUtils
Param | Type | Default |
---|---|---|
[encoding] | string |
""utf-8"" |
CommandCLI ⇐ AbstractCommand
THe root command for a command based CLI that uses sub-commands.
Kind: global class
Extends: AbstractCommand
- CommandCLI ⇐
AbstractCommand
- new CommandCLI()
- .title ⇒
string
- .description ⇒
string
- .usage ⇒
string
- .help() ⇒
void
- .addCommand(name, command, description)
- .removeCommand(name) ⇒
void
- .getCommand(name) ⇒
Object
- .getCommands() ⇒
Array.<string>
- .run(args, options) ⇒
Promise
- .init(command, parsed) ⇒
Object
- .getOption(optionName) ⇒
Object
- .getOptions() ⇒
Array.<string>
- .addOption(optionName, [type], [defaultValue], [description])
- .removeOption(optionName) ⇒
void
- .getOptionShortcut(shortcut) ⇒
string
- .getOptionShortcuts() ⇒
Array.<string>
- .addOptionShortcut(shortcut, optionName)
- .removeOptionShortcut(shortcut) ⇒
void
- .parseOptions(command, initialOptions) ⇒
Object
Constructs a new CLI.
Returns the title of this root CLI. Should be overloaded by extending classes.
Kind: instance property of CommandCLI
Overrides: title
Returns the description of this root CLI. Should be overloaded by extending classes.
Kind: instance property of CommandCLI
Overrides: description
Returns the usage of this root CLI. Should be overloaded by sxtending classes.
Kind: instance property of CommandCLI
Overrides: usage
The default help implementation for a AbstractCommand. Overload this if you want to customize your help display.
Kind: instance method of CommandCLI
Add a new sub-command to this command.
name the name of the command, as it would be used.
command the command itself, which can be the following:
-
function commands, are simple functions that get passed the signature
(args,options)
when the command is executed. This approach is great for very simple "command CLIs". -
filenane commands will, if the file exists and exports a sub-class of the
AwesomeCLI.AbstractCommand
class, load it as javascript, and create an instance of it. This lets you write sub-commands in their own class space and easily load them into AwesomeCLI. This is the best approach to doing commands and highly recommended.- AbstractCommmand commands, are similar to filename commands, but they dont do the loading as you are already providing the loaded instance to AwesomeCLI.
description Help descriptive text for this command.
Kind: instance method of CommandCLI
Param | Type |
---|---|
name | string |
command | function | AbstractCommand | string |
description | string |
Remove a command by name.
Kind: instance method of CommandCLI
Param | Type |
---|---|
name | string |
Get the command object for a given command name.
Kind: instance method of CommandCLI
Param | Type |
---|---|
name | string |
Returns an array of all command names for this particular command. Does not return commands defined by ancestor commands.
Kind: instance method of CommandCLI
Executes the given command. Generally speaking you should not
overload this function but instead overload execute(args,options)
or
before(args,options)
or after(args,options)
.
Kind: instance method of CommandCLI
Param | Type |
---|---|
args | Array |
options | Object |
Called by the run()
method to initiate the root command and
option parsing. Generally this doesn't need to be overloaded.
Kind: instance method of CommandCLI
Returns: Object
- the parsed arguments and options.
Param | Type | Description |
---|---|---|
command | Array |
line arguments. |
parsed | Object |
options and their values. |
Returns the object used to describe an option after it has been added.
Kind: instance method of CommandCLI
Param | Type |
---|---|
optionName | string |
Returns an array of all the option names that have been added.
Kind: instance method of CommandCLI
Adds a new options.
optionName must be unique to this command and any descendant commands.
type can be "*", "boolean", "number", or "string".
defaultvalue is the value used if the option is not prvided.
description is the help description for this option.
Kind: instance method of CommandCLI
Param | Type | Default |
---|---|---|
optionName | string |
|
[type] | string |
""*"" |
[defaultValue] | * |
|
[description] | string |
"""" |
Removes a given option.
Kind: instance method of CommandCLI
Param | Type |
---|---|
optionName | string |
Returns the Shortcut object for a given shortcut.
Kind: instance method of CommandCLI
Param | Type |
---|---|
shortcut | string |
Returns an array of all the shortcut names added.
Kind: instance method of CommandCLI
Adds a new option shortcut which maps the shortcut
to a
specific optionName
.
Kind: instance method of CommandCLI
Param | Type |
---|---|
shortcut | string |
optionName | string |
Removes an option shortcut.
Kind: instance method of CommandCLI
Param | Type |
---|---|
shortcut | string |
Responsible for parsing the command line arguments and determining what is an option and what is an argument.
Generally there is no reason to overload this.
Kind: instance method of CommandCLI
Param | Type | Description |
---|---|---|
command | Array |
line arguments. |
initialOptions | Object |
Thrown if a command that is being added is not a Function, AbstractCommand, or filename string.
Kind: global class
Extends: Error
Thrown when an option is used when executing the CLI but that option does not exist or is otherwise not allowed.
Kind: global class
Extends: Error
Thrown when a user of the CLI passes in a value to the CLI that does not match the given type for the option, for example passing a string when a number is required.
Kind: global class
Extends: Error
Thrown when an option is being added but the given type is not "*" or "string" or "number" or "boolean".
Kind: global class
Extends: Error
Thrown when a command CLI gets a command it does not have a command mapped to.
Kind: global class
Extends: Error
Thrown when a user of the CLI gives a specific option but does not follow it with a required argument.
Kind: global class
Extends: Error
Defines the AwesomeCLI main object, whcih returns pointer to the various AwesomeCLI classes.
Kind: global constant
- AbstractCLI
- new AbstractCLI()
- .title ⇒
string
- .description ⇒
string
- .usage ⇒
string
- .help() ⇒
void
- .init(command, parsed) ⇒
Object
- .run(command, parsed) ⇒
Promise
- .getOption(optionName) ⇒
Object
- .getOptions() ⇒
Array.<string>
- .addOption(optionName, [type], [defaultValue], [description])
- .removeOption(optionName) ⇒
void
- .getOptionShortcut(shortcut) ⇒
string
- .getOptionShortcuts() ⇒
Array.<string>
- .addOptionShortcut(shortcut, optionName)
- .removeOptionShortcut(shortcut) ⇒
void
- .parseOptions(command, initialOptions) ⇒
Object
Constructs a new CLI.
Returns the title of this root CLI. Should be overloaded by extending classes.
Kind: instance property of AbstractCLI
Returns the description of this root CLI. Should be overloaded by extending classes.
Kind: instance property of AbstractCLI
Returns the usage of this root CLI. Should be overloaded by sxtending classes.
Kind: instance property of AbstractCLI
The default help implementation for a root CLI. Overload this if you want to customize your help display.
Kind: instance method of AbstractCLI
Called by the run()
method to initiate the root command and
option parsing. Generally this doesn't need to be overloaded.
Kind: instance method of AbstractCLI
Returns: Object
- the parsed arguments and options.
Param | Type | Description |
---|---|---|
command | Array |
line arguments. |
parsed | Object |
options and their values. |
Called when you start your CLI, this takes care of initializing, parsing arguments, and ensuring everything is run smoothly.
By and large there is zero reason to overload this. You should overload
execute(args,options)
, before(args,options)
, or after(args,options)
instead.
Kind: instance method of AbstractCLI
Param | Type | Description |
---|---|---|
command | Array |
line arguments. |
parsed | Object |
options and their values. |
Returns the object used to describe an option after it has been added.
Kind: instance method of AbstractCLI
Param | Type |
---|---|
optionName | string |
Returns an array of all the option names that have been added.
Kind: instance method of AbstractCLI
Adds a new options.
optionName must be unique to this command and any descendant commands.
type can be "*", "boolean", "number", or "string".
defaultvalue is the value used if the option is not prvided.
description is the help description for this option.
Kind: instance method of AbstractCLI
Param | Type | Default |
---|---|---|
optionName | string |
|
[type] | string |
""*"" |
[defaultValue] | * |
|
[description] | string |
"""" |
Removes a given option.
Kind: instance method of AbstractCLI
Param | Type |
---|---|
optionName | string |
Returns the Shortcut object for a given shortcut.
Kind: instance method of AbstractCLI
Param | Type |
---|---|
shortcut | string |
Returns an array of all the shortcut names added.
Kind: instance method of AbstractCLI
Adds a new option shortcut which maps the shortcut
to a
specific optionName
.
Kind: instance method of AbstractCLI
Param | Type |
---|---|
shortcut | string |
optionName | string |
Removes an option shortcut.
Kind: instance method of AbstractCLI
Param | Type |
---|---|
shortcut | string |
Responsible for parsing the command line arguments and determining what is an option and what is an argument.
Generally there is no reason to overload this.
Kind: instance method of AbstractCLI
Param | Type | Description |
---|---|---|
command | Array |
line arguments. |
initialOptions | Object |