@magicdawn/x-args
Version:
play with cli commands like a composer
79 lines (78 loc) • 2.63 kB
TypeScript
import { Command, Usage } from "clipanion";
import { ExecSyncOptionsWithBufferEncoding } from "node:child_process";
import { quote } from "shlex";
//#region src/commands/txt-command/index.d.ts
declare class TxtCommand extends Command {
static paths?: string[][];
static usage: Usage;
txtFiles: string[];
command: string;
yes: boolean;
wait: boolean;
waitTimeout?: string | undefined;
session: string;
execute(): Promise<number | void>;
}
//#endregion
//#region src/commands/txt-command/api.d.ts
declare enum SessionControl {
Start = "start",
ReStart = "restart",
Continue = "continue"
}
type CommandBuilderContext = {
/** current line */line: string; /** args split from line */
args: string[]; /** helper: apply command template */
applyCommandTemplate: typeof applyCommandTemplate; /** helper: shlex.quote */
quote: typeof quote;
};
declare function applyCommandTemplate(command: string, {
line,
args
}: Pick<CommandBuilderContext, 'line' | 'args'>): string;
interface RunContext extends CommandBuilderContext {
/** shortcut for `execSync` */
runCommandSync: (command: string) => void;
/** the txt file being processed */
txtFile: string;
}
interface StartTxtCommandOptions extends Pick<TxtCommand, 'yes' | 'wait' | 'waitTimeout'> {
txtFiles: string | string[];
session: SessionControl;
execOptions?: Partial<ExecSyncOptionsWithBufferEncoding>;
command?: string | ((ctx: CommandBuilderContext) => string);
run?: (ctx: RunContext) => void | Promise<void>;
}
declare const defaultTxtCommandContext: {
session: SessionControl.Continue;
};
declare function startTxtCommand(opts: StartTxtCommandOptions): Promise<void>;
//#endregion
//#region src/util/BaseCommand.d.ts
declare abstract class BaseCommand extends Command {
/**
* glob
*/
files: string;
ignoreCase: boolean;
globCwd: string | undefined;
yes: boolean;
showTokens: boolean;
abstract execute(): Promise<number | void>;
}
//#endregion
//#region src/util/file.d.ts
interface FilenameTokens {
fullpath: string;
dir: string;
file: string;
name: string;
ext: string;
pdir: string;
rname: string;
}
declare function getFilenameTokens(item: string): FilenameTokens;
declare function renderFilenameTokens(template: string, options: FilenameTokens): string;
declare function printFilenameTokens(tokens: FilenameTokens): void;
//#endregion
export { BaseCommand, CommandBuilderContext, FilenameTokens, RunContext, SessionControl, StartTxtCommandOptions, TxtCommand, applyCommandTemplate, defaultTxtCommandContext, getFilenameTokens, printFilenameTokens, renderFilenameTokens, startTxtCommand };