RoadmapShopEvents
Skip to main content

Home > @rushstack/ts-command-line > CommandLineAction

CommandLineAction class

Represents a sub-command that is part of the CommandLineParser command line. Applications should create subclasses of CommandLineAction corresponding to each action that they want to expose.

The action name should be comprised of lower case words separated by hyphens or colons. The name should include an English verb (e.g. "deploy"). Use a hyphen to separate words (e.g. "upload-docs"). A group of related commands can be prefixed with a colon (e.g. "docs:generate", "docs:deploy", "docs:serve", etc).

Signature:

export declare abstract class CommandLineAction extends CommandLineParameterProvider 

Extends: CommandLineParameterProvider

Constructors

ConstructorModifiersDescription
(constructor)(options)Constructs a new instance of the CommandLineAction class

Properties

PropertyModifiersTypeDescription
actionNamereadonlystringThe name of the action. For example, if the tool is called "example", then the "build" action might be invoked as: "example build -q --some-other-option"
documentationreadonlystringA detailed description that is shown on the action help page, which is displayed by the command "example build --help", e.g. for actionName="build".
parametersreadonlyReadonlyArray<CommandLineParameter>

Returns a collection of the parameters that were defined for this object.

(Inherited from CommandLineParameterProvider)

parametersProcessedreadonlyboolean

Informs the caller if the argparse data has been processed into parameters.

(Inherited from CommandLineParameterProvider)

remainderreadonlyCommandLineRemainder | undefined

If CommandLineParameterProvider.defineCommandLineRemainder() was called, this object captures any remaining command line arguments after the recognized portion.

(Inherited from CommandLineParameterProvider)

summaryreadonlystringA quick summary that is shown on the main help page, which is displayed by the command "example --help"

Methods

MethodModifiersDescription
defineChoiceListParameter(definition)

Defines a command-line parameter whose value must be a string from a fixed set of allowable choices (similar to an enum). The parameter can be specified multiple times to build a list.

(Inherited from CommandLineParameterProvider)

defineChoiceParameter(definition)

Defines a command-line parameter whose value must be a string from a fixed set of allowable choices (similar to an enum).

(Inherited from CommandLineParameterProvider)

defineCommandLineRemainder(definition)

Defines a rule that captures any remaining command line arguments after the recognized portion.

(Inherited from CommandLineParameterProvider)

defineFlagParameter(definition)

Defines a command-line switch whose boolean value is true if the switch is provided, and false otherwise.

(Inherited from CommandLineParameterProvider)

defineIntegerListParameter(definition)

Defines a command-line parameter whose argument is an integer. The parameter can be specified multiple times to build a list.

(Inherited from CommandLineParameterProvider)

defineIntegerParameter(definition)

Defines a command-line parameter whose argument is an integer.

(Inherited from CommandLineParameterProvider)

defineStringListParameter(definition)

Defines a command-line parameter whose argument is a single text string. The parameter can be specified multiple times to build a list.

(Inherited from CommandLineParameterProvider)

defineStringParameter(definition)

Defines a command-line parameter whose argument is a single text string.

(Inherited from CommandLineParameterProvider)

getChoiceListParameter(parameterLongName, parameterScope)

Returns the CommandLineChoiceListParameter with the specified long name.

(Inherited from CommandLineParameterProvider)

getChoiceParameter(parameterLongName, parameterScope)

Returns the CommandLineChoiceParameter with the specified long name.

(Inherited from CommandLineParameterProvider)

getFlagParameter(parameterLongName, parameterScope)

Returns the CommandLineFlagParameter with the specified long name.

(Inherited from CommandLineParameterProvider)

getIntegerListParameter(parameterLongName, parameterScope)

Returns the CommandLineIntegerParameter with the specified long name.

(Inherited from CommandLineParameterProvider)

getIntegerParameter(parameterLongName, parameterScope)

Returns the CommandLineIntegerParameter with the specified long name.

(Inherited from CommandLineParameterProvider)

getParameterStringMap()

Returns a object which maps the long name of each parameter in this.parameters to the stringified form of its value. This is useful for logging telemetry, but it is not the proper way of accessing parameters or their values.

(Inherited from CommandLineParameterProvider)

getStringListParameter(parameterLongName, parameterScope)

Returns the CommandLineStringListParameter with the specified long name.

(Inherited from CommandLineParameterProvider)

getStringParameter(parameterLongName, parameterScope)

Returns the CommandLineStringParameter with the specified long name.

(Inherited from CommandLineParameterProvider)

onDefineParameters()protectedThe child class should implement this hook to define its command-line parameters, e.g. by calling defineFlagParameter().
onExecute()protectedYour subclass should implement this hook to perform the operation.
parseScopedLongName(scopedLongName)

Returns an object with the parsed scope (if present) and the long name of the parameter.

(Inherited from CommandLineParameterProvider)

renderHelpText()

Generates the command-line help text.

(Inherited from CommandLineParameterProvider)

renderUsageText()

Generates the command-line usage text.

(Inherited from CommandLineParameterProvider)