import type { CreateApiContextOptions } from '@ms-cloudpack/api-server'; import type { AutoDispose } from './AutoDispose.js'; import type { SharedOptions } from './SharedOptions.js'; import type { Span } from '@ms-cloudpack/telemetry'; import type { ProgramOptions } from './ProgramOptions.js'; /** * Context for running a command in a specific app (after initialization). * For convenience, this can be passed/spread directly to `createApiContext`. */ export interface AppCommandContext extends Pick { /** App path (CWD for most operations). */ appPath: string; } export declare const ExitCodeSuccessful = 0; export declare const ExitCodeGenericError = 1; export declare const ExitCodeAuthenticationError = 2; export type ExitCode = typeof ExitCodeSuccessful | typeof ExitCodeGenericError | typeof ExitCodeAuthenticationError; export interface CommandExitParams { /** * Message to show on exit. * If `isInterrupted` is true, use an empty string (it will show a default interrupt message). */ message: string; /** Whether there are errors. By default, checks the reporter for failed tasks. */ hasErrors?: boolean; /** Exit code to use. Defaults to 1 if there are errors, 0 if not. */ exitCode?: ExitCode; /** True if the user interrupted an operation (ctrl+C). Sets the message automatically. */ isInterrupted?: boolean; /** Whether to restart the command after it exits. */ restart?: boolean; } export interface CommandActionParams extends AppCommandContext, Pick { /** * Command-specific options, parsed from `process.argv`. * Types are generally defined in each command's `src/commands//types/Types.ts` module. * The command line options are defined in each command's `src/commands//index.ts` module. */ options: TOptions; /** * Command-specific arguments. Arguments in commander are positional arguments that are not options. * For example, in `echo somestring`, `somestring` is an argument. */ args: string[]; /** * Whether the command is being run for multiple apps. (It only runs on one app at a time, but * multi-app may impact formatting choices or other behaviors.) * * Note that this will only ever be true for commands initialized with `discoverAppPaths: 'multi'`. */ isMultiApp: boolean; /** * Parent span for the command. */ span: Span; /** * Function that can be called with any `Disposable`s that should be cleaned up automatically * when the program exits. (See `AutoDisposableList.add` for implementation.) */ autoDispose: AutoDispose; /** * Set a callback to get the message to display if ctrl+C is pressed. */ setInterruptMessageHandler: (getMessage: () => string) => void; /** * Indicates whether this command execution is a restart of a previous execution. * When true, the command is being run again due to a restart trigger (e.g., config changes). * This can be used to modify behavior on restart, such as skipping browser opening. */ isRestart: boolean; } /** * Command action function (executor). This is the type of the `execute` function which should * be exported from each command's `src/commands//execute.ts` module and is called by * `CommandExecutor` against each app. * * The function should return a promise of an exit options object: * - For most commands, this should be the result of running the command. * - Interrupts will be handled automatically (use `setInterruptMessageHandler` for a custom message). * - For commands such as `start` which run continuously, it's okay if the promise doesn't resolve. * If a restart is needed, return `{ restart: true, ... }`. * - For multi-app, if there's a failure in one app, the command will continue running for others. */ export type CommandAction = (params: CommandActionParams) => Promise; export type CommandActionModule = { execute: CommandAction; }; //# sourceMappingURL=CommandAction.d.ts.map