execli
Version:
Generate task-oriented CLIs declaratively
68 lines • 2.69 kB
TypeScript
import { Options } from "execa";
import { Context, ContextLike, InternalOptionsContext } from "./context.js";
import { Command, Exec, Line, OutputLine } from "./exec.js";
type BaseTask = Readonly<{
title: Line;
}>;
type SkipResult = boolean | string | Promise<boolean | string>;
type SkippableTask<C> = Readonly<{
skip?: (context: Context<C>) => SkipResult;
}>;
type TaggedTask = Readonly<{
tags?: readonly Line[];
}>;
type BaseLeafTask<C> = BaseTask & SkippableTask<C> & TaggedTask;
type CommandGetter<C> = (context: Context<C>) => Command;
type OptionsGetter<C> = (context: Context<C>) => Options;
type CommandProperties<C> = Readonly<{
command: Command | CommandGetter<C>;
options?: Options | OptionsGetter<C>;
}>;
type CommandTask<C> = BaseLeafTask<C> & CommandProperties<C>;
type RunnableTask<C> = Readonly<{
run: (payload: Readonly<{
context: Context<C>;
exec: Exec;
outputLine: OutputLine;
}>) => Line | void | Promise<Line | void>;
}>;
type RegularTask<C> = BaseLeafTask<C> & RunnableTask<C>;
type LeafTask<C> = CommandTask<C> | RegularTask<C>;
type IntersectableContext<C> = C extends ContextLike<any> ? C : unknown;
type NestedChildrenMarker = false;
type ParentTask<C, A> = BaseTask & Readonly<{
rollback?: RunnableTask<IntersectableContext<C>>["run"];
}> & SkippableTask<IntersectableContext<C>> & (A extends ContextLike ? Readonly<{
addContext: (payload: Readonly<{
/**
* Secrets will be redacted in displayed command strings.
*/
addSecret: (secret: string) => void;
context: Context<IntersectableContext<C>>;
exec: Exec;
}>) => A | Promise<A>;
}> : unknown) & Readonly<{
children: A extends NestedChildrenMarker ? any : ReadonlyArray<Task<IntersectableContext<C> & IntersectableContext<A>, NestedChildrenMarker>>;
concurrent?: boolean | number;
}>;
export type Task<C = void, A = void> = LeafTask<C> | ParentTask<C, A>;
type FlatTask = Readonly<{
parentTitle?: string;
}> & (TaggedTask | Readonly<{
children: readonly string[];
}>);
type MutableFlatTasks = Record<string, FlatTask>;
export type FlatTasks = Readonly<MutableFlatTasks>;
export declare const buildFlatTasks: (task: Task<any>, flatTasks?: MutableFlatTasks, parentTitle?: string) => FlatTasks;
export declare const runTask: <C>(task: Task<C, void>, context: Readonly<{
concurrency: number;
}> & Readonly<C> & Readonly<{
dryRun: boolean;
from: string | undefined;
only: readonly string[];
skip: readonly string[];
tag: readonly string[];
until: string | undefined;
}>, flatTasks: FlatTasks) => Promise<void>;
export {};
//# sourceMappingURL=tasks.d.ts.map