Interface RunOptions

Options for the run function.

interface RunOptions {
    afterExecute?: ((payload: {
        result: unknown;
        setResult: ((result: unknown) => void);
        state: State<unknown, OptionsConfig>;
    }) => void);
    afterParse?: ((payload: {
        context: Context<OptionsConfig>;
        parsedOptions: {};
        setParsedOptions: ((optionValues: {}) => void);
    }) => void);
    afterResolve?: ((payload: {
        addResolvedCommands: ((result: ResolvedCommand[]) => void);
        context: Context<OptionsConfig>;
        resolvedCommands: ResolvedCommand[];
    }) => void);
    beforeEnd?: ((payload: {
        data: unknown;
        setData: ((data: unknown) => void);
        state: State<unknown, OptionsConfig>;
    }) => void);
    beforeExecute?: ((payload: {
        initialData: unknown;
        setInitialData: ((data: unknown) => void);
        setResultAndSkip: ((result: unknown) => void);
        skip: (() => void);
        state: State<unknown, OptionsConfig>;
    }) => void);
    beforeNext?: ((payload: {
        data: unknown;
        nextCommand: undefined | ResolvedCommand;
        setData: ((data: unknown) => void);
        setNextCommand: ((command: ResolvedCommand) => void);
        state: State<unknown, OptionsConfig>;
    }) => void);
    beforeParse?: ((payload: {
        commandString: string | string[];
        context: Context<OptionsConfig>;
        optionsConfig: OptionsConfig;
        setParsedOptionsAndSkip: ((optionValues: {}) => void);
        setParseFn: ((parseFn: ParseCommandFn) => void);
        skip: (() => void);
    }) => void);
    beforeResolve?: ((payload: {
        addResolvedCommands: ((result: ResolvedCommand[]) => void);
        commandsDir: string;
        commandString: string;
        context: Context<OptionsConfig>;
        setParseFn: ((parseFn: ParseCommandFn) => void);
        setResolveFn: ((resolveFn: ResolveCommandFn) => void);
        skip: (() => void);
    }) => void);
    command?: string | string[];
    commandsDir?: string;
    initialData?: any;
    onError?: ((payload: {
        context: Context<OptionsConfig>;
        error: unknown;
        ignore: (() => void);
        setError: ((error: unknown) => void);
    }) => void);
    onExit?: ((payload: {
        cancel: (() => void);
        code: number;
        context: Context<OptionsConfig>;
        message?: any;
        setCode: ((code: number) => void);
        setMessage: ((message: any) => void);
    }) => void);
    options?: OptionsConfig;
    plugins?: {
        description?: string;
        init: ((context: Context<OptionsConfig>) => MaybePromise<boolean>);
        meta?: Record<string, any>;
        name: string;
        version: string;
    }[];
}

Properties

afterExecute?: ((payload: {
    result: unknown;
    setResult: ((result: unknown) => void);
    state: State<unknown, OptionsConfig>;
}) => void)

A hook that runs once all commands have been called or when context.end() is called.

afterParse?: ((payload: {
    context: Context<OptionsConfig>;
    parsedOptions: {};
    setParsedOptions: ((optionValues: {}) => void);
}) => void)

A hook that runs after parsing the command string.

afterResolve?: ((payload: {
    addResolvedCommands: ((result: ResolvedCommand[]) => void);
    context: Context<OptionsConfig>;
    resolvedCommands: ResolvedCommand[];
}) => void)

A hook that runs after importing command modules.

beforeEnd?: ((payload: {
    data: unknown;
    setData: ((data: unknown) => void);
    state: State<unknown, OptionsConfig>;
}) => void)

A hook that runs before executing the context.end() function.

beforeExecute?: ((payload: {
    initialData: unknown;
    setInitialData: ((data: unknown) => void);
    setResultAndSkip: ((result: unknown) => void);
    skip: (() => void);
    state: State<unknown, OptionsConfig>;
}) => void)

A hook that runs before calling the first command.

beforeNext?: ((payload: {
    data: unknown;
    nextCommand: undefined | ResolvedCommand;
    setData: ((data: unknown) => void);
    setNextCommand: ((command: ResolvedCommand) => void);
    state: State<unknown, OptionsConfig>;
}) => void)

A hook that runs before executing the context.next() function.

beforeParse?: ((payload: {
    commandString: string | string[];
    context: Context<OptionsConfig>;
    optionsConfig: OptionsConfig;
    setParsedOptionsAndSkip: ((optionValues: {}) => void);
    setParseFn: ((parseFn: ParseCommandFn) => void);
    skip: (() => void);
}) => void)

A hook that runs before parsing the command string using the options config from plugins and imported command modules.

beforeResolve?: ((payload: {
    addResolvedCommands: ((result: ResolvedCommand[]) => void);
    commandsDir: string;
    commandString: string;
    context: Context<OptionsConfig>;
    setParseFn: ((parseFn: ParseCommandFn) => void);
    setResolveFn: ((resolveFn: ResolveCommandFn) => void);
    skip: (() => void);
}) => void)

A hook that runs before attempting to locate and import command modules.

command?: string | string[]

The command string or array to be parsed and executed. If not provided, it defaults to system arguments.

commandsDir?: string

A directory path containing command modules.

"<cwd>/commands" || "<caller-dir>/commands"
initialData?: any

Initial context or data to pass to commands during execution.

onError?: ((payload: {
    context: Context<OptionsConfig>;
    error: unknown;
    ignore: (() => void);
    setError: ((error: unknown) => void);
}) => void)

A hook that runs whenever an error is thrown.

onExit?: ((payload: {
    cancel: (() => void);
    code: number;
    context: Context<OptionsConfig>;
    message?: any;
    setCode: ((code: number) => void);
    setMessage: ((message: any) => void);
}) => void)

A hook that runs whenever a plugin or command intends to exit the process.

options?: OptionsConfig

Options to include in the context.

plugins?: {
    description?: string;
    init: ((context: Context<OptionsConfig>) => MaybePromise<boolean>);
    meta?: Record<string, any>;
    name: string;
    version: string;
}[]

An array of plugins that can modify or augment the behavior of commands.

Type declaration

  • Optionaldescription?: string
  • init: ((context: Context<OptionsConfig>) => MaybePromise<boolean>)

    Initialize the plugin.

      • (context): MaybePromise<boolean>
      • Parameters

        Returns MaybePromise<boolean>

        A boolean or promise that resolves to a boolean indicating whether the plugin was successfully initialized.

  • Optionalmeta?: Record<string, any>

    Additional metadata about the plugin that doesn't fit in the standard fields.

    Note: Plugin info on the Context object will be frozen after the plugin is initialized. However, the freeze is shallow, so the fields of this object will be mutable by default.

  • name: string
  • version: string