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

    Class GetDotenvCli<TOptions>

    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.

    NOTE: This host is additive and does not alter the legacy CLI.

    Type Parameters

    Hierarchy

    • Command
      • GetDotenvCli
    Index

    Constructors

    Properties

    args: string[]
    commands: readonly Command[]
    options: readonly Option[]
    parent: null | Command
    processedArgs: any[]
    registeredArguments: readonly Argument[]

    Methods

    • Register callback fn for the command.

      Parameters

      • fn: (this: this, ...args: any[]) => void | Promise<void>

      Returns this

      this command for chaining

      program
      .command('serve')
      .description('start service')
      .action(function() {
      // do work here
      });
    • Define argument syntax for command, adding a prepared argument.

      Parameters

      • arg: Argument

      Returns this

      this command for chaining

    • Add a prepared subcommand.

      See .command() for creating an attached subcommand which inherits settings from its parent.

      Parameters

      • cmd: Command
      • Optionalopts: CommandOptions

      Returns this

      this command for chaining

    • Add prepared custom help command.

      Parameters

      • cmd: Command

      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

      • option: Option

      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

      • position: AddHelpTextPosition
      • text: string

      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

      • position: AddHelpTextPosition
      • text: (context: AddHelpTextContext) => string

      Returns this

    • Add a prepared Option.

      See .option() and .requiredOption() for creating and attaching an option in a single call.

      Parameters

      • option: Option

      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

      • T

      Parameters

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

      Returns this

      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.

      Parameters

      • name: string
      • Optionaldescription: string
      • OptionaldefaultValue: unknown

      Returns this

      this command for chaining

      program.argument('<input-file>');
      program.argument('[output-file]');
    • Define argument syntax for command, adding multiple at once (without descriptions).

      See also .argument().

      Parameters

      • names: string

      Returns this

      this command for chaining

      program.arguments('<cmd> [env]');
      
    • 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).

      Parameters

      • args: {
            description?: string;
            helpHeader?: string;
            importMetaUrl?: string;
            name?: string;
            version?: string;
        }

      Returns Promise<GetDotenvCli<TOptions>>

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

      Parameters

      • nameAndArgs: string

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

      • Optionalopts: CommandOptions

        configuration options

      Returns Command

      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

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

      Parameters

      • configuration: HelpConfiguration

      Returns this

    • Get configuration

      Returns HelpConfiguration

    • 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

      • configuration: OutputConfiguration

      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

      • sourceCommand: Command

      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.

      Parameters

      • name: string
      • Optionaldescription: string

      Returns Argument

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

      Parameters

      • flags: string
      • Optionaldescription: string

      Returns Option

    • 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

      • message: string
      • OptionalerrorOptions: ErrorOptions

      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 null | string

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

      Parameters

      • Optionalcallback: (err: CommanderError) => void

      Returns this

    • Retrieve option value.

      Parameters

      • key: string

      Returns any

    • Get source of option value.

      Parameters

      • key: string

      Returns OptionValueSource

    • Get source of option value. See also .optsWithGlobals().

      Parameters

      • key: string

      Returns OptionValueSource

    • Output help information and exit.

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

      Parameters

      • Optionalcontext: HelpContext

      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

      • Optionalcontext: HelpContext

      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

      • event: HookEvent
      • listener: (thisCommand: Command, actionCommand: Command) => void | Promise<void>

      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);
      
      • Convenience helper to create a namespaced subcommand.

      Parameters

      • name: string

      Returns Command

    • 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().

      Parameters

      • flags: string
      • Optionaldescription: string
      • OptionaldefaultValue: string | boolean | string[]

      Returns this

      this command for chaining

      program
      .option('-p, --pepper', 'add pepper')
      .option('--pt, --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

      • T

      Parameters

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

      Returns this

      this command for chaining

      program
      .option('-p, --pepper', 'add pepper')
      .option('--pt, --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
    • Parameters

      • flags: string
      • description: string
      • regexp: RegExp
      • OptionaldefaultValue: string | boolean | string[]

      Returns this

      since v7, instead use choices or a custom 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

      Type Parameters

      • T extends OptionValues

      Returns T

    • Return an object containing merged local and global option values as key-value pairs.

      Type Parameters

      • T extends OptionValues

      Returns T

    • Output help information for this command.

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

      Parameters

      • Optionalcontext: HelpContext

      Returns void

    • Parameters

      • Optionalcb: (str: string) => string

      Returns void

      since v7

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

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

      Call with no parameters to parse process.argv. Detects Electron and special node options like node --eval. Easy mode!

      Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are from:

      • 'node': default, argv[0] is the application and argv[1] is the script being run, with user arguments after that
      • 'electron': argv[0] is the application and argv[1] varies depending on whether the electron application is packaged
      • 'user': just user arguments

      Parameters

      • Optionalargv: readonly string[]
      • OptionalparseOptions: ParseOptions

      Returns this

      this command for chaining

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

      Call with no parameters to parse process.argv. Detects Electron and special node options like node --eval. Easy mode!

      Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are from:

      • 'node': default, argv[0] is the application and argv[1] is the script being run, with user arguments after that
      • 'electron': argv[0] is the application and argv[1] varies depending on whether the electron application is packaged
      • 'user': just user arguments

      Parameters

      • Optionalargv: readonly string[]
      • OptionalparseOptions: ParseOptions

      Returns Promise<GetDotenvCli<TOptions>>

      Promise

      await program.parseAsync(); // parse process.argv and auto-detect electron and special node flags
      await program.parseAsync(process.argv); // assume argv[0] is app and argv[1] is script
      await 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.

      Side effects: modifies command by storing options. Does not reset state if called again.

      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.

      Parameters

      • flags: string
      • Optionaldescription: string
      • OptionaldefaultValue: string | boolean | string[]

      Returns this

    • 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

      • T

      Parameters

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

      Returns this

    • Parameters

      • flags: string
      • description: string
      • regexp: RegExp
      • OptionaldefaultValue: string | boolean | string[]

      Returns this

      since v7, instead use choices or a custom function

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

      Parameters

      • key: string
      • value: unknown

      Returns this

    • Store option value and where the value came from.

      Parameters

      • key: string
      • value: unknown
      • source: OptionValueSource

      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

    • Whether to store option values as properties on command object, or store separately (specify false). In both cases the option values can be accessed using .opts().

      Type Parameters

      • T extends OptionValues

      Returns GetDotenvCli<TOptions> & T

      this command for chaining

    • Whether to store option values as properties on command object, or store separately (specify false). In both cases the option values can be accessed using .opts().

      Type Parameters

      • T extends OptionValues

      Parameters

      • storeAsProperties: true

      Returns GetDotenvCli<TOptions> & T

      this command for chaining

    • Whether to store option values as properties on command object, or store separately (specify false). In both cases the option values can be accessed using .opts().

      Parameters

      • OptionalstoreAsProperties: boolean

      Returns this

      this command for chaining

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

      Parameters

      • str: string

      Returns this

      this command for chaining

    • Get the summary.

      Returns string

    • Tag options added during the provided callback as 'app' for grouped help. Allows downstream apps to demarcate their root-level options.

      Type Parameters

      • T

      Parameters

      • fn: (root: Command) => T

      Returns T

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