EdgeAIG's picture
download
raw
4.53 kB
/**
* Command Implementation
* ======================
*
* Internal implementation details for CLI commands.
* Public API is in ../Command.ts
*/
import * as Arr from "../../../Array.ts";
import * as Context from "../../../Context.ts";
import * as Effect from "../../../Effect.ts";
import * as CliError from "../CliError.ts";
import type * as GlobalFlag from "../GlobalFlag.ts";
import type { FlagDoc, HelpDoc } from "../HelpDoc.ts";
import * as Param from "../Param.ts";
import { type ConfigInternal } from "./config.ts";
import type { Command, CommandContext, Environment, ParsedTokens } from "../Command.ts";
interface SubcommandGroup {
readonly group: string | undefined;
readonly commands: Arr.NonEmptyReadonlyArray<Command<any, unknown, any, unknown, unknown>>;
}
/**
* Internal implementation interface with all the machinery.
* Use toImpl() to access from internal code.
*/
export interface CommandInternal<Name extends string, Input, E, R, ContextInput> extends Command<Name, Input, ContextInput, E, R> {
readonly config: ConfigInternal;
readonly contextConfig: ConfigInternal;
readonly service: Context.Key<CommandContext<Name>, ContextInput>;
readonly annotations: Context.Context<never>;
readonly globalFlags: ReadonlyArray<GlobalFlag.GlobalFlag<any>>;
readonly parse: (input: ParsedTokens) => Effect.Effect<Input, CliError.CliError, Environment>;
readonly parseContext: (input: ParsedTokens) => Effect.Effect<ContextInput, CliError.CliError, Environment>;
readonly handle: (input: Input, commandPath: ReadonlyArray<string>) => Effect.Effect<void, E | CliError.CliError, R | Environment>;
readonly buildHelpDoc: (commandPath: ReadonlyArray<string>) => HelpDoc;
}
export declare const TypeId: "~effect/cli/Command";
/**
* Casts a Command to its internal implementation.
* For use by internal modules that need access to config, parse, handle, etc.
*/
export declare const toImpl: <Name extends string, Input, E, R, ContextInput = {}>(self: Command<Name, Input, ContextInput, E, R>) => CommandInternal<Name, Input, E, R, ContextInput>;
export declare const Proto: Effect.Effect<any, never, any>;
/**
* Internal command constructor. Only accepts already-parsed ConfigInternal.
*/
export declare const makeCommand: <const Name extends string, Input, E, R, ContextInput = {}>(options: {
readonly name: Name;
readonly config: ConfigInternal;
readonly contextConfig?: ConfigInternal | undefined;
readonly service?: Context.Key<CommandContext<Name>, ContextInput> | undefined;
readonly annotations?: Context.Context<never> | undefined;
readonly globalFlags?: ReadonlyArray<GlobalFlag.GlobalFlag<any>> | undefined;
readonly description?: string | undefined;
readonly shortDescription?: string | undefined;
readonly alias?: string | undefined;
readonly hidden?: boolean | undefined;
readonly examples?: ReadonlyArray<Command.Example> | undefined;
readonly subcommands?: ReadonlyArray<SubcommandGroup> | undefined;
readonly parse?: ((input: ParsedTokens) => Effect.Effect<Input, CliError.CliError, Environment>) | undefined;
readonly parseContext?: ((input: ParsedTokens) => Effect.Effect<ContextInput, CliError.CliError, Environment>) | undefined;
readonly handle?: ((input: Input, commandPath: ReadonlyArray<string>) => Effect.Effect<void, E, R | Environment>) | undefined;
}) => Command<Name, Input, ContextInput, E, R>;
/**
* Converts a single flag param into a FlagDoc for help display.
*/
export declare const toFlagDoc: (single: Param.Single<typeof Param.flagKind, unknown>) => FlagDoc;
/**
* Creates a parser for a given config. Used as the default for both `parse`
* and `parseContext`, and also by `withSharedFlags` to avoid constructing a
* full throwaway command.
*/
export declare const makeParser: (cfg: ConfigInternal) => (input: ParsedTokens) => Effect.Effect<Record<string, any>, CliError.CliError, Environment>;
/**
* Checks that inherited parent context flags do not reuse names declared by
* child command flags.
*
* When `contextConfig` is supplied, it is used as the inherited flag set;
* otherwise the parent's current context config is checked.
*/
export declare const checkForDuplicateFlags: <Name extends string, Input, ContextInput, E, R>(parent: Command<Name, Input, ContextInput, E, R>, subcommands: ReadonlyArray<Command.Any>, options?: {
readonly contextConfig?: ConfigInternal | undefined;
} | undefined) => void;
export {};
//# sourceMappingURL=command.d.ts.map

Xet Storage Details

Size:
4.53 kB
·
Xet hash:
432688ce0d4b195eca8ea2e321cb1595a2c18f41243974d8596664e8d4f847ee

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.