@avandar/acclimate 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +289 -0
- package/dist/index.cjs +381 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +223 -0
- package/dist/index.d.ts +223 -0
- package/dist/index.js +379 -0
- package/dist/index.js.map +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/CLIError.ts","../src/AcclimateCLI/AcclimateCLI.ts","../src/AcclimateCLI/createCLI/defaultCLIState.ts","../src/AcclimateCLI/createCLI/createCLI.ts","../src/AcclimateCLI/runCLI/runCLI.ts","../src/Acclimate.ts"],"names":["match","camelCase"],"mappings":";;;;;;AA4CO,IAAM,QAAA,GAAN,MAAM,SAAA,SAAiB,KAAA,CAAM;AAAA,EAClC,OAAO,qBAAqB,OAAA,EAIf;AACX,IAAA,OAAO,IAAI,SAAA,CAAS;AAAA,MAClB,OAAA,EACE,OAAA,CAAQ,OAAA,IAAW,CAAA,6BAAA,EAAgC,QAAQ,SAAS,CAAA,CAAA,CAAA;AAAA,MACtE,IAAA,EAAM,yBAAA;AAAA,MACN,SAAS,EAAE,SAAA,EAAW,QAAQ,SAAA,EAAW,UAAA,EAAY,QAAQ,UAAA;AAAW,KACzE,CAAA;AAAA,EACH;AAAA,EACA,OAAO,sBAAsB,OAAA,EAGhB;AACX,IAAA,OAAO,IAAI,SAAA,CAAS;AAAA,MAClB,OAAA,EACE,OAAA,CAAQ,OAAA,IAAW,CAAA,iBAAA,EAAoB,QAAQ,UAAU,CAAA,YAAA,CAAA;AAAA,MAC3D,IAAA,EAAM,yBAAA;AAAA,MACN,OAAA,EAAS,EAAE,UAAA,EAAY,OAAA,CAAQ,UAAA;AAAW,KAC3C,CAAA;AAAA,EACH;AAAA,EAEA,OAAO,6BAA6B,OAAA,EAGvB;AACX,IAAA,OAAO,IAAI,SAAA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A,CAAQ,YAAY,CAAA,IAAK,YAAA;AAC5C,QAAA,IACE,sBAAA,CAAuB,UAAU,CAAA,IACjC,CAAC,cAAc,gBAAgB,CAAA,IAC/B,gBAAA,CAAiB,UAAU,CAAA,EAC3B;AACA,UAAA,mBAAA,CAAoB,UAAU,CAAA,GAAI,QAAA;AAAA,QACpC,CAAA,MAAO;AACL,UAAA,aAAA,CAAc,UAAU,CAAA,GAAI,QAAA;AAAA,QAC9B;AAAA,MACF;AACA,MAAA,YAAA,GAAe,MAAA;AACf,MAAA,WAAA,GAAc,EAAC;AAAA,IACjB,CAAA,MAAO;AACL,MAAA,WAAA,CAAY,KAAK,MAAM,CAAA;AAAA,IACzB;AAAA,EACF;AAEA,EAAA,aAAA,CAAc,EAAE,iBAAA,EAAmB,aAAA,EAAe,mBAAA,EAAqB,KAAK,CAAA;AAC9E;;;ACnTO,IAAM,SAAA,GAAuB;AAAA,EAClC,SAAA;AAAA,EACA,GAAA,EAAK,CAAC,GAAA,KAAuB;AAC3B,IAAA,MAAA,CAAO,EAAE,KAAK,KAAA,EAAO,OAAA,CAAQ,KAAK,KAAA,CAAM,CAAC,GAAG,CAAA;AAAA,EAC9C;AACF","file":"index.cjs","sourcesContent":["import type { CLIParamDataType } from \"./AcclimateCLI/AcclimateCLI.types\";\n\ntype CLIErrorInfo =\n | {\n code: \"already_run\";\n details: undefined;\n }\n | {\n code: \"unknown_command\";\n details: { commandName: string };\n }\n | {\n code: \"invalid_positional_arg_config\";\n details: { positionalArgName: string };\n }\n | {\n code: \"too_many_positional_args\";\n details: { count: number };\n }\n | {\n code: \"missing_required_positional_arg\";\n details: { positionalArgName: string };\n }\n | {\n code: \"missing_required_option\";\n details: { optionName: string };\n }\n | {\n code: \"unknown_option\";\n details: {\n optionName: string;\n };\n }\n | {\n code: \"invalid_cli_param_value\";\n details: {\n paramName: string;\n paramValue: CLIParamDataType;\n };\n }\n | { code: \"unknown_error\"; details: undefined };\n\ntype CLIErrorOptions = { message: string } & CLIErrorInfo;\n\nexport class CLIError extends Error {\n static invalidCLIParamValue(options: {\n paramName: string;\n paramValue: CLIParamDataType;\n message?: string;\n }): CLIError {\n return new CLIError({\n message:\n options.message ?? `Invalid value for CLI param \"${options.paramName}\"`,\n code: \"invalid_cli_param_value\",\n details: { paramName: options.paramName, paramValue: options.paramValue },\n });\n }\n static missingRequiredOption(options: {\n optionName: string;\n message?: string;\n }): CLIError {\n return new CLIError({\n message:\n options.message ?? `Required option \"${options.optionName}\" is missing`,\n code: \"missing_required_option\",\n details: { optionName: options.optionName },\n });\n }\n\n static missingRequiredPositionalArg(options: {\n positionalArgName: string;\n message?: string;\n }): CLIError {\n return new CLIError({\n message:\n options.message ??\n `Required positional argument \"${options.positionalArgName}\" is missing`,\n code: \"missing_required_positional_arg\",\n details: { positionalArgName: options.positionalArgName },\n });\n }\n\n static unknownOption(options: {\n optionName: string;\n message?: string;\n }): CLIError {\n return new CLIError({\n message: options.message ?? `Option \"${options.optionName}\" not found`,\n code: \"unknown_option\",\n details: { optionName: options.optionName },\n });\n }\n\n static tooManyPositionalArgs(options: {\n count: number;\n message?: string;\n }): CLIError {\n return new CLIError({\n message: options.message ?? \"Too many positional arguments provided.\",\n code: \"too_many_positional_args\",\n details: { count: options.count },\n });\n }\n\n static invalidPositionalArgConfig(options: {\n positionalArgName: string;\n message?: string;\n }): CLIError {\n return new CLIError({\n message:\n options.message ??\n `Positional argument configuration for \"${options.positionalArgName}\" is invalid`,\n code: \"invalid_positional_arg_config\",\n details: { positionalArgName: options.positionalArgName },\n });\n }\n\n static unknownCommand(options: {\n commandName: string;\n message?: string;\n }): CLIError {\n return new CLIError({\n message: options.message ?? `Command \"${options.commandName}\" not found`,\n code: \"unknown_command\",\n details: { commandName: options.commandName },\n });\n }\n\n static alreadyRun(options: { message?: string } = {}): CLIError {\n return new CLIError({\n message: options.message ?? \"CLI has already been run\",\n code: \"already_run\",\n details: undefined,\n });\n }\n\n constructor(options: CLIErrorOptions) {\n super(`❌ ${options.message}`);\n }\n}\n","import { CLIError } from \"@/CLIError\";\nimport type {\n AddEntry,\n CLICommandName,\n CLIFullOptionName,\n CLIOptionParam,\n CLIPositionalParam,\n CLIPositionalParamName,\n CLIState,\n FullCLIArgValues,\n IAcclimateCLI,\n} from \"./AcclimateCLI.types\";\nimport type { EmptyObject, Simplify } from \"type-fest\";\n\nexport function AcclimateCLI<\n TPositionalParams extends\n | Record<CLIPositionalParamName, CLIPositionalParam>\n | EmptyObject,\n TOptionParams extends Record<CLIFullOptionName, CLIOptionParam> | EmptyObject,\n TGlobalOptionParams extends\n | Record<CLIFullOptionName, CLIOptionParam>\n | EmptyObject,\n TCommands extends Record<CLICommandName, IAcclimateCLI> | EmptyObject,\n>(\n state: CLIState<\n TPositionalParams,\n TOptionParams,\n TGlobalOptionParams,\n TCommands\n >,\n): IAcclimateCLI<\n TPositionalParams,\n TOptionParams,\n TGlobalOptionParams,\n TCommands\n> {\n return {\n state,\n\n action: (\n action: (\n args: Simplify<\n FullCLIArgValues<\n TPositionalParams,\n TOptionParams,\n TGlobalOptionParams\n >\n >,\n ) => void,\n ): IAcclimateCLI<\n TPositionalParams,\n TOptionParams,\n TGlobalOptionParams,\n TCommands\n > => {\n return AcclimateCLI({\n ...state,\n action,\n });\n },\n\n description: (\n description: string,\n ): IAcclimateCLI<\n TPositionalParams,\n TOptionParams,\n TGlobalOptionParams,\n TCommands\n > => {\n return AcclimateCLI({\n ...state,\n description,\n });\n },\n\n addPositionalArg: <\n PName extends CLIPositionalParamName,\n P extends CLIPositionalParam<PName>,\n >(\n param: P,\n ) => {\n if (\n param.required &&\n state.positionalArgs.some((p) => {\n return !p.required;\n })\n ) {\n throw CLIError.invalidPositionalArgConfig({\n positionalArgName: param.name,\n message:\n \"Required positional arguments must be before optional positional arguments\",\n });\n }\n\n return AcclimateCLI({\n ...state,\n positionalArgs: [\n ...state.positionalArgs,\n { ...param, required: param.required ?? true },\n ],\n } as unknown as CLIState<\n AddEntry<TPositionalParams, P[\"name\"], P>,\n TOptionParams,\n TGlobalOptionParams,\n TCommands\n >);\n },\n\n addGlobalOption: <P extends CLIOptionParam>(param: P) => {\n const newAliases = (param.aliases ?? []).reduce(\n (acc, alias) => {\n acc[alias] = param.name;\n return acc;\n },\n {} as Record<`-${string}` | `--${string}`, `--${string}`>,\n );\n return AcclimateCLI<\n TPositionalParams,\n TOptionParams,\n AddEntry<TGlobalOptionParams, P[\"name\"], P>,\n TCommands\n >({\n ...state,\n aliases: { ...state.aliases, ...newAliases },\n globalOptionArgs: {\n ...state.globalOptionArgs,\n [param.name]: param,\n },\n } as unknown as CLIState<\n TPositionalParams,\n TOptionParams,\n AddEntry<TGlobalOptionParams, P[\"name\"], P>,\n TCommands\n >);\n },\n\n addOption: <P extends CLIOptionParam>(param: P) => {\n const newAliases = (param.aliases ?? []).reduce(\n (acc, alias) => {\n acc[alias] = param.name;\n return acc;\n },\n {} as Record<`-${string}` | `--${string}`, `--${string}`>,\n );\n return AcclimateCLI<\n TPositionalParams,\n AddEntry<TOptionParams, P[\"name\"], P>,\n TGlobalOptionParams,\n TCommands\n >({\n ...state,\n aliases: { ...state.aliases, ...newAliases },\n optionArgs: { ...state.optionArgs, [param.name]: param },\n } as unknown as CLIState<\n TPositionalParams,\n AddEntry<TOptionParams, P[\"name\"], P>,\n TGlobalOptionParams,\n TCommands\n >);\n },\n\n addCommand: <C extends CLICommandName, CommandCLI extends IAcclimateCLI>(\n commandName: C,\n cli: CommandCLI,\n ): IAcclimateCLI<\n TPositionalParams,\n TOptionParams,\n TGlobalOptionParams,\n AddEntry<TCommands, C, CommandCLI>\n > => {\n return AcclimateCLI({\n ...state,\n commands: {\n ...state.commands,\n [commandName]: cli,\n },\n } as unknown as CLIState<\n TPositionalParams,\n TOptionParams,\n TGlobalOptionParams,\n AddEntry<TCommands, C, CommandCLI>\n >);\n },\n\n getCommandCLI: <C extends Extract<keyof TCommands, CLICommandName>>(\n commandName: C,\n ): C extends keyof TCommands ? TCommands[C] : never => {\n const cmd = state.commands[commandName];\n if (!cmd) {\n throw CLIError.unknownCommand({\n commandName,\n message: `Command \"${commandName}\" not found`,\n });\n }\n return cmd as C extends keyof TCommands ? TCommands[C] : never;\n },\n };\n}\n","import type { CLIState } from \"../AcclimateCLI.types\";\nimport type { EmptyObject } from \"type-fest\";\n\nexport const defaultCLIState: Omit<\n CLIState<EmptyObject, EmptyObject, EmptyObject, EmptyObject>,\n \"name\"\n> = {\n aliases: {},\n description: undefined,\n commands: {},\n positionalArgs: [],\n optionArgs: {},\n globalOptionArgs: {},\n action: () => {},\n};\n","import { AcclimateCLI } from \"../AcclimateCLI\";\nimport { defaultCLIState } from \"./defaultCLIState\";\nimport type { IAcclimateCLI } from \"../AcclimateCLI.types\";\nimport type { EmptyObject } from \"type-fest\";\n\n/**\n * Builder function to create a new CLI instance with a given name.\n *\n * @param name - The name of the CLI.\n * @returns A new CLI instance.\n */\nexport function createCLI(\n name: string,\n): IAcclimateCLI<EmptyObject, EmptyObject, EmptyObject, EmptyObject> {\n return AcclimateCLI({ ...defaultCLIState, name });\n}\n","import { camelCase } from \"change-case\";\nimport { match } from \"ts-pattern\";\nimport { CLIError } from \"@/CLIError\";\nimport type {\n AnyCLI,\n CLICommandName,\n CLIFullOptionName,\n CLIOptionAlias,\n CLIOptionParam,\n CLIParam,\n CLIParamDataType,\n CLIPositionalParam,\n CLIPositionalParamName,\n CLIState,\n FullCLIArgValues,\n IAcclimateCLI,\n ValueOfParam,\n} from \"@/AcclimateCLI/AcclimateCLI.types\";\nimport type { EmptyObject } from \"type-fest\";\n\nfunction _isValidFullOptionName(name: string): name is CLIFullOptionName {\n return name.startsWith(\"--\");\n}\n\nfunction _isValidOptionAlias(name: string): name is CLIOptionAlias {\n return name.startsWith(\"-\");\n}\n\nfunction isEmptyObject(obj: object): obj is EmptyObject {\n return Object.keys(obj).length === 0;\n}\n\nfunction _validateParsedValue<\n P extends CLIParam<string>,\n PValue extends ValueOfParam<P>,\n>(options: { parsedValue: PValue; paramConfig: P }): PValue {\n const { parsedValue, paramConfig } = options;\n if (paramConfig.validator) {\n const validator = paramConfig.validator as (\n value: PValue,\n ) => boolean | string;\n const validationResult = validator(parsedValue);\n if (validationResult === true) {\n return parsedValue;\n }\n throw CLIError.invalidCLIParamValue({\n paramName: paramConfig.name,\n paramValue: parsedValue,\n message:\n typeof validationResult === \"string\" ? validationResult : undefined,\n });\n }\n return parsedValue;\n}\n\nfunction _parseAndValidateValue<\n P extends CLIParam<string>,\n PValue extends ValueOfParam<P>,\n>(options: {\n inputValue: string | undefined;\n defaultValue: PValue | undefined;\n paramConfig: P;\n}): PValue {\n const { inputValue, defaultValue, paramConfig } = options;\n if (inputValue === undefined) {\n // if there is no input value, we use the default value for validation.\n // if there is no default value, we throw an error.\n if (defaultValue === undefined) {\n if (_isValidFullOptionName(paramConfig.name)) {\n throw CLIError.missingRequiredOption({\n optionName: paramConfig.name,\n });\n } else {\n throw CLIError.missingRequiredPositionalArg({\n positionalArgName: paramConfig.name,\n });\n }\n }\n\n // and then just validate it. (no need to parse it first)\n return _validateParsedValue({\n parsedValue: defaultValue,\n paramConfig,\n });\n }\n\n const parsedValue =\n paramConfig.parser ?\n (paramConfig.parser(inputValue) as PValue)\n // if no parser was set, we use the default parser\n : (match(paramConfig.type)\n .with(\"boolean\", () => {\n return inputValue === \"false\" ? false : true;\n })\n .with(\"number\", () => {\n return Number.parseInt(inputValue, 10);\n })\n .with(\"string\", () => {\n return inputValue;\n })\n .exhaustive(() => {\n return inputValue;\n }) as PValue);\n return _validateParsedValue({\n parsedValue,\n paramConfig,\n });\n}\n\nfunction _replaceAliases<\n TGlobalOptionArgs extends\n | Record<CLIFullOptionName, CLIOptionParam>\n | EmptyObject,\n TOptionArgs extends Record<CLIFullOptionName, CLIOptionParam> | EmptyObject,\n TPositionalArgs extends\n | Record<CLIPositionalParamName, CLIOptionParam>\n | EmptyObject,\n TCommands extends Record<CLICommandName, AnyCLI> | EmptyObject,\n>({\n aliasedOptionArgs,\n cli,\n}: {\n aliasedOptionArgs: Record<CLIOptionAlias, string>;\n cli: IAcclimateCLI<\n TGlobalOptionArgs,\n TOptionArgs,\n TPositionalArgs,\n TCommands\n >;\n}): Record<CLIOptionAlias, string> {\n const aliasMap = cli.state.aliases;\n return Object.entries(aliasedOptionArgs).reduce(\n (acc, [aliasKey, value]) => {\n const alias = aliasKey as CLIOptionAlias;\n const optionName = aliasMap[alias] ?? alias;\n acc[optionName] = value;\n return acc;\n },\n {} as Record<CLIOptionAlias, string>,\n );\n}\n\nfunction _runCLIHelper<\n TPositionalParams extends\n | Record<CLIPositionalParamName, CLIPositionalParam>\n | EmptyObject,\n TOptionParams extends Record<CLIFullOptionName, CLIOptionParam> | EmptyObject,\n TGlobalOptionParams extends\n | Record<CLIFullOptionName, CLIOptionParam>\n | EmptyObject,\n TCommands extends Record<CLICommandName, AnyCLI> | EmptyObject,\n>(options: {\n rawPositionalArgs: string[];\n rawOptionArgs: Record<CLIOptionAlias, string>;\n rawGlobalOptionArgs: Record<CLIFullOptionName, string>;\n cli: IAcclimateCLI<\n TPositionalParams,\n TOptionParams,\n TGlobalOptionParams,\n TCommands\n >;\n}): void {\n const { rawGlobalOptionArgs, rawOptionArgs, rawPositionalArgs, cli } = {\n ...options,\n rawGlobalOptionArgs: _replaceAliases({\n aliasedOptionArgs: options.rawGlobalOptionArgs,\n cli: options.cli,\n }),\n rawOptionArgs: _replaceAliases({\n aliasedOptionArgs: options.rawOptionArgs,\n\n // TODO(jpsyx): fix that this does not have the CLI may not have all\n cli: options.cli,\n }),\n };\n\n // is the first argument a command?\n const firstArg = rawPositionalArgs[0];\n if (\n firstArg &&\n !isEmptyObject(cli.state.commands) &&\n cli.state.commands[firstArg]\n ) {\n // add the parent's global options to the sub-command\n const commandCLI = Object.values(\n cli.state.globalOptionArgs as Record<CLIFullOptionName, CLIOptionParam>,\n ).reduce(\n (newCmd, argConfig) => {\n return newCmd.addGlobalOption(argConfig);\n },\n cli.getCommandCLI(firstArg as Extract<keyof TCommands, string>) as AnyCLI,\n );\n\n // run the sub-command\n return _runCLIHelper({\n rawPositionalArgs: rawPositionalArgs.slice(1),\n rawOptionArgs,\n rawGlobalOptionArgs,\n cli: commandCLI,\n });\n }\n\n // build the positional arguments dictionary\n // first check that we haven't supplied too many positional arguments\n if (rawPositionalArgs.length > cli.state.positionalArgs.length) {\n throw CLIError.tooManyPositionalArgs({\n count: rawPositionalArgs.length,\n });\n }\n\n // parse positional arguments\n const parsedPositionalArgs = cli.state.positionalArgs.reduce(\n (acc, argConfig, idx) => {\n const rawVal = rawPositionalArgs[idx];\n if (argConfig.required && rawVal === undefined) {\n throw CLIError.missingRequiredPositionalArg({\n positionalArgName: argConfig.name,\n });\n }\n acc[argConfig.name] = _parseAndValidateValue({\n inputValue: rawVal,\n defaultValue: argConfig.defaultValue,\n paramConfig: argConfig,\n });\n return acc;\n },\n {} as Record<string, CLIParamDataType>,\n );\n\n // parse the options\n const parsedOptionArgs = Object.values(\n cli.state.optionArgs as Record<CLIFullOptionName, CLIOptionParam>,\n ).reduce(\n (acc, argConfig) => {\n const rawVal = rawOptionArgs[argConfig.name];\n if (argConfig.required && rawVal === undefined) {\n throw CLIError.missingRequiredOption({\n optionName: argConfig.name,\n });\n }\n\n acc[camelCase(argConfig.name)] = _parseAndValidateValue({\n inputValue: rawVal,\n defaultValue: argConfig.defaultValue,\n paramConfig: argConfig,\n });\n return acc;\n },\n {} as Record<string, CLIParamDataType>,\n );\n\n // parse the global options\n const parsedGlobalOptionArgs = Object.values(\n cli.state.globalOptionArgs as Record<CLIFullOptionName, CLIOptionParam>,\n ).reduce(\n (acc, argConfig) => {\n const rawVal = rawGlobalOptionArgs[argConfig.name];\n if (argConfig.required && rawVal === undefined) {\n throw CLIError.missingRequiredOption({\n optionName: argConfig.name,\n });\n }\n acc[camelCase(argConfig.name)] = _parseAndValidateValue({\n inputValue: rawVal,\n defaultValue: argConfig.defaultValue,\n paramConfig: argConfig,\n });\n return acc;\n },\n {} as Record<string, CLIParamDataType>,\n );\n\n // run the action\n cli.state.action({\n ...parsedPositionalArgs,\n ...parsedOptionArgs,\n ...parsedGlobalOptionArgs,\n } as FullCLIArgValues<TPositionalParams, TOptionParams, TGlobalOptionParams>);\n}\n\n/**\n * Run a CLI instance given an array of inputs.\n *\n * @param options - The options for running the CLI.\n */\nexport function runCLI(options: { input: string[]; cli: AnyCLI }): void {\n const { input, cli } = options;\n const firstOptionIdx = input.findIndex((token) => {\n return token.startsWith(\"-\");\n });\n\n const [rawPositionalArgs, rest] =\n firstOptionIdx === -1 ?\n [input, []]\n : [input.slice(0, firstOptionIdx), input.slice(firstOptionIdx)];\n\n const rawOptionArgs: Record<CLIOptionAlias, string> = {};\n const rawGlobalOptionArgs: Record<CLIFullOptionName, string> = {};\n let currentAlias: CLIOptionAlias | undefined;\n let currentVals: string[] = [];\n\n const { aliases, globalOptionArgs } = cli.state as CLIState<\n Record<CLIFullOptionName, CLIOptionParam>,\n Record<CLIFullOptionName, CLIOptionParam>,\n Record<CLIPositionalParamName, CLIOptionParam>,\n Record<CLICommandName, AnyCLI>\n >;\n\n for (const argVal of rest.concat(\"-\")) {\n if (_isValidOptionAlias(argVal)) {\n if (currentAlias) {\n const rawValue = currentVals.join(\" \");\n const optionName = aliases[currentAlias] ?? currentAlias;\n if (\n _isValidFullOptionName(optionName) &&\n !isEmptyObject(globalOptionArgs) &&\n globalOptionArgs[optionName]\n ) {\n rawGlobalOptionArgs[optionName] = rawValue;\n } else {\n rawOptionArgs[optionName] = rawValue;\n }\n }\n currentAlias = argVal;\n currentVals = [];\n } else {\n currentVals.push(argVal);\n }\n }\n\n _runCLIHelper({ rawPositionalArgs, rawOptionArgs, rawGlobalOptionArgs, cli });\n}\n","import { createCLI } from \"./AcclimateCLI\";\nimport { runCLI } from \"./AcclimateCLI/runCLI/runCLI\";\nimport type { IAcclimateCLI } from \"./AcclimateCLI/AcclimateCLI.types\";\n\ntype Acclimate = {\n /**\n * Create a new Acclimate CLI instance.\n *\n * @param name - The name of the CLI.\n * @returns A new CLI instance.\n */\n createCLI: (name: string) => IAcclimateCLI;\n\n /**\n * Run a CLI instance.\n *\n * It can only be run once. Calling any other methods after `.run()` will\n * throw an error.\n *\n * @param cli - The CLI instance to run.\n */\n run: (cli: IAcclimateCLI) => void;\n};\n\nexport const Acclimate: Acclimate = {\n createCLI,\n run: (cli: IAcclimateCLI) => {\n runCLI({ cli, input: process.argv.slice(2) });\n },\n};\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { EmptyObject, Simplify, CamelCasedProperties } from 'type-fest';
|
|
2
|
+
|
|
3
|
+
type CLIPositionalParamName = string;
|
|
4
|
+
type CLICommandName = string;
|
|
5
|
+
type CLIFullOptionName = `--${string}`;
|
|
6
|
+
type CLIOptionAlias = `--${string}` | `-${string}`;
|
|
7
|
+
type _DropNonStringKeys<T> = {
|
|
8
|
+
[K in Extract<keyof T, string>]: T[K];
|
|
9
|
+
};
|
|
10
|
+
type AddEntry<T, K extends string, V> = Simplify<_DropNonStringKeys<T & {
|
|
11
|
+
[Key in K]: V;
|
|
12
|
+
}>>;
|
|
13
|
+
type _FullCLIParams<TPositionalArgs extends Record<CLIPositionalParamName, CLIPositionalParam>, TOptionArgs extends Record<CLIFullOptionName, CLIOptionParam>, TGlobalOptionArgs extends Record<CLIFullOptionName, CLIOptionParam>> = _DropNonStringKeys<TPositionalArgs & TOptionArgs & TGlobalOptionArgs>;
|
|
14
|
+
type ValueOfParam<T extends CLIParam> = T extends CLIStringParam<string, infer PValue> ? PValue : T extends CLINumberParam<string, infer PValue> ? PValue : T extends CLIBooleanParam<string> ? boolean : never;
|
|
15
|
+
type FullCLIArgValues<TPositionalArgs extends Record<CLIPositionalParamName, CLIPositionalParam>, TOptionArgs extends Record<CLIFullOptionName, CLIOptionParam>, TGlobalOptionArgs extends Record<CLIFullOptionName, CLIOptionParam>> = CamelCasedProperties<{
|
|
16
|
+
[K in keyof _FullCLIParams<TPositionalArgs, TOptionArgs, TGlobalOptionArgs>]: ValueOfParam<_FullCLIParams<TPositionalArgs, TOptionArgs, TGlobalOptionArgs>[K]>;
|
|
17
|
+
}>;
|
|
18
|
+
type CLIBaseParam<PName extends string> = {
|
|
19
|
+
/**
|
|
20
|
+
* The name of the param.
|
|
21
|
+
*/
|
|
22
|
+
name: PName;
|
|
23
|
+
/**
|
|
24
|
+
* The description of the option.
|
|
25
|
+
*/
|
|
26
|
+
description?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Whether to ask the user for a value if the input is empty by entering
|
|
29
|
+
* into an interactive prompt and waiting for a user's input.
|
|
30
|
+
*
|
|
31
|
+
* If `true`, a default message will be presented to the user. Otherwise,
|
|
32
|
+
* if a `{ message }` object is provided, the custom message will be presented
|
|
33
|
+
* to the user.
|
|
34
|
+
*/
|
|
35
|
+
askIfEmpty?: boolean | {
|
|
36
|
+
message: string;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
type CLIStringParam<PName extends string, PValue extends string = string> = CLIBaseParam<PName> & {
|
|
40
|
+
type: "string";
|
|
41
|
+
choices?: PValue[];
|
|
42
|
+
/**
|
|
43
|
+
* The default value of the option.
|
|
44
|
+
* If `required` is true, the `defaultValue` is ignored, because the user
|
|
45
|
+
* must always provide a value.
|
|
46
|
+
*/
|
|
47
|
+
defaultValue?: PValue;
|
|
48
|
+
/**
|
|
49
|
+
* A custom validator function to apply on the parsed value.
|
|
50
|
+
* For example, this is where we might want to check if a value is of the
|
|
51
|
+
* expected format or if it is within a certain range.
|
|
52
|
+
*
|
|
53
|
+
* Returning anything other than `true` will be treated as an error message.
|
|
54
|
+
*
|
|
55
|
+
* If `false` then a generic error message will be used. Otherwise, if a
|
|
56
|
+
* string is returned, then that will be used as the error message.
|
|
57
|
+
* @default undefined
|
|
58
|
+
*/
|
|
59
|
+
validator?: (value: PValue) => boolean | string;
|
|
60
|
+
/**
|
|
61
|
+
* Parses the raw string input into the expected data type.
|
|
62
|
+
*
|
|
63
|
+
* If not provided, the default parser will return the value as is.
|
|
64
|
+
*
|
|
65
|
+
* @param value - The value to parse.
|
|
66
|
+
* @returns The parsed value.
|
|
67
|
+
*/
|
|
68
|
+
parser?: (value: string) => PValue;
|
|
69
|
+
};
|
|
70
|
+
type CLINumberParam<PName extends string, T extends number = number> = CLIBaseParam<PName> & {
|
|
71
|
+
type: "number";
|
|
72
|
+
choices?: T[];
|
|
73
|
+
/**
|
|
74
|
+
* The default value of the option.
|
|
75
|
+
* If `required` is true, the `defaultValue` is ignored, because the user
|
|
76
|
+
* must always provide a value.
|
|
77
|
+
*/
|
|
78
|
+
defaultValue?: T;
|
|
79
|
+
/**
|
|
80
|
+
* A custom validator function to apply on the parsed value.
|
|
81
|
+
* For example, this is where we might want to check if a value is of the
|
|
82
|
+
* expected format or if it is within a certain range.
|
|
83
|
+
*
|
|
84
|
+
* Returning anything other than `true` will be treated as an error message.
|
|
85
|
+
*
|
|
86
|
+
* If `false` then a generic error message will be used. Otherwise, if a
|
|
87
|
+
* string is returned, then that will be used as the error message.
|
|
88
|
+
* @default undefined
|
|
89
|
+
*/
|
|
90
|
+
validator?: (value: T) => boolean | string;
|
|
91
|
+
/**
|
|
92
|
+
* Parses the raw string input into the expected data type.
|
|
93
|
+
*
|
|
94
|
+
* If not provided, the default parser will call `Number.parseInt(value, 10)`.
|
|
95
|
+
*
|
|
96
|
+
* @param value - The value to parse.
|
|
97
|
+
* @returns The parsed value.
|
|
98
|
+
*/
|
|
99
|
+
parser?: (value: string) => T;
|
|
100
|
+
};
|
|
101
|
+
type CLIBooleanParam<PName extends string> = CLIBaseParam<PName> & {
|
|
102
|
+
type: "boolean";
|
|
103
|
+
/**
|
|
104
|
+
* The default value of the option.
|
|
105
|
+
* If `required` is true, the `defaultValue` is ignored, because the user
|
|
106
|
+
* must always provide a value.
|
|
107
|
+
*/
|
|
108
|
+
defaultValue?: boolean;
|
|
109
|
+
/**
|
|
110
|
+
* A custom validator function to apply on the parsed value.
|
|
111
|
+
* For example, this is where we might want to check if a value is of the
|
|
112
|
+
* expected format or if it is within a certain range.
|
|
113
|
+
*
|
|
114
|
+
* Returning anything other than `true` will be treated as an error message.
|
|
115
|
+
*
|
|
116
|
+
* If `false` then a generic error message will be used. Otherwise, if a
|
|
117
|
+
* string is returned, then that will be used as the error message.
|
|
118
|
+
* @default undefined
|
|
119
|
+
*/
|
|
120
|
+
validator?: (value: boolean) => boolean | string;
|
|
121
|
+
/**
|
|
122
|
+
* Parses the raw string input into the expected data type.
|
|
123
|
+
*
|
|
124
|
+
* If not provided, the default parser will treat the string "false" as false
|
|
125
|
+
* and any other value as true. This means that empty strings are treated
|
|
126
|
+
* as true, which is what allows booleans to be parsed as flags by default
|
|
127
|
+
* (without having to explicitly set "true").
|
|
128
|
+
*
|
|
129
|
+
* @param value - The value to parse.
|
|
130
|
+
* @returns The parsed value.
|
|
131
|
+
*/
|
|
132
|
+
parser?: (value: string) => boolean;
|
|
133
|
+
};
|
|
134
|
+
type CLIParam<PName extends string = string> = CLIStringParam<PName> | CLINumberParam<PName> | CLIBooleanParam<PName>;
|
|
135
|
+
type CLIPositionalParam<PName extends string = string> = CLIParam<PName> & {
|
|
136
|
+
/**
|
|
137
|
+
* Whether the parameter is required.
|
|
138
|
+
*
|
|
139
|
+
* Positional arguments can only be optional if they are not followed by any
|
|
140
|
+
* required positional arguments.
|
|
141
|
+
*
|
|
142
|
+
* @default true
|
|
143
|
+
*/
|
|
144
|
+
required: boolean;
|
|
145
|
+
};
|
|
146
|
+
type CLIOptionParam<PName extends CLIFullOptionName = CLIFullOptionName> = CLIParam<PName> & {
|
|
147
|
+
/**
|
|
148
|
+
* The aliases of the positional argument.
|
|
149
|
+
* Aliases must start with `-` or `--` and must be unique within the CLI.
|
|
150
|
+
*/
|
|
151
|
+
aliases?: readonly CLIOptionAlias[];
|
|
152
|
+
/**
|
|
153
|
+
* Whether the parameter is required.
|
|
154
|
+
* @default false
|
|
155
|
+
*/
|
|
156
|
+
required: boolean;
|
|
157
|
+
};
|
|
158
|
+
type AnyCLI = IAcclimateCLI<any, any, any, any>;
|
|
159
|
+
type CLIState<TPositionalParams extends Record<CLIPositionalParamName, CLIPositionalParam> | EmptyObject, TOptionParams extends Record<CLIFullOptionName, CLIOptionParam> | EmptyObject, TGlobalOptionParams extends Record<CLIFullOptionName, CLIOptionParam> | EmptyObject, TCommands extends Record<CLICommandName, AnyCLI> | EmptyObject> = {
|
|
160
|
+
/** The name of the CLI. */
|
|
161
|
+
name: string;
|
|
162
|
+
/**
|
|
163
|
+
* The aliases for options in the CLI. Keys are aliases and values are the
|
|
164
|
+
* canonical name of the option.
|
|
165
|
+
*/
|
|
166
|
+
aliases: Record<CLIOptionAlias, Extract<keyof TGlobalOptionParams | keyof TOptionParams, CLIFullOptionName>>;
|
|
167
|
+
/** The description of the CLI. */
|
|
168
|
+
description?: string;
|
|
169
|
+
/** The commands of the CLI. */
|
|
170
|
+
commands: TCommands;
|
|
171
|
+
/** The positional arguments of the CLI. */
|
|
172
|
+
positionalArgs: TPositionalParams extends EmptyObject ? readonly CLIPositionalParam[] : ReadonlyArray<TPositionalParams[keyof TPositionalParams]>;
|
|
173
|
+
/** The named options of the CLI. */
|
|
174
|
+
optionArgs: TOptionParams;
|
|
175
|
+
/** The global options of the CLI. */
|
|
176
|
+
globalOptionArgs: TGlobalOptionParams;
|
|
177
|
+
/** The action to run when the CLI is executed. */
|
|
178
|
+
action: (args: Simplify<FullCLIArgValues<TPositionalParams, TOptionParams, TGlobalOptionParams>>) => void;
|
|
179
|
+
};
|
|
180
|
+
type IAcclimateCLI<TPositionalParams extends Record<CLIPositionalParamName, CLIPositionalParam> | EmptyObject = EmptyObject, TOptionParams extends Record<CLIFullOptionName, CLIOptionParam> | EmptyObject = EmptyObject, TGlobalOptionParams extends Record<CLIFullOptionName, CLIOptionParam> | EmptyObject = EmptyObject, TCommands extends Record<CLICommandName, AnyCLI> | EmptyObject = EmptyObject> = {
|
|
181
|
+
/** The internal state of the CLI. */
|
|
182
|
+
state: CLIState<TPositionalParams, TOptionParams, TGlobalOptionParams, TCommands>;
|
|
183
|
+
/** Set the description of the CLI. */
|
|
184
|
+
description: (description: string) => IAcclimateCLI<TPositionalParams, TOptionParams, TGlobalOptionParams, TCommands>;
|
|
185
|
+
action: (action: (args: Simplify<FullCLIArgValues<TPositionalParams, TOptionParams, TGlobalOptionParams>>) => void) => IAcclimateCLI<TPositionalParams, TOptionParams, TGlobalOptionParams, TCommands>;
|
|
186
|
+
/**
|
|
187
|
+
* Add a sub-command to the CLI. A command is essentially a nested CLI.
|
|
188
|
+
*
|
|
189
|
+
* If the first positional argument is a command, then Acclimate will parse
|
|
190
|
+
* all subsequent arguments with that command's CLI.
|
|
191
|
+
*/
|
|
192
|
+
addCommand: <C extends CLICommandName, CommandCLI extends IAcclimateCLI<any, any, any, any>>(commandName: C, cli: CommandCLI) => IAcclimateCLI<TPositionalParams, TOptionParams, TGlobalOptionParams, AddEntry<TCommands, C, CommandCLI>>;
|
|
193
|
+
/** Add a positional argument to the CLI. */
|
|
194
|
+
addPositionalArg: <PName extends CLIPositionalParamName, P extends CLIPositionalParam<PName>>(param: P) => IAcclimateCLI<AddEntry<TPositionalParams, P["name"], P>, TOptionParams, TGlobalOptionParams, TCommands>;
|
|
195
|
+
/** Add a global option to the CLI that is available to all commands. */
|
|
196
|
+
addGlobalOption: <const P extends CLIOptionParam>(param: P) => IAcclimateCLI<TPositionalParams, TOptionParams, AddEntry<TGlobalOptionParams, P["name"], P>, TCommands>;
|
|
197
|
+
/** Add a named option to the CLI. */
|
|
198
|
+
addOption: <P extends CLIOptionParam>(param: P) => IAcclimateCLI<TPositionalParams, AddEntry<TOptionParams, P["name"], P>, TGlobalOptionParams, TCommands>;
|
|
199
|
+
/** Get a command's CLI by name. */
|
|
200
|
+
getCommandCLI: <C extends Extract<keyof TCommands, CLICommandName>>(commandName: C) => C extends keyof TCommands ? TCommands[C] : never;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
type Acclimate = {
|
|
204
|
+
/**
|
|
205
|
+
* Create a new Acclimate CLI instance.
|
|
206
|
+
*
|
|
207
|
+
* @param name - The name of the CLI.
|
|
208
|
+
* @returns A new CLI instance.
|
|
209
|
+
*/
|
|
210
|
+
createCLI: (name: string) => IAcclimateCLI;
|
|
211
|
+
/**
|
|
212
|
+
* Run a CLI instance.
|
|
213
|
+
*
|
|
214
|
+
* It can only be run once. Calling any other methods after `.run()` will
|
|
215
|
+
* throw an error.
|
|
216
|
+
*
|
|
217
|
+
* @param cli - The CLI instance to run.
|
|
218
|
+
*/
|
|
219
|
+
run: (cli: IAcclimateCLI) => void;
|
|
220
|
+
};
|
|
221
|
+
declare const Acclimate: Acclimate;
|
|
222
|
+
|
|
223
|
+
export { Acclimate };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { EmptyObject, Simplify, CamelCasedProperties } from 'type-fest';
|
|
2
|
+
|
|
3
|
+
type CLIPositionalParamName = string;
|
|
4
|
+
type CLICommandName = string;
|
|
5
|
+
type CLIFullOptionName = `--${string}`;
|
|
6
|
+
type CLIOptionAlias = `--${string}` | `-${string}`;
|
|
7
|
+
type _DropNonStringKeys<T> = {
|
|
8
|
+
[K in Extract<keyof T, string>]: T[K];
|
|
9
|
+
};
|
|
10
|
+
type AddEntry<T, K extends string, V> = Simplify<_DropNonStringKeys<T & {
|
|
11
|
+
[Key in K]: V;
|
|
12
|
+
}>>;
|
|
13
|
+
type _FullCLIParams<TPositionalArgs extends Record<CLIPositionalParamName, CLIPositionalParam>, TOptionArgs extends Record<CLIFullOptionName, CLIOptionParam>, TGlobalOptionArgs extends Record<CLIFullOptionName, CLIOptionParam>> = _DropNonStringKeys<TPositionalArgs & TOptionArgs & TGlobalOptionArgs>;
|
|
14
|
+
type ValueOfParam<T extends CLIParam> = T extends CLIStringParam<string, infer PValue> ? PValue : T extends CLINumberParam<string, infer PValue> ? PValue : T extends CLIBooleanParam<string> ? boolean : never;
|
|
15
|
+
type FullCLIArgValues<TPositionalArgs extends Record<CLIPositionalParamName, CLIPositionalParam>, TOptionArgs extends Record<CLIFullOptionName, CLIOptionParam>, TGlobalOptionArgs extends Record<CLIFullOptionName, CLIOptionParam>> = CamelCasedProperties<{
|
|
16
|
+
[K in keyof _FullCLIParams<TPositionalArgs, TOptionArgs, TGlobalOptionArgs>]: ValueOfParam<_FullCLIParams<TPositionalArgs, TOptionArgs, TGlobalOptionArgs>[K]>;
|
|
17
|
+
}>;
|
|
18
|
+
type CLIBaseParam<PName extends string> = {
|
|
19
|
+
/**
|
|
20
|
+
* The name of the param.
|
|
21
|
+
*/
|
|
22
|
+
name: PName;
|
|
23
|
+
/**
|
|
24
|
+
* The description of the option.
|
|
25
|
+
*/
|
|
26
|
+
description?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Whether to ask the user for a value if the input is empty by entering
|
|
29
|
+
* into an interactive prompt and waiting for a user's input.
|
|
30
|
+
*
|
|
31
|
+
* If `true`, a default message will be presented to the user. Otherwise,
|
|
32
|
+
* if a `{ message }` object is provided, the custom message will be presented
|
|
33
|
+
* to the user.
|
|
34
|
+
*/
|
|
35
|
+
askIfEmpty?: boolean | {
|
|
36
|
+
message: string;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
type CLIStringParam<PName extends string, PValue extends string = string> = CLIBaseParam<PName> & {
|
|
40
|
+
type: "string";
|
|
41
|
+
choices?: PValue[];
|
|
42
|
+
/**
|
|
43
|
+
* The default value of the option.
|
|
44
|
+
* If `required` is true, the `defaultValue` is ignored, because the user
|
|
45
|
+
* must always provide a value.
|
|
46
|
+
*/
|
|
47
|
+
defaultValue?: PValue;
|
|
48
|
+
/**
|
|
49
|
+
* A custom validator function to apply on the parsed value.
|
|
50
|
+
* For example, this is where we might want to check if a value is of the
|
|
51
|
+
* expected format or if it is within a certain range.
|
|
52
|
+
*
|
|
53
|
+
* Returning anything other than `true` will be treated as an error message.
|
|
54
|
+
*
|
|
55
|
+
* If `false` then a generic error message will be used. Otherwise, if a
|
|
56
|
+
* string is returned, then that will be used as the error message.
|
|
57
|
+
* @default undefined
|
|
58
|
+
*/
|
|
59
|
+
validator?: (value: PValue) => boolean | string;
|
|
60
|
+
/**
|
|
61
|
+
* Parses the raw string input into the expected data type.
|
|
62
|
+
*
|
|
63
|
+
* If not provided, the default parser will return the value as is.
|
|
64
|
+
*
|
|
65
|
+
* @param value - The value to parse.
|
|
66
|
+
* @returns The parsed value.
|
|
67
|
+
*/
|
|
68
|
+
parser?: (value: string) => PValue;
|
|
69
|
+
};
|
|
70
|
+
type CLINumberParam<PName extends string, T extends number = number> = CLIBaseParam<PName> & {
|
|
71
|
+
type: "number";
|
|
72
|
+
choices?: T[];
|
|
73
|
+
/**
|
|
74
|
+
* The default value of the option.
|
|
75
|
+
* If `required` is true, the `defaultValue` is ignored, because the user
|
|
76
|
+
* must always provide a value.
|
|
77
|
+
*/
|
|
78
|
+
defaultValue?: T;
|
|
79
|
+
/**
|
|
80
|
+
* A custom validator function to apply on the parsed value.
|
|
81
|
+
* For example, this is where we might want to check if a value is of the
|
|
82
|
+
* expected format or if it is within a certain range.
|
|
83
|
+
*
|
|
84
|
+
* Returning anything other than `true` will be treated as an error message.
|
|
85
|
+
*
|
|
86
|
+
* If `false` then a generic error message will be used. Otherwise, if a
|
|
87
|
+
* string is returned, then that will be used as the error message.
|
|
88
|
+
* @default undefined
|
|
89
|
+
*/
|
|
90
|
+
validator?: (value: T) => boolean | string;
|
|
91
|
+
/**
|
|
92
|
+
* Parses the raw string input into the expected data type.
|
|
93
|
+
*
|
|
94
|
+
* If not provided, the default parser will call `Number.parseInt(value, 10)`.
|
|
95
|
+
*
|
|
96
|
+
* @param value - The value to parse.
|
|
97
|
+
* @returns The parsed value.
|
|
98
|
+
*/
|
|
99
|
+
parser?: (value: string) => T;
|
|
100
|
+
};
|
|
101
|
+
type CLIBooleanParam<PName extends string> = CLIBaseParam<PName> & {
|
|
102
|
+
type: "boolean";
|
|
103
|
+
/**
|
|
104
|
+
* The default value of the option.
|
|
105
|
+
* If `required` is true, the `defaultValue` is ignored, because the user
|
|
106
|
+
* must always provide a value.
|
|
107
|
+
*/
|
|
108
|
+
defaultValue?: boolean;
|
|
109
|
+
/**
|
|
110
|
+
* A custom validator function to apply on the parsed value.
|
|
111
|
+
* For example, this is where we might want to check if a value is of the
|
|
112
|
+
* expected format or if it is within a certain range.
|
|
113
|
+
*
|
|
114
|
+
* Returning anything other than `true` will be treated as an error message.
|
|
115
|
+
*
|
|
116
|
+
* If `false` then a generic error message will be used. Otherwise, if a
|
|
117
|
+
* string is returned, then that will be used as the error message.
|
|
118
|
+
* @default undefined
|
|
119
|
+
*/
|
|
120
|
+
validator?: (value: boolean) => boolean | string;
|
|
121
|
+
/**
|
|
122
|
+
* Parses the raw string input into the expected data type.
|
|
123
|
+
*
|
|
124
|
+
* If not provided, the default parser will treat the string "false" as false
|
|
125
|
+
* and any other value as true. This means that empty strings are treated
|
|
126
|
+
* as true, which is what allows booleans to be parsed as flags by default
|
|
127
|
+
* (without having to explicitly set "true").
|
|
128
|
+
*
|
|
129
|
+
* @param value - The value to parse.
|
|
130
|
+
* @returns The parsed value.
|
|
131
|
+
*/
|
|
132
|
+
parser?: (value: string) => boolean;
|
|
133
|
+
};
|
|
134
|
+
type CLIParam<PName extends string = string> = CLIStringParam<PName> | CLINumberParam<PName> | CLIBooleanParam<PName>;
|
|
135
|
+
type CLIPositionalParam<PName extends string = string> = CLIParam<PName> & {
|
|
136
|
+
/**
|
|
137
|
+
* Whether the parameter is required.
|
|
138
|
+
*
|
|
139
|
+
* Positional arguments can only be optional if they are not followed by any
|
|
140
|
+
* required positional arguments.
|
|
141
|
+
*
|
|
142
|
+
* @default true
|
|
143
|
+
*/
|
|
144
|
+
required: boolean;
|
|
145
|
+
};
|
|
146
|
+
type CLIOptionParam<PName extends CLIFullOptionName = CLIFullOptionName> = CLIParam<PName> & {
|
|
147
|
+
/**
|
|
148
|
+
* The aliases of the positional argument.
|
|
149
|
+
* Aliases must start with `-` or `--` and must be unique within the CLI.
|
|
150
|
+
*/
|
|
151
|
+
aliases?: readonly CLIOptionAlias[];
|
|
152
|
+
/**
|
|
153
|
+
* Whether the parameter is required.
|
|
154
|
+
* @default false
|
|
155
|
+
*/
|
|
156
|
+
required: boolean;
|
|
157
|
+
};
|
|
158
|
+
type AnyCLI = IAcclimateCLI<any, any, any, any>;
|
|
159
|
+
type CLIState<TPositionalParams extends Record<CLIPositionalParamName, CLIPositionalParam> | EmptyObject, TOptionParams extends Record<CLIFullOptionName, CLIOptionParam> | EmptyObject, TGlobalOptionParams extends Record<CLIFullOptionName, CLIOptionParam> | EmptyObject, TCommands extends Record<CLICommandName, AnyCLI> | EmptyObject> = {
|
|
160
|
+
/** The name of the CLI. */
|
|
161
|
+
name: string;
|
|
162
|
+
/**
|
|
163
|
+
* The aliases for options in the CLI. Keys are aliases and values are the
|
|
164
|
+
* canonical name of the option.
|
|
165
|
+
*/
|
|
166
|
+
aliases: Record<CLIOptionAlias, Extract<keyof TGlobalOptionParams | keyof TOptionParams, CLIFullOptionName>>;
|
|
167
|
+
/** The description of the CLI. */
|
|
168
|
+
description?: string;
|
|
169
|
+
/** The commands of the CLI. */
|
|
170
|
+
commands: TCommands;
|
|
171
|
+
/** The positional arguments of the CLI. */
|
|
172
|
+
positionalArgs: TPositionalParams extends EmptyObject ? readonly CLIPositionalParam[] : ReadonlyArray<TPositionalParams[keyof TPositionalParams]>;
|
|
173
|
+
/** The named options of the CLI. */
|
|
174
|
+
optionArgs: TOptionParams;
|
|
175
|
+
/** The global options of the CLI. */
|
|
176
|
+
globalOptionArgs: TGlobalOptionParams;
|
|
177
|
+
/** The action to run when the CLI is executed. */
|
|
178
|
+
action: (args: Simplify<FullCLIArgValues<TPositionalParams, TOptionParams, TGlobalOptionParams>>) => void;
|
|
179
|
+
};
|
|
180
|
+
type IAcclimateCLI<TPositionalParams extends Record<CLIPositionalParamName, CLIPositionalParam> | EmptyObject = EmptyObject, TOptionParams extends Record<CLIFullOptionName, CLIOptionParam> | EmptyObject = EmptyObject, TGlobalOptionParams extends Record<CLIFullOptionName, CLIOptionParam> | EmptyObject = EmptyObject, TCommands extends Record<CLICommandName, AnyCLI> | EmptyObject = EmptyObject> = {
|
|
181
|
+
/** The internal state of the CLI. */
|
|
182
|
+
state: CLIState<TPositionalParams, TOptionParams, TGlobalOptionParams, TCommands>;
|
|
183
|
+
/** Set the description of the CLI. */
|
|
184
|
+
description: (description: string) => IAcclimateCLI<TPositionalParams, TOptionParams, TGlobalOptionParams, TCommands>;
|
|
185
|
+
action: (action: (args: Simplify<FullCLIArgValues<TPositionalParams, TOptionParams, TGlobalOptionParams>>) => void) => IAcclimateCLI<TPositionalParams, TOptionParams, TGlobalOptionParams, TCommands>;
|
|
186
|
+
/**
|
|
187
|
+
* Add a sub-command to the CLI. A command is essentially a nested CLI.
|
|
188
|
+
*
|
|
189
|
+
* If the first positional argument is a command, then Acclimate will parse
|
|
190
|
+
* all subsequent arguments with that command's CLI.
|
|
191
|
+
*/
|
|
192
|
+
addCommand: <C extends CLICommandName, CommandCLI extends IAcclimateCLI<any, any, any, any>>(commandName: C, cli: CommandCLI) => IAcclimateCLI<TPositionalParams, TOptionParams, TGlobalOptionParams, AddEntry<TCommands, C, CommandCLI>>;
|
|
193
|
+
/** Add a positional argument to the CLI. */
|
|
194
|
+
addPositionalArg: <PName extends CLIPositionalParamName, P extends CLIPositionalParam<PName>>(param: P) => IAcclimateCLI<AddEntry<TPositionalParams, P["name"], P>, TOptionParams, TGlobalOptionParams, TCommands>;
|
|
195
|
+
/** Add a global option to the CLI that is available to all commands. */
|
|
196
|
+
addGlobalOption: <const P extends CLIOptionParam>(param: P) => IAcclimateCLI<TPositionalParams, TOptionParams, AddEntry<TGlobalOptionParams, P["name"], P>, TCommands>;
|
|
197
|
+
/** Add a named option to the CLI. */
|
|
198
|
+
addOption: <P extends CLIOptionParam>(param: P) => IAcclimateCLI<TPositionalParams, AddEntry<TOptionParams, P["name"], P>, TGlobalOptionParams, TCommands>;
|
|
199
|
+
/** Get a command's CLI by name. */
|
|
200
|
+
getCommandCLI: <C extends Extract<keyof TCommands, CLICommandName>>(commandName: C) => C extends keyof TCommands ? TCommands[C] : never;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
type Acclimate = {
|
|
204
|
+
/**
|
|
205
|
+
* Create a new Acclimate CLI instance.
|
|
206
|
+
*
|
|
207
|
+
* @param name - The name of the CLI.
|
|
208
|
+
* @returns A new CLI instance.
|
|
209
|
+
*/
|
|
210
|
+
createCLI: (name: string) => IAcclimateCLI;
|
|
211
|
+
/**
|
|
212
|
+
* Run a CLI instance.
|
|
213
|
+
*
|
|
214
|
+
* It can only be run once. Calling any other methods after `.run()` will
|
|
215
|
+
* throw an error.
|
|
216
|
+
*
|
|
217
|
+
* @param cli - The CLI instance to run.
|
|
218
|
+
*/
|
|
219
|
+
run: (cli: IAcclimateCLI) => void;
|
|
220
|
+
};
|
|
221
|
+
declare const Acclimate: Acclimate;
|
|
222
|
+
|
|
223
|
+
export { Acclimate };
|