Options
All
  • Public
  • Public/Protected
  • All
Menu

@carnesen/cli

Index

Type aliases

CCliAnyStringChoices

CCliAnyStringChoices: string[] | keyof string[]

CCliArgGroupOptions

CCliArgGroupOptions<Optional>: { description?: CCliDescription; hidden?: undefined | false | true; optional?: Optional; placeholder?: undefined | string }

Options for creating an argument group, a group of adjacent command-line arguments

Type parameters

  • Optional: boolean

    If true, the type of args passed to {@link CCliArgGroupOptions.parse} does not include undefined.

Type declaration

  • Optional description?: CCliDescription

    A text description of this argument group. Paragraphs are re-wrapped when printed to the terminal so don't worry about whitespace.

  • Optional hidden?: undefined | false | true

    If true, command-line usage won't show this arg group unless it's invoked directly

  • Optional optional?: Optional

    Unless true, a CCliUsageError thrown if no argument is provided for this argument group

  • Optional placeholder?: undefined | string

    A short placeholder for this argument group in command-line usage. By convention, @carnesen/cli placeholders are wrapped in angled brackets e.g. "<email>"

CCliColor

CCliColor: { blue: any; bold: any; green: any; red: any }

Methods for decorating command output with colors

Type declaration

  • blue: function
    • blue(text: string): string
  • bold: function
    • bold(text: string): string
  • green: function
    • green(text: string): string
  • red: function
    • red(text: string): string

CCliCommandActionInput

CCliCommandActionInput<PositionalArgGroup, NamedArgGroups, DoubleDashArgGroup>: { color: CCliColor; doubleDashValue: InferParsedValueFromCCliArgGroup<DoubleDashArgGroup>; logger: CCliLogger; namedValues: {}; positionalValue: InferParsedValueFromCCliArgGroup<PositionalArgGroup> }

Type of the input argument injected into injected into {@link CCliCommandOptions.action}

Type parameters

Type declaration

CCliCommandGroupOptions

CCliCommandGroupOptions: { description?: CCliDescription; hidden?: undefined | false | true; name: string; subcommands: CCliSubcommand[] }

Options for {@link CliCommandGroup}

Type declaration

  • Optional description?: CCliDescription

    A short description for command-line usage

  • Optional hidden?: undefined | false | true

    If true, hide these commands in command-line usage

  • name: string

    Name of this command group

  • subcommands: CCliSubcommand[]

    The {@link ICliCommandGroup]]s and/or [[ICliCommand}s in this group

CCliCommandOptions

CCliCommandOptions<PositionalArgGroup, NamedArgGroups, DoubleDashArgGroup>: { action: (input: CCliCommandActionInput<PositionalArgGroup, NamedArgGroups, DoubleDashArgGroup>) => any; description?: CCliDescription; doubleDashArgGroup?: DoubleDashArgGroup; hidden?: undefined | false | true; name: string; namedArgGroups?: NamedArgGroups; positionalArgGroup?: PositionalArgGroup }

Options for creating a @carnesen/cli command

Type parameters

Type declaration

  • action: (input: CCliCommandActionInput<PositionalArgGroup, NamedArgGroups, DoubleDashArgGroup>) => any

    Function or async function that implements the command

  • Optional description?: CCliDescription

    A sentence or two about this command for command-line usage or a function returning the description text

  • Optional doubleDashArgGroup?: DoubleDashArgGroup

    A CCliArgGroup for the arguments after a lone "--"

  • Optional hidden?: undefined | false | true

    If true, don't show this command in command-line usage

  • name: string

    Identifier for this command in command-line usage

  • Optional namedArgGroups?: NamedArgGroups

    A CCliArgGroup for the arguments passed as "--name value"

  • Optional positionalArgGroup?: PositionalArgGroup

    A CCliArgGroup for the arguments before the first separator argument

CCliDescription

CCliDescription: undefined | string | CCliDescriptionFunction

CCliDescriptionFunction

CCliDescriptionFunction: (input: { color: CCliColor }) => string

Type of a command description when it's a function

Type declaration

CCliFlagArgGroupOptions

CCliFlagArgGroupOptions: Pick<CCliArgGroupOptions<true>, "description" | "hidden">

Options for CCliFlagArgGroup

CCliJsonArgGroupOptions

CCliJsonArgGroupOptions: CCliArgGroupOptions<boolean>

Options for CCliJsonArgGroup

CCliJsonArgGroupValue

CCliJsonArgGroupValue: any

CCliLeaf

CCliLeaf: { current: CCliCommand; parents: CCliCommandGroup[] }

Data structure representing a leaf node in a command tree

Type declaration

CCliNumberArgGroupOptions

CCliNumberArgGroupOptions<Optional>: CCliArgGroupOptions<Optional>

Options for CCliNumberArgGroup

Type parameters

  • Optional: boolean

CCliNumberArgGroupValue

CCliNumberArgGroupValue<Optional>: CCliConditionalValue<number, Optional>

Type parameters

  • Optional: boolean

CCliNumberArrayArgGroupOptions

CCliNumberArrayArgGroupOptions<Optional>: CCliArgGroupOptions<Optional>

Options for CCliNumberArrayArgGroup a.k.a ccli.numberArray

Type parameters

  • Optional: boolean

CCliNumberArrayArgGroupValue

CCliNumberArrayArgGroupValue<Optional>: CCliConditionalValue<number[], Optional>

Type parameters

  • Optional: boolean

CCliOptions

CCliOptions: { ansi?: undefined | false | true; color?: CCliColor; columns?: undefined | number; done?: CCliProcess["exit"]; logger?: CCliLogger }

Options for creating a CCli

Type declaration

  • Optional ansi?: undefined | false | true

    Enable/disable ANSI text color decoration

    default

    process.stdout.isTTY && process.stderr.isTTY

  • Optional color?: CCliColor

    Text coloring methods. Takes precedence over the ansi option if provided. If not provided, a CCliColor instance will be created using cCliColorFactory with the {@link CCliOptions.ansi} option

  • Optional columns?: undefined | number

    Number of terminal columns

    default

    process.stdout.columns || 100

  • Optional done?: CCliProcess["exit"]

    Called after the command has completed. Defaults to process.exit

  • Optional logger?: CCliLogger

    CliLogger object to use for the CLI. Defaults to the global console object. The CLI runner calls logger.log on the command's action return value if there is one. The CLI runner calls logger.error on the exception if one is thrown. The logger is injected into the command action too.

CCliParseArgs

CCliParseArgs<Optional>: CCliConditionalValue<string[], Optional>

Defines the type of the args passed to an CCliArgGroup.parse

Type parameters

  • Optional: boolean

CCliProcess

CCliProcess: { argv: string[]; exit: (code?: undefined | number) => void; stderr: { isTTY: boolean }; stdout: { columns: number; isTTY: boolean } }

An isomorphic subset of the Node.js global process object. By defining our own type for this we avoid depending on @types/node package

Type declaration

  • argv: string[]
  • exit: (code?: undefined | number) => void
      • (code?: undefined | number): void
      • Parameters

        • Optional code: undefined | number

        Returns void

  • stderr: { isTTY: boolean }
    • isTTY: boolean
  • stdout: { columns: number; isTTY: boolean }
    • columns: number
    • isTTY: boolean

CCliRoot

Root of a command tree

CCliStringArgGroupOptions

CCliStringArgGroupOptions<Optional>: CCliArgGroupOptions<Optional>

Options for {@link CliStringArgGroup}

Type parameters

  • Optional: boolean

CCliStringArgGroupValue

CCliStringArgGroupValue<Optional>: CCliConditionalValue<string, Optional>

Type parameters

  • Optional: boolean

CCliStringArrayArgGroupOptions

CCliStringArrayArgGroupOptions<Optional>: CCliArgGroupOptions<Optional>

Options for {@link CliStringArgGroup}

Type parameters

  • Optional: boolean

CCliStringArrayArgGroupValue

CCliStringArrayArgGroupValue<Optional>: CCliConditionalValue<string[], Optional>

Type parameters

  • Optional: boolean

CCliStringChoiceArgGroupOptions

CCliStringChoiceArgGroupOptions<Optional, Choices>: CCliArgGroupOptions<Optional> & { choices: Choices }

Options for a CCliStringChoiceArgGroup

typeparam

true, a value need not be provided

Type parameters

CCliStringChoiceArgGroupValue

CCliStringChoiceArgGroupValue<Optional, Choices>: CCliConditionalValue<Choices[number], Optional>

Type parameters

CCliSubcommand

CCliSubcommand: CCliCommandGroup | CCliCommand<any, any, any>

Type of {@link CCliCommandGroupOptions.subcommands}

CCliTree

CCliTree: { current: CCliRoot; parents: CCliCommandGroup[] }

Data structure representing a node in a command tree

Type declaration

InferParsedValueFromCCliArgGroup

InferParsedValueFromCCliArgGroup<ArgGroup>: ArgGroup extends CCliArgGroup<infer Value, true> ? Value | undefined : ArgGroup extends CCliArgGroup<infer Value> ? NonNullable<Value> : never

Type parameters

  • ArgGroup

NavigateCCliTreeResult

NavigateCCliTreeResult: { args: string[]; message?: undefined | string; tree: CCliTree }

FOR INTERNAL USE ONLY. The result of calling {@link navigateCommandTree}

Type declaration

  • args: string[]

    Passed args past those used during navigation

  • Optional message?: undefined | string

    An error message describing why navigation stopped

  • tree: CCliTree

    The point in the command tree at which navigation stopped

RenderCCliDescriptionOptions

RenderCCliDescriptionOptions: { color: CCliColor }

Type of the object injected into a command's description when it's a function

Type declaration

Functions

Const CCliWordMark

  • CCliWordMark(__namedParameters: { color: { blue: any; bold: any; green: any; red: any } }): string
  • Parameters

    • __namedParameters: { color: { blue: any; bold: any; green: any; red: any } }
      • color: { blue: any; bold: any; green: any; red: any }
        • blue: function
          • blue(text: string): string
        • bold: function
          • bold(text: string): string
        • green: function
          • green(text: string): string
        • red: function
          • red(text: string): string

    Returns string

cCliColorFactory

  • cCliColorFactory(ansi?: undefined | false | true): CCliColor
  • A factory for CCliColors

    Parameters

    • Optional ansi: undefined | false | true

      If true, return a CCliAnsiColor instance. If false, return a CCliNoopColor instance. If undefined, return a CliAnsiColor instance if stdout and stderr are both a TTY or a CliNoopColor instance otherwise.

    Returns CCliColor

cCliProcessFactory

getGlobalProcess

  • getGlobalProcess(): any
  • Get a reference to the global variable process if it exists. The return value is type-asserted as any so be careful with it.

    Returns any

navigateCCliTree

  • FOR INTERNAL USE ONLY. Walk a tree of commands to find the one selected by the arguments provided

    Parameters

    • root: CCliRoot

      A command tree root

    • args: string[]

      An array of command-line arguments

    Returns NavigateCCliTreeResult

    The result of the search

renderCCliDescription

Generated using TypeDoc and MonoLisa