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

    Class GetDotenvCli<TOptions, TArgs, TOpts, TGlobal>

    Plugin-first CLI host for get-dotenv. Extends Commander.Command.

    Responsibilities:

    • Resolve options strictly and compute dotenv context (resolveAndLoad).
    • Expose a stable accessor for the current context (getCtx).
    • Provide a namespacing helper (ns).
    • Support composable plugins with parent → children install and afterResolve.

    Type Parameters

    Hierarchy

    Implements

    Index
    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,
    >[]
    • Run afterResolve hooks for registered plugins (parent → children). When commandPath is provided, only the matching branch of the plugin tree runs; otherwise all plugins run (backward compatibility).

      Each prefix of the command path is matched against the plugins' realized mount paths (effective namespaces, override > default), the same paths that key config slices. Intermediate matches run their own afterResolve hook. The deepest match runs afterResolve for itself and all its descendants.

      Parameters

      • ctx: GetDotenvCliCtx<TOptions>

        The resolved host context passed to each hook.

      • OptionalcommandPath: string[]

        Command names from the root to the invoked command.

      Returns Promise<void>

    • 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]');
    • Attach legacy/base root flags to this CLI instance. Delegates to the pure builder in attachRootOptions.ts.

      The flags get no Commander defaults: opts() holds only values given on the command line. defaults only shapes the help text.

      Parameters

      Returns this

    • Branding helper: set CLI name/description/version and optional help header. If version is omitted and importMetaUrl is provided, attempts to read the nearest package.json version (best-effort; non-fatal on failure).

      importMetaUrl also sets the host root (the packaged config layer, Decision 23); the last of the constructor and brand() to give one wins.

      -V, --version is registered once, the first time a version is known. A later brand() only updates the version it prints, so calling brand() again (as every createCli run does) is safe (#87).

      Parameters

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

    • 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

    • 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>

    • 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

    • Evaluate dynamic descriptions for this command and all descendants using the provided resolved configuration. Mutates the Option.description in place so Commander help renders updated text.

      Parameters

      Returns void

    • 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

    • Output help information and exit.

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

      Parameters

      Returns never

    • Parameters

      • cb: (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

    • 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

    • 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

      • cb: (str: string) => string

      Returns void

      since v7

    • Parse argv: install the plugin tree, build the qualified-name table, normalize the argv, render top-level help or hand the normalized argv to Commander (spec 4.4).

      • argv and { from } work as in Commander (including node -e/-p and Electron detection when both are omitted); only the user arguments are normalized, and Commander parses them with { from: 'user' }.
      • On the first call the host installs its plugins, then builds its qualified-name table from the root's current name (so call brand() first) and registers each command's hidden terminator. Building the table throws on a qualified-name collision or a plain long option that starts with <alias>-. Later calls reuse the table.
      • normalizeArgv moves every qualified option to its owner. A normalization error is reported through this.error(): exit code 1, or a thrown CommanderError under exitOverride().
      • -h that the argv walk leaves with the root renders top-level help (its context resolved without side effects) instead of a parse.
      • Under --debug (or --<alias>-debug) or GETDOTENV_DEBUG, one [getdotenv:argv] typed: [...] normalized: [...] line goes to stderr.

      Commander sets rawArgs only on the command being parsed (this root), to the normalized user arguments; subcommands keep an empty rawArgs.

      Parameters

      • Optionalargv: readonly string[]

        Arguments, as for Commander's parseAsync.

      • OptionalparseOptions: ParseOptions

        Commander's parse options (from).

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

      This command.

    • 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,
      >

    • Resolve options (strict) and compute dotenv context. Stores the context on the instance under a symbol.

      Parameters

      • customOptions: Partial<TOptions> = {}

        Partial options to overlay for this invocation.

      • Optionalopts: ResolveAndLoadOptions

        Optional resolver behavior switches.

        • runAfterResolve (default true): when false, skips running plugin afterResolve hooks. Useful for top-level help rendering to avoid long-running side-effects while still evaluating dynamic help text.
        • invokedSubcommand: when provided, only the plugin subtree whose realized mount path is this name (its effective namespace: override > default) runs afterResolve hooks. When omitted, all plugins run afterResolve (backward compatibility).

      Returns Promise<GetDotenvCliCtx<TOptions>>

    • 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

    • 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