Interface ClideHooks

The core hooks interface that defines lifecycle events for the CLI execution process. Hooks are called in sequential order as listed below.

interface ClideHooks {
    afterExecute: ((payload: {
        result: unknown;
        setResult: ((result: unknown) => void);
        state: State<unknown, OptionsConfig>;
    }) => MaybePromise<void>);
    afterParse: ((payload: {
        context: Context<OptionsConfig>;
        parsedOptions: {};
        setParsedOptions: ((optionValues: {}) => void);
    }) => MaybePromise<void>);
    afterResolve: ((payload: {
        addResolvedCommands: ((resolvedCommands: ResolvedCommand[]) => void);
        context: Context<OptionsConfig>;
        resolvedCommands: ResolvedCommand[];
    }) => MaybePromise<void>);
    afterStateChange: ((payload: {
        changes: Partial<NextState>;
        state: State<unknown, OptionsConfig>;
    }) => MaybePromise<void>);
    beforeEnd: ((payload: {
        data: unknown;
        setData: ((data: unknown) => void);
        state: State<unknown, OptionsConfig>;
    }) => MaybePromise<void>);
    beforeExecute: ((payload: {
        initialData: unknown;
        setInitialData: ((data: unknown) => void);
        setResultAndSkip: ((result: unknown) => void);
        skip: (() => void);
        state: State<unknown, OptionsConfig>;
    }) => MaybePromise<void>);
    beforeNext: ((payload: {
        data: unknown;
        nextCommand: undefined | ResolvedCommand;
        setData: ((data: unknown) => void);
        setNextCommand: ((command: ResolvedCommand) => void);
        state: State<unknown, OptionsConfig>;
    }) => MaybePromise<void>);
    beforeParse: ((payload: {
        commandString: string | string[];
        context: Context<OptionsConfig>;
        optionsConfig: OptionsConfig;
        setParsedOptionsAndSkip: ((optionValues: {}) => void);
        setParseFn: ((parseFn: ParseCommandFn) => void);
        skip: (() => void);
    }) => MaybePromise<void>);
    beforeResolve: ((payload: {
        addResolvedCommands: ((resolvedCommands: ResolvedCommand[]) => void);
        commandsDir: string;
        commandString: string;
        context: Context<OptionsConfig>;
        setParseFn: ((parseFn: ParseCommandFn) => void);
        setResolveFn: ((resolveFn: ResolveCommandFn) => void);
        skip: (() => void);
    }) => MaybePromise<void>);
    beforeResolveNext: ((payload: {
        addResolvedCommands: ((resolvedCommands: ResolvedCommand[]) => void);
        commandsDir: string;
        commandString: string;
        context: Context<OptionsConfig>;
        lastResolved: ResolvedCommand;
        setParseFn: ((parseFn: ParseCommandFn) => void);
        setResolveFn: ((resolveFn: ResolveCommandFn) => void);
        skip: (() => void);
    }) => MaybePromise<void>);
    beforeStateChange: ((payload: {
        changes: Partial<NextState>;
        setChanges: ((changes: Partial<NextState>) => void);
        skip: (() => void);
        state: State<unknown, OptionsConfig>;
    }) => MaybePromise<void>);
    error: ((payload: {
        context: Context<OptionsConfig>;
        error: unknown;
        ignore: (() => void);
        setError: ((error: unknown) => void);
    }) => MaybePromise<void>);
    exit: ((payload: {
        cancel: (() => void);
        code: number;
        context: Context<OptionsConfig>;
        message?: any;
        setCode: ((code: number) => void);
        setMessage: ((message: any) => void);
    }) => MaybePromise<void>);
}

Properties

afterExecute: ((payload: {
    result: unknown;
    setResult: ((result: unknown) => void);
    state: State<unknown, OptionsConfig>;
}) => MaybePromise<void>)
  1. Called once per execution, after the final state update.
afterParse: ((payload: {
    context: Context<OptionsConfig>;
    parsedOptions: {};
    setParsedOptions: ((optionValues: {}) => void);
}) => MaybePromise<void>)
  1. Called after command arguments and options have been parsed
afterResolve: ((payload: {
    addResolvedCommands: ((resolvedCommands: ResolvedCommand[]) => void);
    context: Context<OptionsConfig>;
    resolvedCommands: ResolvedCommand[];
}) => MaybePromise<void>)
  1. Called after all commands in the chain have been resolved
afterStateChange: ((payload: {
    changes: Partial<NextState>;
    state: State<unknown, OptionsConfig>;
}) => MaybePromise<void>)
  1. Called after each state update during command execution
beforeEnd: ((payload: {
    data: unknown;
    setData: ((data: unknown) => void);
    state: State<unknown, OptionsConfig>;
}) => MaybePromise<void>)
  1. Called once per execution, before the final state update, if state.end() is called.
beforeExecute: ((payload: {
    initialData: unknown;
    setInitialData: ((data: unknown) => void);
    setResultAndSkip: ((result: unknown) => void);
    skip: (() => void);
    state: State<unknown, OptionsConfig>;
}) => MaybePromise<void>)
  1. Called before command execution begins
beforeNext: ((payload: {
    data: unknown;
    nextCommand: undefined | ResolvedCommand;
    setData: ((data: unknown) => void);
    setNextCommand: ((command: ResolvedCommand) => void);
    state: State<unknown, OptionsConfig>;
}) => MaybePromise<void>)
  1. Called before each state transition during command execution

This hook is triggered by both explicit state.next() calls and the initial state.start() call, which internally uses state.next().

beforeParse: ((payload: {
    commandString: string | string[];
    context: Context<OptionsConfig>;
    optionsConfig: OptionsConfig;
    setParsedOptionsAndSkip: ((optionValues: {}) => void);
    setParseFn: ((parseFn: ParseCommandFn) => void);
    skip: (() => void);
}) => MaybePromise<void>)
  1. Called before parsing command arguments and options
beforeResolve: ((payload: {
    addResolvedCommands: ((resolvedCommands: ResolvedCommand[]) => void);
    commandsDir: string;
    commandString: string;
    context: Context<OptionsConfig>;
    setParseFn: ((parseFn: ParseCommandFn) => void);
    setResolveFn: ((resolveFn: ResolveCommandFn) => void);
    skip: (() => void);
}) => MaybePromise<void>)
  1. Initial preparation hook called before command resolution begins.
beforeResolveNext: ((payload: {
    addResolvedCommands: ((resolvedCommands: ResolvedCommand[]) => void);
    commandsDir: string;
    commandString: string;
    context: Context<OptionsConfig>;
    lastResolved: ResolvedCommand;
    setParseFn: ((parseFn: ParseCommandFn) => void);
    setResolveFn: ((resolveFn: ResolveCommandFn) => void);
    skip: (() => void);
}) => MaybePromise<void>)
  1. Called before resolving each subcommand in the command chain
beforeStateChange: ((payload: {
    changes: Partial<NextState>;
    setChanges: ((changes: Partial<NextState>) => void);
    skip: (() => void);
    state: State<unknown, OptionsConfig>;
}) => MaybePromise<void>)
  1. Called before each state update during command execution
error: ((payload: {
    context: Context<OptionsConfig>;
    error: unknown;
    ignore: (() => void);
    setError: ((error: unknown) => void);
}) => MaybePromise<void>)

Called whenever an error is thrown.

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

Called whenever a plugin or command intends to exit the process.