KC's Workspace
    Preparing search index...
    Index

    Constructors

    • Parameters

      • flags: string
      • Optionaldescription: string

      Returns Option

    Properties

    argChoices?: string[]
    defaultValue?: any
    defaultValueDescription?: string
    description: string
    envVar?: string
    flags: string
    helpGroupHeading?: string
    hidden: boolean
    long?: string
    mandatory: boolean
    negate: boolean
    optional: boolean
    parseArg?: <T>(value: string, previous: T) => T
    presetArg?: unknown
    required: boolean
    short?: string
    variadic: boolean

    Methods

    • Set the custom handler for processing CLI option arguments into option values.

      Type Parameters

      • T

      Parameters

      • fn: (value: string, previous: T) => T

      Returns this

    • Return option name, in a camelcase format that can be used as an object attribute key.

      Returns string

    • Only allow option value to be one of choices.

      Parameters

      • values: readonly string[]

      Returns this

    • Add option name(s) that conflict with this option. An error will be displayed if conflicting options are found during parsing.

      Parameters

      • names: string | string[]

      Returns this

      new Option('--rgb').conflicts('cmyk');
      new Option('--js').conflicts(['ts', 'jsx']);
    • Set the default value, and optionally supply the description to be displayed in the help.

      Parameters

      • value: unknown
      • Optionaldescription: string

      Returns this

    • Set environment variable to check for option value.

      An environment variables is only used if when processed the current option value is undefined, or the source of the current value is 'default' or 'config' or 'env'.

      Parameters

      • name: string

      Returns this

    • Set the help group heading.

      Parameters

      • heading: string

      Returns this

    • Hide option in help.

      Parameters

      • Optionalhide: boolean

      Returns this

    • Specify implied option values for when this option is set and the implied options are not.

      The custom processing (parseArg) is not called on the implied values.

      Parameters

      Returns this

      program
      .addOption(new Option('--log', 'write logging information to file'))
      .addOption(new Option('--trace', 'log extra details').implies({ log: 'trace.txt' }));
    • Return whether a boolean option.

      Options are one of boolean, negated, required argument, or optional argument.

      Returns boolean

    • Whether the option is mandatory and must have a value after parsing.

      Parameters

      • Optionalmandatory: boolean

      Returns this

    • Return option name.

      Returns string

    • Preset to use when option used without option-argument, especially optional but also boolean and negated. The custom processing (parseArg) is called.

      Parameters

      • arg: unknown

      Returns this

      new Option('--color').default('GREYSCALE').preset('RGB');
      new Option('--donate [amount]').preset('20').argParser(parseFloat);