fynjs API
    Preparing search index...

    Interface CommandNode

    Object representation for an instance of a command on the CLI

    interface CommandNode {
        _jsonMeta?: CommandMeta;
        alias: string;
        argsList: string[];
        argsMap: Record<string, ArgumentValue>;
        argv: string[];
        cmdBase: Command;
        isGreedy: boolean;
        name: string;
        optCount: Record<string, number>;
        optNodes: Record<string, OptionNode>;
        subCmdNodes: Record<string, CommandNode>;
        get args(): Record<string, unknown>;
        get cmdChain(): CommandNode[];
        get error(): Error;
        get errors(): Error[];
        get hasErrors(): boolean;
        get jsonMeta(): CommandMeta;
        get options(): Record<string, Record<string, unknown>>;
        get opts(): Record<string, unknown>;
        get optsFull(): Record<string, Record<string, unknown>>;
        get parent(): ClapNode;
        get rootCmd(): CommandNode;
        get source(): Record<string, OptionSource>;
        get subCommands(): Record<string, CommandMeta>;
        addArg(arg: string): void;
        addCommandNode(node: CommandNode): CommandNode;
        addError(e: Error): void;
        addOptionNode(node: OptionNode): OptionNode;
        addVerbatimArg(arg: string): void;
        applyConfig(config: Record<string, any>, src?: OptionSource): void;
        applyDefaults(): void;
        checkRequiredOptions(missing?: any[]): any[];
        getErrorNodes(errorNodes?: ClapNode[]): ClapNode[];
        getExecCommands(
            cmds: CommandNode[],
            includeSubCommands: boolean,
        ): CommandNode[];
        getParent<T extends ClapNode = CommandNode>(): T;
        invokeExec(includeSubCommands: boolean, parsed?: ParseResult): number;
        invokeExecAsync(
            includeSubCommands: boolean,
            parsed?: ParseResult,
        ): Promise<number>;
        makeCamelCaseOptions(): void;
        removeOptionNode(name: string): void;
    }

    Hierarchy

    • ClapNode
      • CommandNode
    Index
    _jsonMeta?: CommandMeta
    alias: string

    Holds the name used in CLI to create the node, in case an alias was used. It could be the same as name.

    argsList: string[]

    arguments for this node

    argsMap: Record<string, ArgumentValue>
    argv: string[]

    As is verbatim CLI args that were consumbed by this node

    cmdBase: Command

    Associated Command data

    isGreedy: boolean

    Command consumes all remaining arguments blindly

    name: string

    command/option name

    optCount: Record<string, number>
    optNodes: Record<string, OptionNode>

    If this is a command node, then it can have options

    subCmdNodes: Record<string, CommandNode>

    sub command nodes

    • get args(): Record<string, unknown>

      get the arguments for this command

      Returns Record<string, unknown>

    • get cmdChain(): CommandNode[]

      Get the command chain (sequence from root to this command, including itself)

      Returns CommandNode[]

      Array of CommandNodes from root to this command

    • get error(): Error

      Returns Error

    • get errors(): Error[]

      Returns Error[]

    • get hasErrors(): boolean

      Returns boolean

    • get options(): Record<string, Record<string, unknown>>

      get the options with full values for this command

      Returns Record<string, Record<string, unknown>>

    • get opts(): Record<string, unknown>

      get the options for this command

      Returns Record<string, unknown>

    • get optsFull(): Record<string, Record<string, unknown>>

      Returns Record<string, Record<string, unknown>>

    • get parent(): ClapNode

      Returns ClapNode

    • get rootCmd(): CommandNode

      Get the root command by traversing up the parent chain until no more parent exists.

      Returns CommandNode

      The root CommandNode

    • get source(): Record<string, OptionSource>

      Returns Record<string, OptionSource>

    • get subCommands(): Record<string, CommandMeta>

      Returns Record<string, CommandMeta>

    • Add an arg to this node

      Parameters

      • arg: string

      Returns void

    • Parameters

      • e: Error

      Returns void

    • Add a option to this node

      Parameters

      • node: OptionNode

      Returns OptionNode

      node for the new option

    • Parameters

      • arg: string

      Returns void

    • Allow you to apply extra config to the parsed object, overriding any opts with source not start with cli.

      For example, you can allow user to specify options in their package.json file, and apply those after the command line is parsed.

      Each key goes to this command and any parsed sub command that declares the option. Keys that match no declared option are ignored.

      Parameters

      • config: Record<string, any>

        Config object containing user options config

      • src: OptionSource = "user"

        Name of the source that provided the config. Default to user

      Returns void

    • Returns void

    • check for missing options that are required

      Parameters

      • missing: any[] = []

      Returns any[]

    • Parameters

      • errorNodes: ClapNode[] = []

      Returns ClapNode[]

    • Get array of all commands that have exec callback

      Root command execution is handled specially:

      • This method filters out the root command (returns false for isRootCommand)
      • Root command execution is determined by _shouldExecuteRootCommand() in nix-clap.ts
      • Root command is executed in runExec/runExecAsync methods when conditions are met

      Parameters

      • cmds: CommandNode[]

        Array to accumulate command nodes with exec handlers

      • includeSubCommands: boolean

        Whether to recursively include sub-commands

      Returns CommandNode[]

      Array of command nodes that have exec handlers (excluding root command)

    • Type Parameters

      Returns T

    • Invoke the command's exec handler

      Parameters

      • includeSubCommands: boolean

        if true, then also do sub commands

      • Optionalparsed: ParseResult

        The parsed result containing remaining args after --

      Returns number

    • Parameters

      • includeSubCommands: boolean
      • Optionalparsed: ParseResult

        The parsed result containing remaining args after --

      Returns Promise<number>

    • For options that has names with - in them, add it using its name converted to camelCase.

      Returns void

    • Parameters

      • name: string

      Returns void