@karmaniverous/get-dotenv
    Preparing search index...

    Interface GetDotenvCliPublic<TOptions, TArgs, TOpts, TGlobal>

    Structural public interface for the host exposed to plugins.

    • Extends Commander.Command so plugins can attach options/commands/hooks.
    • Adds host-specific helpers used by built-in plugins.

    Purpose: remove nominal class identity (private fields) from the plugin seam to avoid TS2379 under exactOptionalPropertyTypes in downstream consumers.

    interface GetDotenvCliPublic<
        TOptions extends GetDotenvOptions = GetDotenvOptions,
        TArgs extends unknown[] = [],
        TOpts extends OptionValues = {},
        TGlobal extends OptionValues = {},
    > {
        args: string[];
        commands: readonly CommandUnknownOpts[];
        options: readonly Option<
            "",
            undefined,
            undefined,
            undefined,
            false,
            undefined,
        >[];
        parent: CommandUnknownOpts
        | null;
        processedArgs: TArgs;
        registeredArguments: readonly Argument<
            "",
            undefined,
            undefined,
            undefined,
            undefined,
        >[];
        action(
            fn: (
                this: this,
                ...args: [
                    ...TArgs[],
                    TOpts,
                    GetDotenvCliPublic<TOptions, TArgs, TOpts, TGlobal>,
                ],
            ) => void | Promise<void>,
        ): this;
        addArgument<
            Usage extends string,
            DefaultT,
            CoerceT,
            ArgRequired extends boolean | undefined,
            ChoicesT,
        >(
            arg: Argument<Usage, DefaultT, CoerceT, ArgRequired, ChoicesT>,
        ): Command<
            [
                ...TArgs[],
                InferArgument<Usage, DefaultT, CoerceT, ArgRequired, ChoicesT>,
            ],
            TOpts,
            TGlobal,
        >;
        addCommand(cmd: CommandUnknownOpts, opts?: CommandOptions): this;
        addHelpCommand(cmd: Command): this;
        addHelpCommand(nameAndArgs: string, description?: string): this;
        addHelpCommand(enable?: boolean): this;
        addHelpOption(option: Option): this;
        addHelpText(position: AddHelpTextPosition, text: string): this;
        addHelpText(
            position: AddHelpTextPosition,
            text: (context: AddHelpTextContext) => string,
        ): this;
        addOption<
            Usage extends string,
            PresetT,
            DefaultT,
            CoerceT,
            Mandatory extends boolean,
            ChoicesT,
        >(
            option: Option<Usage, PresetT, DefaultT, CoerceT, Mandatory, ChoicesT>,
        ): Command<
            TArgs,
            InferOptions<
                TOpts,
                Usage,
                DefaultT,
                CoerceT,
                Mandatory,
                PresetT,
                ChoicesT,
            >,
            TGlobal,
        >;
        alias(alias: string): this;
        alias(): string;
        aliases(aliases: readonly string[]): this;
        aliases(): string[];
        allowExcessArguments(allowExcess?: boolean): this;
        allowUnknownOption(allowUnknown?: boolean): this;
        argument<S extends string, T>(
            flags: S,
            description: string,
            parseArg: (value: string, previous: T) => T,
        ): Command<
            [...TArgs[], InferArgument<S, undefined, T, undefined, undefined>],
            TOpts,
            TGlobal,
        >;
        argument<S extends string, T>(
            flags: S,
            description: string,
            parseArg: (value: string, previous: T) => T,
            defaultValue: T,
        ): Command<
            [...TArgs[], InferArgument<S, T, T, undefined, undefined>],
            TOpts,
            TGlobal,
        >;
        argument<S extends string>(
            usage: S,
            description?: string,
        ): Command<
            [
                ...TArgs[],
                InferArgument<S, undefined, undefined, undefined, undefined>,
            ],
            TOpts,
            TGlobal,
        >;
        argument<S extends string, DefaultT>(
            usage: S,
            description: string,
            defaultValue: DefaultT,
        ): Command<
            [
                ...TArgs[],
                InferArgument<S, DefaultT, undefined, undefined, undefined>,
            ],
            TOpts,
            TGlobal,
        >;
        arguments<Names extends string>(
            args: Names,
        ): Command<[...TArgs[], ...InferArguments<Names>[]], TOpts, TGlobal>;
        combineFlagAndOptionalValue(combine?: boolean): this;
        command<Usage extends string>(
            nameAndArgs: Usage,
            opts?: CommandOptions,
        ): Command<[...InferCommandArguments<Usage>[]], {}, TOpts & TGlobal>;
        command(
            nameAndArgs: string,
            description: string,
            opts?: ExecutableCommandOptions,
        ): this;
        commandsGroup(heading: string): this;
        commandsGroup(): string;
        configureHelp(configuration: HelpConfiguration): this;
        configureHelp(): HelpConfiguration;
        configureOutput(configuration: OutputConfiguration): this;
        configureOutput(): OutputConfiguration;
        copyInheritedSettings(sourceCommand: CommandUnknownOpts): this;
        createArgument<Usage extends string>(
            name: Usage,
            description?: string,
        ): Argument<Usage>;
        createCommand(name?: string): Command;
        createDynamicOption<Usage extends string>(
            flags: Usage,
            desc: (cfg: ResolvedHelpConfig) => string,
            parser?: (value: string, previous?: unknown) => unknown,
            defaultValue?: unknown,
        ): Option<Usage>;
        createDynamicOption<Usage extends string, TValue = unknown>(
            flags: Usage,
            desc: (cfg: ResolvedHelpConfig) => string,
            parser: (value: string, previous?: TValue) => TValue,
            defaultValue?: TValue,
        ): Option<Usage>;
        createHelp(): Help;
        createOption<Usage extends string>(
            flags: Usage,
            description?: string,
        ): Option<Usage>;
        description(str: string): this;
        description(str: string, argsDescription: Record<string, string>): this;
        description(): string;
        enablePositionalOptions(positional?: boolean): this;
        error(message: string, errorOptions?: ErrorOptions): never;
        executableDir(path: string): this;
        executableDir(): string | null;
        exitOverride(callback?: (err: CommanderError) => void): this;
        getCtx(): GetDotenvCliCtx<TOptions>;
        getOptionValue<K extends string | number | symbol>(key: K): TOpts[K];
        getOptionValue(key: string): unknown;
        getOptionValueSource<K extends string | number | symbol>(
            key: K,
        ): OptionValueSource;
        getOptionValueSource(key: string): OptionValueSource;
        getOptionValueSourceWithGlobals<K extends string | number | symbol>(
            key: K,
        ): OptionValueSource;
        getOptionValueSourceWithGlobals(key: string): OptionValueSource;
        hasCtx(): boolean;
        help(context?: HelpContext): never;
        help(cb?: (str: string) => string): never;
        helpCommand(nameAndArgs: string, description?: string): this;
        helpCommand(enable: boolean): this;
        helpGroup(heading: string): this;
        helpGroup(): string;
        helpInformation(context?: HelpContext): string;
        helpOption(flags?: string | boolean, description?: string): this;
        hook(
            event: HookEvent,
            listener: (
                thisCommand: this,
                actionCommand: CommandUnknownOpts,
            ) => void | Promise<void>,
        ): this;
        name(str: string): this;
        name(): string;
        nameFromFilename(filename: string): this;
        ns<Usage extends string>(
            name: Usage,
        ): GetDotenvCliPublic<
            TOptions,
            [...TArgs[], ...InferCommandArguments<Usage>[]],
            {},
            TOpts & TGlobal,
        >;
        on(event: string | symbol, listener: (...args: any[]) => void): this;
        option<S extends string>(
            usage: S,
            description?: string,
        ): Command<
            TArgs,
            InferOptions<TOpts, S, undefined, undefined, false, undefined, undefined>,
            TGlobal,
        >;
        option<S extends string, DefaultT extends string | boolean | string[] | []>(
            usage: S,
            description?: string,
            defaultValue?: DefaultT,
        ): Command<
            TArgs,
            InferOptions<TOpts, S, DefaultT, undefined, false, undefined, undefined>,
            TGlobal,
        >;
        option<S extends string, T>(
            usage: S,
            description: string,
            parseArg: (value: string, previous: T) => T,
        ): Command<
            TArgs,
            InferOptions<TOpts, S, undefined, T, false, undefined, undefined>,
            TGlobal,
        >;
        option<S extends string, T>(
            usage: S,
            description: string,
            parseArg: (value: string, previous: T) => T,
            defaultValue?: T,
        ): Command<
            TArgs,
            InferOptions<TOpts, S, T, T, false, undefined, undefined>,
            TGlobal,
        >;
        optionsGroup(heading: string): this;
        optionsGroup(): string;
        opts(): TOpts;
        optsWithGlobals(): Resolve<TOpts & TGlobal>;
        outputHelp(context?: HelpContext): void;
        outputHelp(cb?: (str: string) => string): void;
        parse(argv?: readonly string[], options?: ParseOptions): this;
        parseAsync(
            argv?: readonly string[],
            options?: ParseOptions,
        ): Promise<GetDotenvCliPublic<TOptions, TArgs, TOpts, TGlobal>>;
        parseOptions(argv: string[]): ParseOptionsResult;
        passThroughOptions(passThrough?: boolean): this;
        requiredOption<S extends string>(
            usage: S,
            description?: string,
        ): Command<
            TArgs,
            InferOptions<TOpts, S, undefined, undefined, true, undefined, undefined>,
            TGlobal,
        >;
        requiredOption<
            S extends string,
            DefaultT extends string | boolean | string[],
        >(
            usage: S,
            description?: string,
            defaultValue?: DefaultT,
        ): Command<
            TArgs,
            InferOptions<TOpts, S, DefaultT, undefined, true, undefined, undefined>,
            TGlobal,
        >;
        requiredOption<S extends string, T>(
            usage: S,
            description: string,
            parseArg: (value: string, previous: T) => T,
        ): Command<
            TArgs,
            InferOptions<TOpts, S, undefined, T, true, undefined, undefined>,
            TGlobal,
        >;
        requiredOption<S extends string, T, D>(
            usage: S,
            description: string,
            parseArg: (value: string, previous: T) => T,
            defaultValue?: D,
        ): Command<
            TArgs,
            InferOptions<TOpts, S, D, T, true, undefined, undefined>,
            TGlobal,
        >;
        resolveAndLoad(
            customOptions?: Partial<TOptions>,
            opts?: ResolveAndLoadOptions,
        ): Promise<GetDotenvCliCtx<TOptions>>;
        restoreStateBeforeParse(): void;
        saveStateBeforeParse(): void;
        setOptionGroup(opt: Option, group: string): void;
        setOptionValue<K extends string | number | symbol>(
            key: K,
            value: unknown,
        ): this;
        setOptionValue(key: string, value: unknown): this;
        setOptionValueWithSource<K extends string | number | symbol>(
            key: K,
            value: unknown,
            source: OptionValueSource,
        ): this;
        setOptionValueWithSource(
            key: string,
            value: unknown,
            source: OptionValueSource,
        ): this;
        showHelpAfterError(displayHelp?: string | boolean): this;
        showSuggestionAfterError(displaySuggestion?: boolean): this;
        storeOptionsAsProperties<T extends OptionValues>(): GetDotenvCliPublic<
            TOptions,
            TArgs,
            TOpts,
            TGlobal,
        > & T;
        storeOptionsAsProperties<T extends OptionValues>(
            storeAsProperties: true,
        ): GetDotenvCliPublic<TOptions, TArgs, TOpts, TGlobal> & T;
        storeOptionsAsProperties(storeAsProperties?: boolean): this;
        summary(str: string): this;
        summary(): string;
        usage(str: string): this;
        usage(): string;
        version(str: string, flags?: string, description?: string): this;
        version(): string | undefined;
    }

    Type Parameters

    Hierarchy

    Implemented by

    Index

    Properties

    args: string[]
    commands: readonly CommandUnknownOpts[]
    options: readonly Option<"", undefined, undefined, undefined, false, undefined>[]
    parent: CommandUnknownOpts | null
    processedArgs: TArgs
    registeredArguments: readonly Argument<
        "",
        undefined,
        undefined,
        undefined,
        undefined,
    >[]

    Methods

    • Register callback fn for the command.

      Parameters

      Returns this

      this command for chaining

      program
      .command('serve')
      .description('start service')
      .action(function() {
      // do work here
      });
    • Add prepared custom help command.

      Parameters

      Returns this

    • Parameters

      • nameAndArgs: string
      • Optionaldescription: string

      Returns this

      since v12, instead use helpCommand

    • Parameters

      • Optionalenable: boolean

      Returns this

      since v12, instead use helpCommand

    • Supply your own option to use for the built-in help option. This is an alternative to using helpOption() to customise the flags and description etc.

      Parameters

      Returns this

    • Add additional text to be displayed with the built-in help.

      Position is 'before' or 'after' to affect just this command, and 'beforeAll' or 'afterAll' to affect this command and all its subcommands.

      Parameters

      Returns this

    • Add additional text to be displayed with the built-in help.

      Position is 'before' or 'after' to affect just this command, and 'beforeAll' or 'afterAll' to affect this command and all its subcommands.

      Parameters

      Returns this

    • Set an alias for the command.

      You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.

      Parameters

      • alias: string

      Returns this

      this command for chaining

    • Get alias for the command.

      Returns string

    • Set aliases for the command.

      Only the first alias is shown in the auto-generated help.

      Parameters

      • aliases: readonly string[]

      Returns this

      this command for chaining

    • Get aliases for the command.

      Returns string[]

    • Allow excess command-arguments on the command line. Pass false to make excess arguments an error.

      Parameters

      • OptionalallowExcess: boolean

      Returns this

      this command for chaining

    • Allow unknown options on the command line.

      Parameters

      • OptionalallowUnknown: boolean

      Returns this

      this command for chaining

    • Define argument syntax for command.

      The default is that the argument is required, and you can explicitly indicate this with <> around the name. Put [] around the name for an optional argument.

      Type Parameters

      • S extends string
      • T

      Parameters

      • flags: S
      • description: string
      • parseArg: (value: string, previous: T) => T

      Returns Command<
          [...TArgs[], InferArgument<S, undefined, T, undefined, undefined>],
          TOpts,
          TGlobal,
      >

      this command for chaining

      program.argument('<input-file>');
      program.argument('[output-file]');
    • Define argument syntax for command.

      The default is that the argument is required, and you can explicitly indicate this with <> around the name. Put [] around the name for an optional argument.

      Type Parameters

      • S extends string
      • T

      Parameters

      • flags: S
      • description: string
      • parseArg: (value: string, previous: T) => T
      • defaultValue: T

      Returns Command<
          [...TArgs[], InferArgument<S, T, T, undefined, undefined>],
          TOpts,
          TGlobal,
      >

      this command for chaining

      program.argument('<input-file>');
      program.argument('[output-file]');
    • Define argument syntax for command.

      The default is that the argument is required, and you can explicitly indicate this with <> around the name. Put [] around the name for an optional argument.

      Type Parameters

      • S extends string

      Parameters

      • usage: S
      • Optionaldescription: string

      Returns Command<
          [
              ...TArgs[],
              InferArgument<S, undefined, undefined, undefined, undefined>,
          ],
          TOpts,
          TGlobal,
      >

      this command for chaining

      program.argument('<input-file>');
      program.argument('[output-file]');
    • Define argument syntax for command.

      The default is that the argument is required, and you can explicitly indicate this with <> around the name. Put [] around the name for an optional argument.

      Type Parameters

      • S extends string
      • DefaultT

      Parameters

      • usage: S
      • description: string
      • defaultValue: DefaultT

      Returns Command<
          [
              ...TArgs[],
              InferArgument<S, DefaultT, undefined, undefined, undefined>,
          ],
          TOpts,
          TGlobal,
      >

      this command for chaining

      program.argument('<input-file>');
      program.argument('[output-file]');
    • Alter parsing of short flags with optional values.

      Parameters

      • Optionalcombine: boolean

      Returns this

      this command for chaining

      // for `.option('-f,--flag [value]'):
      .combineFlagAndOptionalValue(true) // `-f80` is treated like `--flag=80`, this is the default behaviour
      .combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
    • Define a command, implemented using an action handler.

      Type Parameters

      • Usage extends string

      Parameters

      • nameAndArgs: Usage

        command name and arguments, args are <required> or [optional] and last may also be variadic...

      • Optionalopts: CommandOptions

        configuration options

      Returns Command<[...InferCommandArguments<Usage>[]], {}, TOpts & TGlobal>

      new command

      The command description is supplied using .description, not as a parameter to .command.

      program
      .command('clone <source> [destination]')
      .description('clone a repository into a newly created directory')
      .action((source, destination) => {
      console.log('clone command called');
      });
    • Define a command, implemented in a separate executable file.

      Parameters

      • nameAndArgs: string

        command name and arguments, args are <required> or [optional] and last may also be variadic...

      • description: string

        description of executable command

      • Optionalopts: ExecutableCommandOptions

        configuration options

      Returns this

      this command for chaining

      The command description is supplied as the second parameter to .command.

       program
      .command('start <service>', 'start named service')
      .command('stop [service]', 'stop named service, or all if no name supplied');
    • Set the default help group heading for subcommands added to this command. (This does not override a group set directly on the subcommand using .helpGroup().)

      Parameters

      • heading: string

      Returns this

      this command for chaining

      program.commandsGroup('Development Commands:);
      program.command('watch')...
      program.command('lint')...
      ...
    • Get the default help group heading for subcommands added to this command.

      Returns string

    • The default output goes to stdout and stderr. You can customise this for special applications. You can also customise the display of errors by overriding outputError.

      The configuration properties are all functions:

      // functions to change where being written, stdout and stderr
      writeOut(str)
      writeErr(str)
      // matching functions to specify width for wrapping help
      getOutHelpWidth()
      getErrHelpWidth()
      // functions based on what is being written out
      outputError(str, write) // used for displaying errors, and not used for displaying help

      Parameters

      Returns this

    • Get configuration

      Returns OutputConfiguration

    • Copy settings that are useful to have in common across root command and subcommands.

      (Used internally when adding a command using .command() so subcommands inherit parent settings.)

      Parameters

      Returns this

    • Factory routine to create a new unattached argument.

      See .argument() for creating an attached argument, which uses this routine to create the argument. You can override createArgument to return a custom argument.

      Type Parameters

      • Usage extends string

      Parameters

      • name: Usage
      • Optionaldescription: string

      Returns Argument<Usage>

    • Factory routine to create a new unattached command.

      See .command() for creating an attached subcommand, which uses this routine to create the command. You can override createCommand to customise subcommands.

      Parameters

      • Optionalname: string

      Returns Command

    • You can customise the help with a subclass of Help by overriding createHelp, or by overriding Help properties using configureHelp().

      Returns Help

    • Factory routine to create a new unattached option.

      See .option() for creating an attached option, which uses this routine to create the option. You can override createOption to return a custom option.

      Type Parameters

      • Usage extends string

      Parameters

      • flags: Usage
      • Optionaldescription: string

      Returns Option<Usage>

    • Set the description.

      Parameters

      • str: string

      Returns this

      this command for chaining

    • Parameters

      • str: string
      • argsDescription: Record<string, string>

      Returns this

      since v8, instead use .argument to add command argument with description

    • Get the description.

      Returns string

    • Enable positional options. Positional means global options are specified before subcommands which lets subcommands reuse the same option names, and also enables subcommands to turn on passThroughOptions.

      The default behaviour is non-positional and global options may appear anywhere on the command line.

      Parameters

      • Optionalpositional: boolean

      Returns this

      this command for chaining

    • Display error message and exit (or call exitOverride).

      Parameters

      Returns never

    • Set the directory for searching for executable subcommands of this command.

      Parameters

      • path: string

      Returns this

      this command for chaining

      program.executableDir(__dirname);
      // or
      program.executableDir('subcommands');
    • Get the executable search directory.

      Returns string | null

    • Register callback to use as replacement for calling process.exit.

      Parameters

      Returns this

    • Retrieve option value.

      Type Parameters

      • K extends string | number | symbol

      Parameters

      • key: K

      Returns TOpts[K]

    • Retrieve option value.

      Parameters

      • key: string

      Returns unknown

    • Output help information and exit.

      Outputs built-in help, and custom text added using .addHelpText().

      Parameters

      Returns never

    • Parameters

      • Optionalcb: (str: string) => string

      Returns never

      since v7

    • Customise or override default help command. By default a help command is automatically added if your command has subcommands.

      Parameters

      • nameAndArgs: string
      • Optionaldescription: string

      Returns this

      program.helpCommand('help [cmd]');
      program.helpCommand('help [cmd]', 'show help');
      program.helpCommand(false); // suppress default help command
      program.helpCommand(true); // add help command even if no subcommands
    • Customise or override default help command. By default a help command is automatically added if your command has subcommands.

      Parameters

      • enable: boolean

      Returns this

      program.helpCommand('help [cmd]');
      program.helpCommand('help [cmd]', 'show help');
      program.helpCommand(false); // suppress default help command
      program.helpCommand(true); // add help command even if no subcommands
    • Set the help group heading for this subcommand in parent command's help.

      Parameters

      • heading: string

      Returns this

      this command for chaining

    • Get the help group heading for this subcommand in parent command's help.

      Returns string

    • Return command help documentation.

      Parameters

      Returns string

    • You can pass in flags and a description to override the help flags and help description for your command. Pass in false to disable the built-in help option.

      Parameters

      • Optionalflags: string | boolean
      • Optionaldescription: string

      Returns this

    • Add hook for life cycle event.

      Parameters

      Returns this

    • Set the name of the command.

      Parameters

      • str: string

      Returns this

      this command for chaining

    • Get the name of the command.

      Returns string

    • Set the name of the command from script filename, such as process.argv[1], or require.main.filename, or __filename.

      (Used internally and public although not documented in README.)

      Parameters

      • filename: string

      Returns this

      this command for chaining

      program.nameFromFilename(require.main.filename);
      
    • Add a listener (callback) for when events occur. (Implemented using EventEmitter.)

      Parameters

      • event: string | symbol
      • listener: (...args: any[]) => void

      Returns this

    • Define option with flags, description, and optional argument parsing function or defaultValue or both.

      The flags string contains the short and/or long flags, separated by comma, a pipe or space. A required option-argument is indicated by <> and an optional option-argument by [].

      See the README for more details, and see also addOption() and requiredOption().

      Type Parameters

      • S extends string

      Parameters

      • usage: S
      • Optionaldescription: string

      Returns Command<
          TArgs,
          InferOptions<TOpts, S, undefined, undefined, false, undefined, undefined>,
          TGlobal,
      >

      this command for chaining

      program
      .option('-p, --pepper', 'add pepper')
      .option('-p, --pizza-type <TYPE>', 'type of pizza') // required option-argument
      .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
      .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function
    • Define option with flags, description, and optional argument parsing function or defaultValue or both.

      The flags string contains the short and/or long flags, separated by comma, a pipe or space. A required option-argument is indicated by <> and an optional option-argument by [].

      See the README for more details, and see also addOption() and requiredOption().

      Type Parameters

      • S extends string
      • DefaultT extends string | boolean | string[] | []

      Parameters

      • usage: S
      • Optionaldescription: string
      • OptionaldefaultValue: DefaultT

      Returns Command<
          TArgs,
          InferOptions<TOpts, S, DefaultT, undefined, false, undefined, undefined>,
          TGlobal,
      >

      this command for chaining

      program
      .option('-p, --pepper', 'add pepper')
      .option('-p, --pizza-type <TYPE>', 'type of pizza') // required option-argument
      .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
      .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function
    • Define option with flags, description, and optional argument parsing function or defaultValue or both.

      The flags string contains the short and/or long flags, separated by comma, a pipe or space. A required option-argument is indicated by <> and an optional option-argument by [].

      See the README for more details, and see also addOption() and requiredOption().

      Type Parameters

      • S extends string
      • T

      Parameters

      • usage: S
      • description: string
      • parseArg: (value: string, previous: T) => T

      Returns Command<
          TArgs,
          InferOptions<TOpts, S, undefined, T, false, undefined, undefined>,
          TGlobal,
      >

      this command for chaining

      program
      .option('-p, --pepper', 'add pepper')
      .option('-p, --pizza-type <TYPE>', 'type of pizza') // required option-argument
      .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
      .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function
    • Define option with flags, description, and optional argument parsing function or defaultValue or both.

      The flags string contains the short and/or long flags, separated by comma, a pipe or space. A required option-argument is indicated by <> and an optional option-argument by [].

      See the README for more details, and see also addOption() and requiredOption().

      Type Parameters

      • S extends string
      • T

      Parameters

      • usage: S
      • description: string
      • parseArg: (value: string, previous: T) => T
      • OptionaldefaultValue: T

      Returns Command<
          TArgs,
          InferOptions<TOpts, S, T, T, false, undefined, undefined>,
          TGlobal,
      >

      this command for chaining

      program
      .option('-p, --pepper', 'add pepper')
      .option('-p, --pizza-type <TYPE>', 'type of pizza') // required option-argument
      .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
      .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function
    • Set the default help group heading for options added to this command. (This does not override a group set directly on the option using .helpGroup().)

      Parameters

      • heading: string

      Returns this

      this command for chaining

      program
      .optionsGroup('Development Options:')
      .option('-d, --debug', 'output extra debugging')
      .option('-p, --profile', 'output profiling information')
    • Get the default help group heading for options added to this command.

      Returns string

    • Return an object containing local option values as key-value pairs

      Returns TOpts

    • Output help information for this command.

      Outputs built-in help, and custom text added using .addHelpText().

      Parameters

      Returns void

    • Parameters

      • Optionalcb: (str: string) => string

      Returns void

      since v7

    • Parse argv, setting options and invoking commands when defined.

      The default expectation is that the arguments are from node and have the application as argv[0] and the script being run in argv[1], with user parameters after that.

      Parameters

      • Optionalargv: readonly string[]
      • Optionaloptions: ParseOptions

      Returns this

      this command for chaining

      program.parse(process.argv);
      program.parse(); // implicitly use process.argv and auto-detect node vs electron conventions
      program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
    • Parse argv, setting options and invoking commands when defined.

      Use parseAsync instead of parse if any of your action handlers are async. Returns a Promise.

      The default expectation is that the arguments are from node and have the application as argv[0] and the script being run in argv[1], with user parameters after that.

      Parameters

      • Optionalargv: readonly string[]
      • Optionaloptions: ParseOptions

      Returns Promise<GetDotenvCliPublic<TOptions, TArgs, TOpts, TGlobal>>

      Promise

      program.parseAsync(process.argv);
      program.parseAsync(); // implicitly use process.argv and auto-detect node vs electron conventions
      program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
    • Parse options from argv removing known options, and return argv split into operands and unknown arguments.

      argv => operands, unknown
      --known kkk op => [op], []
      op --known kkk => [op], []
      sub --unknown uuu op => [sub], [--unknown uuu op]
      sub -- --unknown uuu op => [sub --unknown uuu op], []
      

      Parameters

      • argv: string[]

      Returns ParseOptionsResult

    • Pass through options that come after command-arguments rather than treat them as command-options, so actual command-options come before command-arguments. Turning this on for a subcommand requires positional options to have been enabled on the program (parent commands).

      The default behaviour is non-positional and options may appear before or after command-arguments.

      Parameters

      • OptionalpassThrough: boolean

      Returns this

      this command for chaining

    • Define a required option, which must have a value after parsing. This usually means the option must be specified on the command line. (Otherwise the same as .option().)

      The flags string contains the short and/or long flags, separated by comma, a pipe or space.

      Type Parameters

      • S extends string

      Parameters

      • usage: S
      • Optionaldescription: string

      Returns Command<
          TArgs,
          InferOptions<TOpts, S, undefined, undefined, true, undefined, undefined>,
          TGlobal,
      >

    • Define a required option, which must have a value after parsing. This usually means the option must be specified on the command line. (Otherwise the same as .option().)

      The flags string contains the short and/or long flags, separated by comma, a pipe or space.

      Type Parameters

      • S extends string
      • DefaultT extends string | boolean | string[]

      Parameters

      • usage: S
      • Optionaldescription: string
      • OptionaldefaultValue: DefaultT

      Returns Command<
          TArgs,
          InferOptions<TOpts, S, DefaultT, undefined, true, undefined, undefined>,
          TGlobal,
      >

    • Define a required option, which must have a value after parsing. This usually means the option must be specified on the command line. (Otherwise the same as .option().)

      The flags string contains the short and/or long flags, separated by comma, a pipe or space.

      Type Parameters

      • S extends string
      • T

      Parameters

      • usage: S
      • description: string
      • parseArg: (value: string, previous: T) => T

      Returns Command<
          TArgs,
          InferOptions<TOpts, S, undefined, T, true, undefined, undefined>,
          TGlobal,
      >

    • Define a required option, which must have a value after parsing. This usually means the option must be specified on the command line. (Otherwise the same as .option().)

      The flags string contains the short and/or long flags, separated by comma, a pipe or space.

      Type Parameters

      • S extends string
      • T
      • D

      Parameters

      • usage: S
      • description: string
      • parseArg: (value: string, previous: T) => T
      • OptionaldefaultValue: D

      Returns Command<
          TArgs,
          InferOptions<TOpts, S, D, T, true, undefined, undefined>,
          TGlobal,
      >

    • Restore state before parse for calls after the first. Not usually called directly, but available for subclasses to save their custom state.

      This is called in a lazy way. Only commands used in parsing chain will have state restored.

      Returns void

    • Called the first time parse is called to save state and allow a restore before subsequent calls to parse. Not usually called directly, but available for subclasses to save their custom state.

      This is called in a lazy way. Only commands used in parsing chain will have state saved.

      Returns void

    • Store option value.

      Type Parameters

      • K extends string | number | symbol

      Parameters

      • key: K
      • value: unknown

      Returns this

    • Store option value.

      Parameters

      • key: string
      • value: unknown

      Returns this

    • Store option value and where the value came from.

      Type Parameters

      • K extends string | number | symbol

      Parameters

      Returns this

    • Store option value and where the value came from.

      Parameters

      Returns this

    • Display the help or a custom message after an error occurs.

      Parameters

      • OptionaldisplayHelp: string | boolean

      Returns this

    • Display suggestion of similar commands for unknown commands, or options for unknown options.

      Parameters

      • OptionaldisplaySuggestion: boolean

      Returns this

    • Set the summary. Used when listed as subcommand of parent.

      Parameters

      • str: string

      Returns this

      this command for chaining

    • Get the summary.

      Returns string

    • Set the command usage.

      Parameters

      • str: string

      Returns this

      this command for chaining

    • Get the command usage.

      Returns string

    • Set the program version to str.

      This method auto-registers the "-V, --version" flag which will print the version number when passed.

      You can optionally supply the flags and description to override the defaults.

      Parameters

      • str: string
      • Optionalflags: string
      • Optionaldescription: string

      Returns this

    • Get the program version.

      Returns string | undefined