clyops Node API
    Preparing search index...

    Class Cli

    A command-line interface. Register options and arguments before parsing. Registration errors indicate a programming mistake.

    Index
    cwd: string

    Working directory used to resolve command-line paths and execute tools.

    name: string

    Program name shown in help, schemas, and completion scripts.

    root: string

    Base directory for default and environment path values.

    values: Record<string, Value> = ...

    Resolved, typed values keyed by option var / argument name.

    • get commandPath(): string[]

      The command words selected by the last parse, e.g. ['db', 'migrate'].

      Returns string[]

    • Register a positional argument. An empty default makes it required.

      Parameters

      • name: string
      • description: string
      • defaultValue: string = ''
      • validation: Validation = ''

      Returns this

    • Register a final positional argument that collects all remaining tokens.

      Parameters

      • name: string
      • description: string
      • validation: Validation = ''

      Returns this

    • Register a command (spec section 1.7) and return it, to register its options and arguments on.

      Parameters

      • name: string
      • description: string

      Returns Cli

    • Tab-separated completion records (spec section 9). words are the words typed after the program name; a program with commands follows them.

      Parameters

      • words: string[] = []

      Returns string

    • Shell script that enables completion for this program (spec section 9): eval "$(prog --completion bash)". Undefined for an unknown shell.

      Parameters

      • shell: string

      Returns string | undefined

    • At most one of these options may be given.

      Parameters

      • ...longs: string[]

      Returns this

    • Register a positional argument using the legacy method name.

      Parameters

      • ...args: [
            name: string,
            description: string,
            defaultValue: string,
            validation: Validation,
        ]

      Returns this

      Use Cli.arg.

    • Register a variadic argument using the legacy method name.

      Parameters

      • ...args: [name: string, description: string, validation: Validation]

      Returns this

      Use Cli.argVariadic.

    • Register an option using the legacy method name.

      Parameters

      • ...args: [
            varName: string,
            long: string,
            short: string,
            defaultValue: string,
            description: string,
            group: string,
            validation: Validation,
        ]

      Returns this

      Use Cli.opt; kept for scripts written against getOpt.

    • Register a repeatable option using the legacy method name.

      Parameters

      • ...args: [
            varName: string,
            long: string,
            short: string,
            description: string,
            group: string,
            validation: Validation,
        ]

      Returns this

      Use Cli.optArray.

    • Whether an option came from CLI, config, or environment rather than a default.

      Parameters

      • long: string

      Returns boolean

    • Whether an option was explicitly supplied on the command line.

      Parameters

      • long: string

      Returns boolean

    • At least one of these options must be given.

      Parameters

      • ...longs: string[]

      Returns this

    • Register an option. defaultValue is a default, 'flag' for a boolean flag, 'optional' for no default, or '' to make the option required.

      Parameters

      • varName: string
      • long: string
      • short: string
      • defaultValue: string
      • description: string
      • group: string = 'Options'
      • validation: Validation = ''

      Returns this

    • Register a repeatable option whose values accumulate into a list.

      Parameters

      • varName: string
      • long: string
      • short: string
      • description: string
      • group: string = 'Options'
      • validation: Validation = ''

      Returns this

    • Declare an external executable required at parse time; description and install hint explain a missing dependency.

      Parameters

      • command: string
      • description: string
      • installHint: string = ''

      Returns this

    • When the first option is given, the others must be too.

      Parameters

      • long: string
      • ...longs: string[]

      Returns this

    • Parse and act like a CLI: handles --help, --help-json-schema and --bash-completion, prints errors and exits on failure. Returns the values.

      Parameters

      • argv: string[] = ...

      Returns Record<string, Value>

    • option holds the config file path; prefixes is comma-separated.

      Parameters

      • option: string
      • prefixes: string

      Returns this

    • Set the description shown below the usage line; returns this CLI.

      Parameters

      • text: string

      Returns this

    • What running the program does: read-only, idempotent, destructive, network.

      Parameters

      Returns this

    • Set the text displayed after the help sections; returns this CLI.

      Parameters

      • text: string

      Returns this

    • Fallback dirs (relative to root) for bare relative values of a path option.

      Parameters

      • long: string
      • dirs: string | string[]

      Returns this

    • What the program reads on stdin; contentType is a MIME type or a comma-separated list.

      Parameters

      • description: string
      • contentType: string = ''

      Returns this

    • What the program writes on stdout; undeclared means text.

      Parameters

      • description: string
      • contentType: string = ''

      Returns this