Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BaseCommand<Context>

Command to be executed when running tscmono or tscmono generate

Type parameters

  • Context: BaseContext

Hierarchy

  • Command
    • BaseCommand

Index

Properties

cli

cli: MiniCli<Context>

Predefined variable that will be populated with a miniature API that can be used to query Clipanion and forward commands.

context

context: Context

Predefined variable that will be populated with the context of the application.

help

help: boolean

Predefined that will be set to true if -h,--help has been used, in which case Command#execute shouldn't be called.

path

path: string[]

The path that got used to access the command being executed.

Static Entries

Entries: { Help: typeof HelpCommand; Version: typeof VersionCommand }

A list of useful semi-opinionated command entries that have to be registered manually.

They cover the basic needs of most CLIs (e.g. help command, version command).

example

cli.register(Command.Entries.Help); cli.register(Command.Entries.Version);

Type declaration

  • Help: typeof HelpCommand

    A command that prints the usage of all commands.

    Paths: -h, --help

  • Version: typeof VersionCommand

    A command that prints the version of the binary (cli.binaryVersion).

    Paths: -v, --version

Static Optional schema

schema: Schema<any>

The schema used to validate the Command instance.

Static Optional usage

usage: Usage

Contains the usage information for the command. If undefined, the command will be hidden from the general listing.

Methods

catch

  • catch(error: any): Promise<void>
  • Standard error handler which will simply rethrow the error. Can be used to add custom logic to handle errors from the command or simply return the parent class error handling.

    Parameters

    • error: any

    Returns Promise<void>

execute

  • execute(): Promise<number>
  • Returns Promise<number>

validateAndExecute

  • validateAndExecute(): Promise<number>
  • Returns Promise<number>

Static Array

  • Array(descriptor: string, __namedParameters?: { arity: undefined | number; description: undefined | string; hidden: undefined | false | true }): <Context>(prototype: Command<Context>, propertyName: string) => void
  • Register a listener that looks for an option and its followup argument. When Clipanion detects that this argument is present, the value will be pushed into the array represented in the property.

    Parameters

    • descriptor: string
    • Optional __namedParameters: { arity: undefined | number; description: undefined | string; hidden: undefined | false | true }
      • arity: undefined | number
      • description: undefined | string
      • hidden: undefined | false | true

    Returns <Context>(prototype: Command<Context>, propertyName: string) => void

      • <Context>(prototype: Command<Context>, propertyName: string): void
      • Type parameters

        • Context: BaseContext

        Parameters

        • prototype: Command<Context>
        • propertyName: string

        Returns void

Static Boolean

  • Boolean(descriptor: string, __namedParameters?: { description: undefined | string; hidden: undefined | false | true }): <Context>(prototype: Command<Context>, propertyName: string) => void
  • Register a boolean listener for the given option names. When Clipanion detects that this argument is present, the value will be set to false. The value won't be set unless the option is found, so you must remember to set it to an appropriate default value.

    Parameters

    • descriptor: string

      the option names.

    • Optional __namedParameters: { description: undefined | string; hidden: undefined | false | true }
      • description: undefined | string
      • hidden: undefined | false | true

    Returns <Context>(prototype: Command<Context>, propertyName: string) => void

      • <Context>(prototype: Command<Context>, propertyName: string): void
      • Type parameters

        • Context: BaseContext

        Parameters

        • prototype: Command<Context>
        • propertyName: string

        Returns void

Static Counter

  • Counter(descriptor: string, __namedParameters?: { description: undefined | string; hidden: undefined | false | true }): <Context>(prototype: Command<Context>, propertyName: string) => void
  • Register a boolean listener for the given option names. Each time Clipanion detects that this argument is present, the counter will be incremented. Each time the argument is negated, the counter will be reset to 0. The counter won't be set unless the option is found, so you must remember to set it to an appropriate default value.

    Parameters

    • descriptor: string

      A comma-separated list of option names.

    • Optional __namedParameters: { description: undefined | string; hidden: undefined | false | true }
      • description: undefined | string
      • hidden: undefined | false | true

    Returns <Context>(prototype: Command<Context>, propertyName: string) => void

      • <Context>(prototype: Command<Context>, propertyName: string): void
      • Type parameters

        • Context: BaseContext

        Parameters

        • prototype: Command<Context>
        • propertyName: string

        Returns void

Static Path

  • Path(...path: string[]): <Context>(prototype: Command<Context>, propertyName: string) => void
  • Wrap the specified command to be attached to the given path on the command line. The first path thus attached will be considered the "main" one, and all others will be aliases.

    Parameters

    • Rest ...path: string[]

      The command path.

    Returns <Context>(prototype: Command<Context>, propertyName: string) => void

      • <Context>(prototype: Command<Context>, propertyName: string): void
      • Type parameters

        • Context: BaseContext

        Parameters

        • prototype: Command<Context>
        • propertyName: string

        Returns void

Static Proxy

  • Proxy(__namedParameters?: { required: undefined | number }): <Context>(prototype: Command<Context>, propertyName: string) => void
  • Register a listener that takes all the arguments remaining (including options and such) and store them into the selected property. Note that all methods affecting positional arguments are evaluated in the definition order; don't mess with it (for example sorting your properties in ascendent order might have adverse results).

    Parameters

    • Optional __namedParameters: { required: undefined | number }
      • required: undefined | number

    Returns <Context>(prototype: Command<Context>, propertyName: string) => void

      • <Context>(prototype: Command<Context>, propertyName: string): void
      • Type parameters

        • Context: BaseContext

        Parameters

        • prototype: Command<Context>
        • propertyName: string

        Returns void

Static Rest

  • Rest(): PropertyDecorator
  • Rest(opts: { required: number }): PropertyDecorator
  • Register a listener that takes all the positional arguments remaining and store them into the selected property. Note that all methods affecting positional arguments are evaluated in the definition order; don't mess with it (for example sorting your properties in ascendent order might have adverse results).

    Returns PropertyDecorator

  • Register a listener that takes all the positional arguments remaining and store them into the selected property. Note that all methods affecting positional arguments are evaluated in the definition order; don't mess with it (for example sorting your properties in ascendent order might have adverse results).

    Parameters

    • opts: { required: number }
      • required: number

        The minimal number of arguments required for the command to be successful.

    Returns PropertyDecorator

Static Schema

  • Defines the schema for the given command.

    Type parameters

    • C: Command<any>

    Parameters

    Returns Schema<C>

Static String

  • String(descriptor: string, opts?: undefined | { arity?: undefined | number; description?: undefined | string; hidden?: undefined | false | true; tolerateBoolean?: undefined | false | true }): PropertyDecorator
  • String(descriptor?: undefined | { name?: undefined | string; required?: undefined | false | true }): PropertyDecorator
  • Register a listener that looks for an option and its followup argument. When Clipanion detects that this argument is present, the value will be set to whatever follows the option in the input. The value won't be set unless the option is found, so you must remember to set it to an appropriate default value. Note that all methods affecting positional arguments are evaluated in the definition order; don't mess with it (for example sorting your properties in ascendent order might have adverse results).

    Parameters

    • descriptor: string

      The option names.

    • Optional opts: undefined | { arity?: undefined | number; description?: undefined | string; hidden?: undefined | false | true; tolerateBoolean?: undefined | false | true }

    Returns PropertyDecorator

  • Register a listener that looks for positional arguments. When Clipanion detects that an argument isn't an option, it will put it in this property and continue processing the rest of the command line. Note that all methods affecting positional arguments are evaluated in the definition order; don't mess with it (for example sorting your properties in ascendent order might have adverse results).

    Parameters

    • Optional descriptor: undefined | { name?: undefined | string; required?: undefined | false | true }

      Whether or not filling the positional argument is required for the command to be a valid selection.

    Returns PropertyDecorator

Static Usage

  • Defines the usage information for the given command.

    Parameters

    Returns Usage

Static addOption

  • addOption<Context>(name: string, builder: (prototype: Command<Context>, propertyName: string) => void): void
  • Type parameters

    • Context: BaseContext

    Parameters

    • name: string
    • builder: (prototype: Command<Context>, propertyName: string) => void
        • (prototype: Command<Context>, propertyName: string): void
        • Parameters

          • prototype: Command<Context>
          • propertyName: string

          Returns void

    Returns void

Static addPath

  • addPath(...path: string[]): void
  • Parameters

    • Rest ...path: string[]

    Returns void

Static getMeta

  • getMeta<Context>(prototype: Command<Context>): Meta<Context>
  • Type parameters

    • Context: BaseContext

    Parameters

    • prototype: Command<Context>

    Returns Meta<Context>

Static resolveMeta

  • resolveMeta<Context>(prototype: Command<Context>): Meta<Context>
  • Type parameters

    • Context: BaseContext

    Parameters

    • prototype: Command<Context>

    Returns Meta<Context>

Generated using TypeDoc