Options
All
  • Public
  • Public/Protected
  • All
Menu

Class OpenTokenCLI

Hierarchy

  • CommandLineParser
    • OpenTokenCLI

Index

Constructors

constructor

  • Returns OpenTokenCLI

Properties

Private _verbose

_verbose: CommandLineFlagParameter

selectedAction

selectedAction: CommandLineAction | undefined

Reports which CommandLineAction was specified on the command line.

remarks

The value will be assigned before onExecute() is invoked.

Accessors

actions

  • get actions(): ReadonlyArray<CommandLineAction>
  • Returns the list of actions that were defined for this CommandLineParser object.

    Returns ReadonlyArray<CommandLineAction>

parameters

  • get parameters(): ReadonlyArray<CommandLineParameter>
  • Returns a collection of the parameters that were defined for this object.

    Returns ReadonlyArray<CommandLineParameter>

remainder

  • get remainder(): CommandLineRemainder | undefined
  • If {@link CommandLineParameterProvider.defineCommandLineRemainder} was called, this object captures any remaining command line arguments after the recognized portion.

    Returns CommandLineRemainder | undefined

Methods

addAction

  • addAction(action: CommandLineAction): void
  • Defines a new action that can be used with the CommandLineParser instance.

    Parameters

    • action: CommandLineAction

    Returns void

defineChoiceParameter

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

    remarks

    Example of a choice parameter:

    example-tool --log-level warn

    Parameters

    • definition: ICommandLineChoiceDefinition

    Returns CommandLineChoiceParameter

defineCommandLineRemainder

  • defineCommandLineRemainder(definition: ICommandLineRemainderDefinition): CommandLineRemainder
  • Defines a rule that captures any remaining command line arguments after the recognized portion.

    remarks

    This feature is useful for commands that pass their arguments along to an external tool, relying on that tool to perform validation. (It could also be used to parse parameters without any validation or documentation, but that is not recommended.)

    Example of capturing the remainder after an optional flag parameter.

    example-tool --my-flag this is the remainder

    In the "--help" documentation, the remainder rule will be represented as "...".

    Parameters

    • definition: ICommandLineRemainderDefinition

    Returns CommandLineRemainder

defineFlagParameter

  • defineFlagParameter(definition: ICommandLineFlagDefinition): CommandLineFlagParameter
  • Defines a command-line switch whose boolean value is true if the switch is provided, and false otherwise.

    remarks

    Example usage of a flag parameter:

    example-tool --debug

    Parameters

    • definition: ICommandLineFlagDefinition

    Returns CommandLineFlagParameter

defineIntegerParameter

  • defineIntegerParameter(definition: ICommandLineIntegerDefinition): CommandLineIntegerParameter
  • Defines a command-line parameter whose argument is an integer.

    remarks

    Example usage of an integer parameter:

    example-tool --max-attempts 5

    Parameters

    • definition: ICommandLineIntegerDefinition

    Returns CommandLineIntegerParameter

defineStringListParameter

  • defineStringListParameter(definition: ICommandLineStringListDefinition): CommandLineStringListParameter
  • Defines a command-line parameter whose argument is a single text string. The parameter can be specified multiple times to build a list.

    remarks

    Example usage of a string list parameter:

    example-tool --add file1.txt --add file2.txt --add file3.txt

    Parameters

    • definition: ICommandLineStringListDefinition

    Returns CommandLineStringListParameter

defineStringParameter

  • defineStringParameter(definition: ICommandLineStringDefinition): CommandLineStringParameter
  • Defines a command-line parameter whose argument is a single text string.

    remarks

    Example usage of a string parameter:

    example-tool --message "Hello, world!"

    Parameters

    • definition: ICommandLineStringDefinition

    Returns CommandLineStringParameter

execute

  • execute(args?: string[]): Promise<boolean>
  • The program entry point will call this method to begin parsing command-line arguments and executing the corresponding action.

    remarks

    The returned promise will never reject: If an error occurs, it will be printed to stderr, process.exitCode will be set to 1, and the promise will resolve to false. This simplifies the most common usage scenario where the program entry point doesn't want to be involved with the command-line logic, and will discard the promise without a then() or catch() block.

    If your caller wants to trap and handle errors, use {@link CommandLineParser.executeWithoutErrorHandling} instead.

    Parameters

    • Optional args: string[]

      the command-line arguments to be parsed; if omitted, then the process.argv will be used

    Returns Promise<boolean>

executeWithoutErrorHandling

  • executeWithoutErrorHandling(args?: string[]): Promise<void>
  • This is similar to {@link CommandLineParser.execute}, except that execution errors simply cause the promise to reject. It is the caller's responsibility to trap

    Parameters

    • Optional args: string[]

    Returns Promise<void>

getAction

  • getAction(actionName: string): CommandLineAction
  • Retrieves the action with the specified name. If no matching action is found, an exception is thrown.

    Parameters

    • actionName: string

    Returns CommandLineAction

getChoiceParameter

  • getChoiceParameter(parameterLongName: string): CommandLineChoiceParameter
  • Returns the CommandLineChoiceParameter with the specified long name.

    remarks

    This method throws an exception if the parameter is not defined.

    Parameters

    • parameterLongName: string

    Returns CommandLineChoiceParameter

getFlagParameter

  • getFlagParameter(parameterLongName: string): CommandLineFlagParameter
  • Returns the CommandLineFlagParameter with the specified long name.

    remarks

    This method throws an exception if the parameter is not defined.

    Parameters

    • parameterLongName: string

    Returns CommandLineFlagParameter

getIntegerParameter

  • getIntegerParameter(parameterLongName: string): CommandLineIntegerParameter
  • Returns the CommandLineIntegerParameter with the specified long name.

    remarks

    This method throws an exception if the parameter is not defined.

    Parameters

    • parameterLongName: string

    Returns CommandLineIntegerParameter

getStringListParameter

  • getStringListParameter(parameterLongName: string): CommandLineStringListParameter
  • Returns the CommandLineStringListParameter with the specified long name.

    remarks

    This method throws an exception if the parameter is not defined.

    Parameters

    • parameterLongName: string

    Returns CommandLineStringListParameter

getStringParameter

  • getStringParameter(parameterLongName: string): CommandLineStringParameter
  • Returns the CommandLineStringParameter with the specified long name.

    remarks

    This method throws an exception if the parameter is not defined.

    Parameters

    • parameterLongName: string

    Returns CommandLineStringParameter

Protected onDefineParameters

  • onDefineParameters(): void
  • Returns void

Protected onExecute

  • onExecute(): Promise<void>
  • Returns Promise<void>

renderHelpText

  • renderHelpText(): string
  • Generates the command-line help text.

    Returns string

tryGetAction

  • tryGetAction(actionName: string): CommandLineAction | undefined
  • Retrieves the action with the specified name. If no matching action is found, undefined is returned.

    Parameters

    • actionName: string

    Returns CommandLineAction | undefined

Generated using TypeDoc