# Command

Command class

# Hierarchy

  • Command

# Methods

# action

action(action: Action): Command

Set the corresponding action to execute for this command

Parameters:

Name Type Description
action Action Action to execute

Returns: Command


# alias

alias(...aliases: string[]): Command

Add one or more aliases so the command can be called by different names.

Parameters:

Name Type Description
...aliases string[] Command aliases

Returns: Command


# argument

argument(synopsis: string, description: string, options: CreateArgumentOpts): Command

Add an argument to the command. Synopsis is a string like <my-argument> or [my-argument]. Angled brackets (e.g. <item>) indicate required input. Square brackets (e.g. [env]) indicate optional input.

Returns the Command object to facilitate chaining of methods.

Parameters:

Name Type Default Description
synopsis string - Argument synopsis.
description string - Argument description.
options CreateArgumentOpts {} -

Returns: Command


# cast

cast(enabled: boolean): Command

Enable or disable auto casting of arguments & options for the command. This is basically a shortcut to calling command.configure({ autoCast: enabled }). By default, auto-casting is inherited from the program configuration. This method allows overriding what's been set on the program level.

Parameters:

Name Type Description
enabled boolean

Returns: Command


# command

command(name: string, description: string, config: Partial‹CommandConfig›): Command

Allow chaining command() calls. See Program.command.

Parameters:

Name Type Default
name string -
description string -
config Partial‹CommandConfig {}

Returns: Command


# complete

complete(completer: Completer): Command

Auto-complete

Parameters:

Name Type
completer Completer

Returns: Command


# configure

configure(props: Partial‹CommandConfig›): Command

Configure some behavioral properties.

Parameters:

Name Type Description
props Partial‹CommandConfig properties to set/update

Returns: Command


# default

default(): Command

Makes the command the default one for the program.

Returns: Command


# help

help(text: string, options: Partial‹CustomizedHelpOpts›): Command

Customize command help. Can be called multiple times to add more paragraphs and/or sections.

Parameters:

Name Type Default Description
text string - Help contents
options Partial‹CustomizedHelpOpts {} Display options

Returns: Command


# hide

hide(): Command

Hide the command from help. Shortcut to calling .configure({ visible: false }).

Returns: Command


# option

option(synopsis: string, description: string, options: CreateOptionCommandOpts): Command

Add an option to the current command.

Parameters:

Name Type Default Description
synopsis string - Option synopsis like '-f, --force', or '-f, --file <file>', or '--with-openssl [path]'
description string - Option description
options CreateOptionCommandOpts {} Additional parameters

Returns: Command


# strict

strict(strict: boolean): Command

Toggle strict mode. Shortcut to calling: .configure({ strictArgsCount: strict, strictOptions: strict }). By default, strict settings are not defined for commands, and inherit from the program settings. Calling.strict(value)` on a command will override the program settings.

Parameters:

Name Type Default Description
strict boolean true boolean enabled flag

Returns: Command