Skip to main content

Program

Hierarchy

Index

Events

readonlyonAfterRegister

onAfterRegister: Event<[string, Commandable<any, any[]>], string> = ...

Called after a command has been registered.

readonlyonAfterRender

onAfterRender: Event<unknown[], string> = ...

Called after a component has rendered.

readonlyonAfterRun

onAfterRun: Event<[Error?], string> = ...

Called after the program and command have been ran.

readonlyonBeforeRegister

onBeforeRegister: Event<[string, Commandable<any, any[]>], string> = ...

Called before a command has been registered.

readonlyonBeforeRender

onBeforeRender: Event<[RunResult], string> = ...

Called after a command has run but before a component will render.

readonlyonBeforeRun

onBeforeRun: Event<[Argv], string> = ...

Called before the program and command will run.

readonlyonCommandFound

onCommandFound: Event<[Argv, string, Commandable<any, any[]>], string> = ...

Called when a command has been found after parsing argv.

readonlyonCommandNotFound

onCommandNotFound: Event<[Argv, string], string> = ...

Called when a command wasn't found after parsing argv.

readonlyonExit

onExit: Event<[string, number], string> = ...

Called when the exit() handler is executed but before the process exits.

readonlyonHelp

onHelp: Event<[string?], string> = ...

Called when the help menu is rendered.

Other

constructor

readonlyoptions

options: Readonly<Required<ProgramOptions>>

Validated and configured options.

readonlystreams

streams: ProgramStreams = ...

blueprint

categories

  • Define option and command categories to supply to the running command, or the program itself.

configure

  • Set an options object by merging the new partial and existing options with the defined blueprint, while running all validation checks. Freeze and return the options object.

    object.configure({ name: 'Boost' });

    object.configure((prevOptions) => ({
    nestedObject: {
    ...prevOptions.nestedObject,
    some: 'value',
    },
    }));

default

  • Register a command and its canonical path as the default command. A default command should be used when stand-alone binary is required.

exit

  • exit(error?: string | Error, errorCode?: number): never
  • Exit the program with an error code. Should be called within a command or component.

getCommand

  • getCommand<O, P>(path: string): null | Commandable<O, P>
  • Return a command by registered path, or null if not found.


    Type parameters

getCommandPaths

  • getCommandPaths(): string[]
  • Return a list of all registered command paths (including aliases).

middleware

  • Define a middleware function to apply to the argv list or args object.

parse

register

  • Register a command and its canonical path (must be unique), otherwise an error is thrown.

renderElement

  • renderElement(element: ReactElement<any, string | JSXElementConstructor<any>>): Promise<void>
  • Render a React element with Ink and output to the configured streams.

run

  • Run the program in the following steps:

    • Apply middleware to argv list.
    • Parse argv into an args object (of options, params, etc).
    • Determine command to run, or fail.
    • Run command and render output.
    • Return exit code.

runAndExit

  • Run the program and also set the process exit code.