zod-args-parser 1.0.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.
@@ -0,0 +1 @@
1
+ {"version":3,"names":["help","decoupleFlags","getOrdinalPlacement","isBooleanSchema","isFlagArg","isOptionArg","noName","stringToBoolean","transformArg","transformOptionToArg","parse","argsv","_len","arguments","length","params","Array","_key","cliOptions","subcommandArr","allSubcommands","Set","flatMap","c","name","aliases","results","subcommand","undefined","printCliHelp","opt","printSubcommandHelp","subcommandStr","find","console","error","cliName","addRawArg","optionName","rawArg","_info","Object","create","addRawValue","rawValue","addSource","source","fillOption","value","assign","i","arg","has","subcommandProps","allowPositional","positional","argAndValue","split","filter","Boolean","argWithEquals","includes","argument","argValue","Error","options","msg","isNegative","startsWith","option","o","map","isTypeBoolean","type","nextArg","optionValue","parsedBoolean","res","safeParse","success","errors","message","data","rawVal","currentArgCount","argType","push","isOptional","hasDefault","_def","defaultValue","subcommandArgCount","argumentType","action","_len2","_key2","e"],"sourceRoot":"../../src","sources":["parser.ts"],"sourcesContent":["import { help } from \"./help.js\";\nimport {\n decoupleFlags,\n getOrdinalPlacement,\n isBooleanSchema,\n isFlagArg,\n isOptionArg,\n noName,\n stringToBoolean,\n transformArg,\n transformOptionToArg,\n} from \"./utils.js\";\n\nimport type {\n Cli,\n NoSubcommand,\n Option,\n PrintHelpOpt,\n SafeParseResult,\n Subcommand,\n UnSafeParseResult,\n} from \"./types.js\";\n\nexport function parse<T extends Subcommand[]>(argsv: string[], ...params: T): UnSafeParseResult<T>;\nexport function parse<T extends Subcommand[], U extends Cli>(\n argsv: string[],\n ...params: [U, ...T]\n): UnSafeParseResult<[...T, NoSubcommand & U]>;\n\nexport function parse<T extends Subcommand[], U extends Cli>(argsv: string[], ...params: [U, ...T]) {\n const cliOptions = (\"cliName\" in params[0] ? params[0] : {}) as U;\n const subcommandArr = params as unknown as T;\n const allSubcommands = new Set<string>(subcommandArr.flatMap(c => [c.name, ...(c.aliases || [])]));\n\n // decouple flags E.g. `-rf` -> `-r, -f`\n argsv = decoupleFlags(argsv);\n\n type ResultObj = Record<string, unknown> & {\n subcommand: string | undefined;\n positional?: string[];\n arguments?: unknown[];\n _info?: Record<string, { rawArg?: string; rawValue?: string; source: \"cli\" | \"default\" }>;\n printCliHelp: (options?: PrintHelpOpt) => void;\n printSubcommandHelp: (subcommand: any, options?: PrintHelpOpt) => void;\n };\n\n const results: ResultObj = {\n subcommand: undefined,\n printCliHelp(opt) {\n help.printCliHelp(params, opt);\n },\n printSubcommandHelp(subcommandStr, opt) {\n const subcommand = subcommandArr.find(c => c.name === subcommandStr);\n if (!subcommand) return console.error(`Cannot print help for subcommand \"${subcommandStr}\" as it does not exist`);\n help.printSubcommandHelp(subcommand, opt, cliOptions.cliName);\n },\n };\n\n const addRawArg = (optionName: string, rawArg: string) => {\n if (!results._info) results._info = {};\n if (!results._info[optionName]) results._info[optionName] = Object.create({});\n results._info[optionName].rawArg = rawArg;\n };\n\n const addRawValue = (optionName: string, rawValue: string) => {\n if (!results._info) results._info = {};\n if (!results._info[optionName]) results._info[optionName] = Object.create({});\n results._info[optionName].rawValue = rawValue;\n };\n\n const addSource = (optionName: string, source: \"cli\" | \"default\") => {\n if (!results._info) results._info = {};\n if (!results._info[optionName]) results._info[optionName] = Object.create({});\n results._info[optionName].source = source;\n };\n\n const fillOption = (optionName: string, value: Option) => {\n if (!results._info) results._info = {};\n if (!results._info[optionName]) results._info[optionName] = Object.create({});\n Object.assign(results._info[optionName], value);\n };\n\n for (let i = 0; i < argsv.length; i++) {\n const arg = argsv[i];\n\n // * subcommand\n if (i === 0) {\n results.subcommand = allSubcommands.has(arg) ? arg : undefined;\n\n // add positional and arguments array\n const subcommandProps = subcommandArr.find(c => c.name === results.subcommand);\n if (subcommandProps?.allowPositional) results.positional = [];\n if (subcommandProps?.arguments?.length) results.arguments = [];\n\n if (results.subcommand) continue;\n }\n\n // * option\n const argAndValue = arg.split(\"=\").filter(Boolean);\n const argWithEquals = arg.includes(\"=\");\n const argument = argAndValue[0];\n const argValue: string | undefined = argAndValue[1];\n\n if (isOptionArg(argument)) {\n if (isFlagArg(argument) && argWithEquals) {\n throw new Error(`Flag arguments cannot be assigned using \"=\": \"${arg}\"`);\n }\n\n const subcommandProps = subcommandArr.find(c => c.name === results.subcommand);\n if (!subcommandProps) throw new Error(`Unknown subcommand: \"${results.subcommand}\"`);\n\n if (!subcommandProps.options) {\n const msg = !results.subcommand\n ? \"options are not allowed here\"\n : `subcommand \"${results.subcommand}\" does not allow options`;\n throw new Error(`Error: ${msg}: \"${argument}\"`);\n }\n\n const optionName = transformArg(argument);\n if (optionName in results) throw new Error(`Duplicate option: \"${argument}\"`);\n\n const isNegative = argument.startsWith(\"--no-\");\n\n const option = subcommandProps.options.find(o => {\n if (o.name === optionName) return true;\n if (isNegative && noName(o.name) === optionName) return true;\n\n if (!o.aliases) return false;\n if (o.aliases.includes(optionName)) return true;\n if (isNegative && o.aliases.map(noName).includes(optionName)) return true;\n\n return false;\n });\n\n if (!option) {\n throw new Error(`Unknown option: \"${argument}\"`);\n }\n\n const isTypeBoolean = isBooleanSchema(option.type);\n const nextArg = argsv[i + 1];\n\n let optionValue: string | boolean = argWithEquals ? argValue : nextArg;\n\n if (isTypeBoolean) {\n if (argWithEquals) {\n const parsedBoolean = stringToBoolean(argValue);\n optionValue = isNegative ? !parsedBoolean : parsedBoolean;\n } else {\n optionValue = !isNegative;\n }\n }\n\n if (typeof optionValue === \"undefined\") {\n throw new Error(`Expected a value for \"${argument}\" but got nothing`);\n }\n\n if (!argWithEquals && isOptionArg(optionValue)) {\n throw new Error(`Expected a value for \"${argument}\" but got an argument \"${nextArg}\"`);\n }\n\n const res = option.type.safeParse(optionValue);\n if (!res.success) {\n throw new Error(`Invalid value \"${optionValue}\" for \"${argument}\": ${res.error.errors[0].message}`);\n }\n\n results[option.name] = res.data;\n addRawArg(option.name, argument);\n const rawVal = argWithEquals ? argValue : isTypeBoolean ? \"\" : nextArg;\n addRawValue(option.name, rawVal);\n fillOption(option.name, option);\n\n if (!argWithEquals && !isTypeBoolean) i++;\n continue;\n }\n\n const subcommandProps = subcommandArr.find(c => c.name === results.subcommand);\n\n // * arguments\n if (subcommandProps?.arguments?.length) {\n if (!results.arguments) results.arguments = [];\n\n const currentArgCount = results.arguments.length;\n\n if (currentArgCount < subcommandProps.arguments.length) {\n const argType = subcommandProps.arguments[currentArgCount].type;\n\n let argValue: string | boolean = arg;\n const isTypeBoolean = isBooleanSchema(argType);\n if (isTypeBoolean) argValue = stringToBoolean(argValue);\n\n const res = argType.safeParse(argValue);\n if (!res.success) {\n throw new Error(\n `The ${getOrdinalPlacement(currentArgCount)} argument \"${arg}\" is invalid: ${res.error.errors[0].message}`,\n );\n }\n\n results.arguments.push(res.data);\n continue;\n }\n }\n\n // * positional\n if (subcommandProps?.allowPositional) {\n if (!results.positional) results.positional = [];\n results.positional.push(arg);\n continue;\n }\n\n const msg = !results.subcommand ? \"here\" : `for subcommand \"${results.subcommand}\"`;\n throw new Error(`Unexpected argument \"${arg}\": positional arguments are not allowed ${msg}`);\n }\n\n // check for missing options - set defaults - add _source\n const subcommandProps = subcommandArr.find(c => c.name === results.subcommand);\n if (subcommandProps?.options?.length) {\n for (const option of subcommandProps.options) {\n if (option.name in results) {\n addSource(option.name, \"cli\");\n fillOption(option.name, option);\n continue;\n }\n\n if (option.type.isOptional()) {\n const hasDefault = typeof option.type._def.defaultValue === \"function\";\n if (!hasDefault) continue;\n results[option.name] = option.type._def.defaultValue();\n addSource(option.name, \"default\");\n fillOption(option.name, option);\n continue;\n }\n\n throw new Error(`Missing required option: ${transformOptionToArg(option.name)}`);\n }\n }\n\n // check for arguments - set defaults\n if (subcommandProps?.arguments?.length) {\n const currentArgCount = results.arguments?.length ?? 0;\n const subcommandArgCount = subcommandProps.arguments.length;\n\n // missing arguments\n if (currentArgCount < subcommandArgCount) {\n for (let i = currentArgCount; i < subcommandArgCount; i++) {\n const argumentType = subcommandProps.arguments[i].type;\n const hasDefault = typeof argumentType._def.defaultValue === \"function\";\n if (hasDefault && results.arguments) {\n results.arguments.push(argumentType._def.defaultValue());\n continue;\n }\n\n if (argumentType.isOptional()) continue;\n\n throw new Error(`the ${getOrdinalPlacement(i)} argument is required: \"${subcommandProps.arguments[i].name}\"`);\n }\n }\n }\n\n if (subcommandProps?.action) {\n subcommandProps.action(results);\n }\n\n return results as UnSafeParseResult<[...T, NoSubcommand & U]>;\n}\n\nexport function safeParse<T extends Subcommand[]>(argsv: string[], ...params: T): SafeParseResult<T>;\nexport function safeParse<T extends Subcommand[], U extends Cli>(\n argsv: string[],\n ...params: [U, ...T]\n): SafeParseResult<[...T, NoSubcommand & U]>;\n\nexport function safeParse<T extends Subcommand[], U extends Cli>(argsv: string[], ...params: [U, ...T]) {\n const cliOptions = (\"cliName\" in params[0] ? params[0] : {}) as U;\n const subcommandArr = params as Subcommand[];\n\n const printCliHelp = (opt?: PrintHelpOpt) => help.printCliHelp(params, opt);\n const printSubcommandHelp = (subcommandStr: NonNullable<T[number][\"name\"]>, opt?: PrintHelpOpt) => {\n const subcommand = subcommandArr.find(c => c.name === subcommandStr);\n if (!subcommand) return console.error(`Cannot print help for subcommand \"${subcommandStr}\" as it does not exist`);\n help.printSubcommandHelp(subcommand, opt, cliOptions.cliName);\n };\n\n try {\n const data = parse(argsv, ...params);\n // @ts-expect-error error\n delete data.printCliHelp;\n // @ts-expect-error error\n delete data.printSubcommandHelp;\n\n return {\n success: true,\n data: data as Omit<typeof data, \"printCliHelp\" | \"printSubcommandHelp\">,\n printCliHelp,\n printSubcommandHelp,\n };\n } catch (e) {\n return { success: false, error: e as Error, printCliHelp, printSubcommandHelp };\n }\n}\n"],"mappings":"AAAA,OAASA,IAAI,KAAQ,WAAW,CAChC,OACEC,aAAa,CACbC,mBAAmB,CACnBC,eAAe,CACfC,SAAS,CACTC,WAAW,CACXC,MAAM,CACNC,eAAe,CACfC,YAAY,CACZC,oBAAoB,KACf,YAAY,CAkBnB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D,YAAY,CAExB,MAAO,CAAAqD,IAAI,CAACnD,mBAAmB,CAE/B,MAAO,CACLgD,OAAO,CAAE,IAAI,CACbG,IAAI,CAAEA,IAAiE,CACvErD,YAAY,CACZE,mBACF,CAAC,CACH,CAAE,MAAOiE,CAAC,CAAE,CACV,MAAO,CAAEjB,OAAO,CAAE,KAAK,CAAE5C,KAAK,CAAE6D,CAAU,CAAEnE,YAAY,CAAEE,mBAAoB,CAAC,CACjF,CACF","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export{};
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["types.ts"],"sourcesContent":["import type { z } from \"zod\";\n\nexport type Subcommand = {\n /**\n * - The subcommand name, use `kebab-case`.\n * - Make sure to not duplicate commands and aliases.\n *\n * @example\n * name: \"test\";\n * name: \"run-app\";\n */\n name: string;\n\n /**\n * - The action is executed with the result of the parsed arguments.\n * - To get typescript types use `setAction` instead of this.\n *\n * @example\n * const helpCommand = createSubcommand({ name: \"help\", options: [...] });\n * helpCommand.setAction(res => console.log(res));\n */\n action?: (results?: any) => void;\n\n /**\n * - The description of the subcommand.\n * - Used for generating the help message.\n */\n description?: string;\n\n /** - Used for generating the help message. */\n placeholder?: string;\n\n /**\n * - Provide an example to show to the user.\n * - Used for generating the help message.\n */\n example?: string;\n\n /**\n * - The aliases of the subcommand.\n * - Make sure to not duplicate aliases and commands.\n */\n aliases?: string[];\n\n /**\n * - Allows positional arguments for this subcommand.\n * - Unlike `arguments`, which are strictly typed, positional arguments are untyped and represented as a string array of\n * variable length.\n * - When enabled and `arguments` are provided, `arguments` will be parsed first. Any remaining arguments will be\n * considered positional arguments and added to the `positional` property in the result.\n */\n allowPositional?: boolean;\n\n /**\n * - The options of the command.\n * - Those options are specific to this subcommand.\n */\n options?: [Option, ...Option[]];\n\n /**\n * - Specifies a list of strictly typed arguments.\n * - The order is important; for example, the first argument will be validated against the first specified type.\n * - It is recommended to not use optional arguments as the parser will fill the arguments by order and can't determine\n * which arguments are optional.\n */\n arguments?: [Argument, ...Argument[]];\n};\n\nexport type Cli = Prettify<\n Omit<Subcommand, \"name\"> & {\n /** - The name of the CLI program. */\n cliName: string;\n\n /**\n * - The usage of the CLI program.\n * - Used for generating the help message.\n */\n usage?: string;\n }\n>;\n\nexport type Option = {\n /**\n * - The name of the option, use `CamelCase`.\n * - For example: the syntax for the option `rootPath` is `--root-path`.\n */\n name: string;\n\n /**\n * - The will be used to validate the user input.\n *\n * @example\n * type: z.boolean().default(false);\n * type: z.coerce.number(); // will be coerced to number by Zod\n * type: z.preprocess(parseStringToArrFn, z.array(z.coerce.number())); // array of numbers\n *\n * @see https://zod.dev/?id=types\n */\n type: z.ZodTypeAny;\n\n /**\n * - The description of the option.\n * - Used for generating the help message.\n */\n description?: string;\n\n /** - Used for generating the help message. */\n placeholder?: string;\n\n /**\n * - The example of using the option.\n * - Used for generating the help message.\n */\n example?: string;\n\n /**\n * - The aliases of the option, use `CamelCase`.\n * - Here you can specify short names or flags.\n * - Make sure to not duplicate aliases.\n */\n aliases?: [string, ...string[]];\n};\n\nexport type Argument = {\n /** - The name of the argument. */\n name: string;\n\n /**\n * - The will be used to validate the user input.\n *\n * @example\n * type: z.boolean();\n * type: z.coerce.number(); // will be coerced to number by Zod\n * type: z.preprocess(ParseStringToArrFn, z.array(z.coerce.number())); // array of numbers\n *\n * @see https://zod.dev/?id=types\n */\n type: z.ZodTypeAny;\n\n /**\n * - The description of the argument.\n * - Used for generating the help message.\n */\n description?: string;\n\n /**\n * - The example of using the argument.\n * - Used for generating the help message.\n */\n example?: string;\n};\n\nexport type ColorFnType = (...text: unknown[]) => string;\n\nexport type PrintHelpOpt = {\n /**\n * - **Optional** `boolean`\n * - Whether to print colors or not.\n * - Default: `true`\n */\n colors?: boolean;\n\n /**\n * - **Optional** `object`\n * - The colors to use for the help message.\n */\n customColors?: {\n title?: ColorFnType;\n description?: ColorFnType;\n default?: ColorFnType;\n optional?: ColorFnType;\n exampleTitle?: ColorFnType;\n example?: ColorFnType;\n command?: ColorFnType;\n option?: ColorFnType;\n argument?: ColorFnType;\n placeholder?: ColorFnType;\n punctuation?: ColorFnType;\n };\n};\n\nexport type _Info = {\n /**\n * - The raw argument as it was passed in\n * - For options that have a default value and are not passed in, the raw argument will be `undefined`\n */\n rawArg?: string;\n /**\n * - The raw value of the argument as it was passed in\n * - It will be empty string for `boolean` options. E.g. `--help` or `-h`\n * - For options that have a default value and are not passed in, the raw value will be `undefined`\n */\n rawValue?: string;\n /**\n * - The source value of the argument:\n * - `cli`: The argument was passed in by the user\n * - `default`: The argument was not passed in and has a default value\n */\n source: \"cli\" | \"default\";\n};\n\n/**\n * - Infer the options type from a subcommand.\n *\n * @example\n * const subcommand = createSubcommand({ name: \"build\", options: [...] });\n * type OptionsType = InferOptionsType<typeof subcommand>;\n */\nexport type InferOptionsType<T extends Partial<Subcommand>> = T[\"options\"] extends infer U extends Option[]\n ? ToOptional<{ [K in U[number][\"name\"]]: z.infer<Extract<U[number], { name: K }>[\"type\"]> }>\n : undefined;\n\n/**\n * - Infer the arguments type from a subcommand.\n *\n * @example\n * const subcommand = createSubcommand({ name: \"build\", arguments: [...] });\n * type ArgumentsType = InferArgumentsType<typeof subcommand>;\n */\nexport type InferArgumentsType<T extends Partial<Subcommand>> = T[\"arguments\"] extends infer U extends Argument[]\n ? { [K in keyof U]: U[K] extends { type: z.ZodTypeAny } ? z.infer<U[K][\"type\"]> : never }\n : undefined;\n\n/** `{ some props } & { other props }` => `{ some props, other props }` */\nexport type Prettify<T> = { [K in keyof T]: T[K] } & {};\n\n/** Allow string type for literal union and get auto completion */\nexport type LiteralUnion<T extends string> = T | (string & {});\n\n/** Extract the undefined properties from an object */\ntype UndefinedProperties<T> = { [P in keyof T]-?: undefined extends T[P] ? P : never }[keyof T];\n\n/** Make undefined properties optional? */\ntype ToOptional<T> = Prettify<\n Partial<Pick<T, UndefinedProperties<T>>> & Pick<T, Exclude<keyof T, UndefinedProperties<T>>>\n>;\n\nexport type OptionsArr2RecordType<T extends Option[] | undefined> = T extends Option[]\n ? ToOptional<{ [K in T[number][\"name\"]]: z.infer<Extract<T[number], { name: K }>[\"type\"]> }>\n : object;\n\nexport type ArgumentsArr2ArrType<T extends Argument[] | undefined> = T extends Argument[]\n ? { arguments: { [K in keyof T]: T[K] extends { type: z.ZodTypeAny } ? z.infer<T[K][\"type\"]> : never } }\n : object;\n\nexport type Positional<S extends Partial<Subcommand>> = S[\"allowPositional\"] extends true ? { positional: string[] } : object;\n\nexport type Info<T extends Option[] | undefined> = T extends Option[]\n ? {\n _info: ToOptional<{\n [K in T[number][\"name\"]]: Extract<T[number], { name: K }> extends infer U extends Option\n ? undefined extends z.infer<U[\"type\"]>\n ? undefined | Prettify<_Info & U> // if optional add undefined\n : Prettify<_Info & U>\n : never;\n }>;\n }\n : object;\n\nexport type NoSubcommand = { name: undefined };\n\nexport type ParseResult<S extends Partial<Subcommand>[]> = {\n [K in keyof S]: Prettify<\n { subcommand: S[K][\"name\"] } & Positional<S[K]> &\n Info<S[K][\"options\"]> &\n OptionsArr2RecordType<S[K][\"options\"]> &\n ArgumentsArr2ArrType<S[K][\"arguments\"]>\n >;\n}[number];\n\nexport type PrintMethods<N extends Subcommand[\"name\"] | undefined> = {\n printCliHelp: (options?: PrintHelpOpt) => void;\n printSubcommandHelp: (subcommand: LiteralUnion<NonNullable<N>>, options?: PrintHelpOpt) => void;\n};\n\nexport type UnSafeParseResult<S extends Partial<Subcommand>[]> = Prettify<\n ParseResult<S> & PrintMethods<S[number][\"name\"]>\n>;\n\nexport type SafeParseResult<S extends Partial<Subcommand>[]> = Prettify<\n ({ success: false; error: Error } | { success: true; data: ParseResult<S> }) & PrintMethods<S[number][\"name\"]>\n>;\n\nexport type ActionFn<T extends Subcommand | Cli> = {\n setAction: (actions: (res: UnSafeParseResult<[T]>) => void) => void;\n};\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1 @@
1
+ import assert from"node:assert";import{z}from"zod";export function transformArg(name){assert(name.startsWith("-"),`[transformArg] Invalid arg name: ${name}`);name=name.startsWith("--")?name.substring(2):name.substring(1);return name.replace(/-([a-z])/g,g=>g[1].toUpperCase());}export function transformOptionToArg(name){name=name.replace(/^[A-Z]/g,g=>g.toLowerCase());if(name.length===1)return`-${name}`;return`--${name.replace(/[A-Z]/g,g=>"-"+g.toLowerCase())}`;}export function isFlagArg(name){return /^-[a-z]$/.test(name);}export function isOptionArg(name){if(typeof name!=="string")return false;return isFlagArg(name)||name.startsWith("--");}export function noName(name){if(name.length===1)return name;return"no"+name.replace(/^[a-z]/,g=>g.toUpperCase());}export function stringToBoolean(str){if(str.toLowerCase()==="true")return true;if(str.toLowerCase()==="false")return false;throw new Error(`[stringToBoolean] Invalid boolean value: "${str}"; Expected "true" or "false"`);}export function getOrdinalPlacement(index){if(index<0)return"";const suffixes=["th","st","nd","rd"];const lastDigit=index%10;const lastTwoDigits=index%100;const suffix=lastDigit===1&&lastTwoDigits!==11?suffixes[1]:lastDigit===2&&lastTwoDigits!==12?suffixes[2]:lastDigit===3&&lastTwoDigits!==13?suffixes[3]:suffixes[0];return`${index+1}${suffix}`;}export function isBooleanSchema(schema){let type=schema;while(type){if(type instanceof z.ZodBoolean){return true;}if(type instanceof z.ZodLiteral){return type.value===true||type.value===false;}type=type._def.innerType;}return false;}export function getDefaultValueFromSchema(schema){let type=schema;while(type){if(type instanceof z.ZodDefault){const defaultValue=type._def.defaultValue();return defaultValue;}type=type._def.innerType;}return undefined;}export function decoupleFlags(args){const flagsRe=/^-[a-z]{2,}$/i;const result=[];for(let i=0;i<args.length;i++){const arg=args[i];const isCoupled=flagsRe.test(arg);if(!isCoupled){result.push(arg);continue;}const decoupledArr=arg.substring(1).split("").map(c=>"-"+c);result.push(...decoupledArr);}return result;}export function print(){for(var _len=arguments.length,messages=new Array(_len),_key=0;_key<_len;_key++){messages[_key]=arguments[_key];}return process.stdout.write(messages.join(" "));}export function println(){for(var _len2=arguments.length,messages=new Array(_len2),_key2=0;_key2<_len2;_key2++){messages[_key2]=arguments[_key2];}messages=messages.filter(Boolean);return console.log(...messages);}export function ln(count){return"\n".repeat(count);}export function indent(count){return" ".repeat(count);}export function addIndentLn(message){let indent=arguments.length>1&&arguments[1]!==undefined?arguments[1]:"";return message.replace(/\n/g,`\n${indent}`);}export function concat(){for(var _len3=arguments.length,messages=new Array(_len3),_key3=0;_key3<_len3;_key3++){messages[_key3]=arguments[_key3];}messages=messages.filter(Boolean);return messages.join(" ");}
@@ -0,0 +1 @@
1
+ {"version":3,"names":["assert","z","transformArg","name","startsWith","substring","replace","g","toUpperCase","transformOptionToArg","toLowerCase","length","isFlagArg","test","isOptionArg","noName","stringToBoolean","str","Error","getOrdinalPlacement","index","suffixes","lastDigit","lastTwoDigits","suffix","isBooleanSchema","schema","type","ZodBoolean","ZodLiteral","value","_def","innerType","getDefaultValueFromSchema","ZodDefault","defaultValue","undefined","decoupleFlags","args","flagsRe","result","i","arg","isCoupled","push","decoupledArr","split","map","c","print","_len","arguments","messages","Array","_key","process","stdout","write","join","println","_len2","_key2","filter","Boolean","console","log","ln","count","repeat","indent","addIndentLn","message","concat","_len3","_key3"],"sourceRoot":"../../src","sources":["utils.ts"],"sourcesContent":["import assert from \"node:assert\";\nimport { z } from \"zod\";\n\n/**\n * @param name - Should start with `'--'`\n * @returns - The transformed name E.g. `--input-dir` -> `InputDir`\n */\nexport function transformArg(name: string): string {\n assert(name.startsWith(\"-\"), `[transformArg] Invalid arg name: ${name}`);\n name = name.startsWith(\"--\") ? name.substring(2) : name.substring(1);\n return name.replace(/-([a-z])/g, g => g[1].toUpperCase());\n}\n\n/** - Reverse of `transformArg`. E.g. `InputDir` -> `--input-dir` , `i` -> `-i` */\nexport function transformOptionToArg(name: string): string {\n name = name.replace(/^[A-Z]/g, g => g.toLowerCase()); // first letter always lower case\n if (name.length === 1) return `-${name}`;\n return `--${name.replace(/[A-Z]/g, g => \"-\" + g.toLowerCase())}`;\n}\n\n/** - Check if an arg string is a short arg. E.g. `-i` -> `true` */\nexport function isFlagArg(name: string): boolean {\n return /^-[a-z]$/.test(name);\n}\n\n/** - Check if an arg string is an options arg. E.g. `--input-dir` -> `true` , `-i` -> `true` */\nexport function isOptionArg(name: string | boolean): boolean {\n if (typeof name !== \"string\") return false;\n return isFlagArg(name) || name.startsWith(\"--\");\n}\n\n/**\n * - Transform option name to no name. E.g. `include` -> `noInclude`\n * - For short name like `-i` it will be ignored\n */\nexport function noName(name: string): string {\n if (name.length === 1) return name;\n return \"no\" + name.replace(/^[a-z]/, g => g.toUpperCase());\n}\n\n/** - Convert string to boolean. E.g. `\"true\"` -> `true` , `\"false\"` -> `false` */\nexport function stringToBoolean(str: string): boolean {\n if (str.toLowerCase() === \"true\") return true;\n if (str.toLowerCase() === \"false\") return false;\n throw new Error(`[stringToBoolean] Invalid boolean value: \"${str}\"; Expected \"true\" or \"false\"`);\n}\n\nexport function getOrdinalPlacement(index: number): string {\n if (index < 0) return \"\";\n\n const suffixes = [\"th\", \"st\", \"nd\", \"rd\"];\n const lastDigit = index % 10;\n const lastTwoDigits = index % 100;\n\n const suffix =\n lastDigit === 1 && lastTwoDigits !== 11\n ? suffixes[1]\n : lastDigit === 2 && lastTwoDigits !== 12\n ? suffixes[2]\n : lastDigit === 3 && lastTwoDigits !== 13\n ? suffixes[3]\n : suffixes[0];\n\n return `${index + 1}${suffix}`;\n}\n\n/** - Check if a schema is a boolean */\nexport function isBooleanSchema(schema: z.ZodTypeAny): boolean {\n let type = schema;\n while (type) {\n if (type instanceof z.ZodBoolean) {\n return true;\n }\n\n if (type instanceof z.ZodLiteral) {\n return type.value === true || type.value === false;\n }\n\n type = type._def.innerType;\n }\n\n return false;\n}\n\nexport function getDefaultValueFromSchema(schema: z.ZodTypeAny): unknown | undefined {\n let type = schema;\n while (type) {\n if (type instanceof z.ZodDefault) {\n const defaultValue = type._def.defaultValue();\n return defaultValue;\n }\n\n type = type._def.innerType;\n }\n\n return undefined;\n}\n\n/** - Decouple flags E.g. `-rf` -> `-r, -f` */\nexport function decoupleFlags(args: string[]): string[] {\n const flagsRe = /^-[a-z]{2,}$/i;\n\n const result = [];\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n const isCoupled = flagsRe.test(arg);\n\n if (!isCoupled) {\n result.push(arg);\n continue;\n }\n\n const decoupledArr = arg\n .substring(1)\n .split(\"\")\n .map(c => \"-\" + c);\n\n result.push(...decoupledArr);\n }\n\n return result;\n}\n\n/** Print */\nexport function print(...messages: string[]) {\n return process.stdout.write(messages.join(\" \"));\n}\n\n/** Print line */\nexport function println(...messages: string[]) {\n messages = messages.filter(Boolean);\n return console.log(...messages);\n}\n\n/** New line */\nexport function ln(count: number) {\n return \"\\n\".repeat(count);\n}\n\n/** Space */\nexport function indent(count: number) {\n return \" \".repeat(count);\n}\n\n/** Add indent before each new line */\nexport function addIndentLn(message: string, indent: string = \"\") {\n return message.replace(/\\n/g, `\\n${indent}`);\n}\n\n/** Concat strings */\nexport function concat(...messages: string[]) {\n messages = messages.filter(Boolean);\n return messages.join(\" \");\n}\n"],"mappings":"AAAA,MAAO,CAAAA,MAAM,KAAM,aAAa,CAChC,OAASC,CAAC,KAAQ,KAAK,CAMvB,MAAO,SAAS,CAAAC,YAAYA,CAACC,IAAY,CAAU,CACjDH,MAAM,CAACG,IAAI,CAACC,UAAU,CAAC,GAAG,CAAC,CAAE,oCAAoCD,IAAI,EAAE,CAAC,CACxEA,IAAI,CAAGA,IAAI,CAACC,UAAU,CAAC,IAAI,CAAC,CAAGD,IAAI,CAACE,SAAS,CAAC,CAAC,CAAC,CAAGF,IAAI,CAACE,SAAS,CAAC,CAAC,CAAC,CACpE,MAAO,CAAAF,IAAI,CAACG,OAAO,CAAC,WAAW,CAAEC,CAAC,EAAIA,CAAC,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC,CAAC,CAC3D,CAGA,MAAO,SAAS,CAAAC,oBAAoBA,CAACN,IAAY,CAAU,CACzDA,IAAI,CAAGA,IAAI,CAACG,OAAO,CAA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ApByC,QAAQ,KAAAC,KAAA,CAAAO,KAAA,EAAAC,KAAA,GAAAA,KAAA,CAAAD,KAAA,CAAAC,KAAA,IAART,QAAQ,CAAAS,KAAA,EAAAV,SAAA,CAAAU,KAAA,GACjCT,QAAQ,CAAGA,QAAQ,CAACU,MAAM,CAACC,OAAO,CAAC,CACnC,MAAO,CAAAC,OAAO,CAACC,GAAG,CAAC,GAAGb,QAAQ,CAAC,CACjC,CAGA,MAAO,SAAS,CAAAc,EAAEA,CAACC,KAAa,CAAE,CAChC,MAAO,IAAI,CAACC,MAAM,CAACD,KAAK,CAAC,CAC3B,CAGA,MAAO,SAAS,CAAAE,MAAMA,CAACF,KAAa,CAAE,CACpC,MAAO,GAAG,CAACC,MAAM,CAACD,KAAK,CAAC,CAC1B,CAGA,MAAO,SAAS,CAAAG,WAAWA,CAACC,OAAe,CAAuB,IAArB,CAAAF,MAAc,CAAAlB,SAAA,CAAAxC,MAAA,IAAAwC,SAAA,MAAAf,SAAA,CAAAe,SAAA,IAAG,EAAE,CAC9D,MAAO,CAAAoB,OAAO,CAACjE,OAAO,CAAC,KAAK,CAAE,KAAK+D,MAAM,EAAE,CAAC,CAC9C,CAGA,MAAO,SAAS,CAAAG,MAAMA,CAAA,CAAwB,SAAAC,KAAA,CAAAtB,SAAA,CAAAxC,MAAA,CAApByC,QAAQ,KAAAC,KAAA,CAAAoB,KAAA,EAAAC,KAAA,GAAAA,KAAA,CAAAD,KAAA,CAAAC,KAAA,IAARtB,QAAQ,CAAAsB,KAAA,EAAAvB,SAAA,CAAAuB,KAAA,GAChCtB,QAAQ,CAAGA,QAAQ,CAACU,MAAM,CAACC,OAAO,CAAC,CACnC,MAAO,CAAAX,QAAQ,CAACM,IAAI,CAAC,GAAG,CAAC,CAC3B","ignoreList":[]}
@@ -0,0 +1,9 @@
1
+ import type { Cli, PrintHelpOpt, Subcommand } from "./types.js";
2
+ declare function printCliHelp(params: [Cli, ...Subcommand[]], printOptions?: PrintHelpOpt): void;
3
+ declare function printSubcommandHelp(subcommand: Subcommand, printOptions?: PrintHelpOpt, cliName?: string): void;
4
+ export declare const help: {
5
+ printCliHelp: typeof printCliHelp;
6
+ printSubcommandHelp: typeof printSubcommandHelp;
7
+ };
8
+ export {};
9
+ //# sourceMappingURL=help.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"help.d.ts","sourceRoot":"","sources":["../../src/help.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAY,GAAG,EAAU,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AA0BlF,iBAAS,YAAY,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,UAAU,EAAE,CAAC,EAAE,YAAY,GAAE,YAAiB,QA4EpF;AAED,iBAAS,mBAAmB,CAAC,UAAU,EAAE,UAAU,EAAE,YAAY,GAAE,YAAiB,EAAE,OAAO,SAAK,QA+DjG;AAsKD,eAAO,MAAM,IAAI;;;CAGhB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { parse, safeParse } from "./parser.js";
2
+ import type { ActionFn, Cli, Prettify, Subcommand } from "./types.js";
3
+ declare function createSubcommand<const T extends Subcommand>(input: T & Subcommand): Prettify<T & ActionFn<T>>;
4
+ declare function createCli<const T extends Cli>(input: T & Cli): Prettify<T & ActionFn<T>>;
5
+ declare const printCliHelp: (params: [Cli, ...Subcommand[]], printOptions?: import("./types.js").PrintHelpOpt) => void, printSubcommandHelp: (subcommand: Subcommand, printOptions?: import("./types.js").PrintHelpOpt, cliName?: string) => void;
6
+ export { createCli, createSubcommand, parse, printCliHelp, printSubcommandHelp, safeParse };
7
+ export type * from "./types.js";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,UAAU,EAAqB,MAAM,YAAY,CAAC;AAEzF,iBAAS,gBAAgB,CAAC,KAAK,CAAC,CAAC,SAAS,UAAU,EAAE,KAAK,EAAE,CAAC,GAAG,UAAU,GAAG,QAAQ,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAItG;AAED,iBAAS,SAAS,CAAC,KAAK,CAAC,CAAC,SAAS,GAAG,EAAE,KAAK,EAAE,CAAC,GAAG,GAAG,GAAG,QAAQ,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAIjF;AAED,QAAA,MAAQ,YAAY,8FAAE,mBAAmB,sGAAS,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,SAAS,EAAE,CAAC;AAE5F,mBAAmB,YAAY,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { Cli, NoSubcommand, SafeParseResult, Subcommand, UnSafeParseResult } from "./types.js";
2
+ export declare function parse<T extends Subcommand[]>(argsv: string[], ...params: T): UnSafeParseResult<T>;
3
+ export declare function parse<T extends Subcommand[], U extends Cli>(argsv: string[], ...params: [U, ...T]): UnSafeParseResult<[...T, NoSubcommand & U]>;
4
+ export declare function safeParse<T extends Subcommand[]>(argsv: string[], ...params: T): SafeParseResult<T>;
5
+ export declare function safeParse<T extends Subcommand[], U extends Cli>(argsv: string[], ...params: [U, ...T]): SafeParseResult<[...T, NoSubcommand & U]>;
6
+ //# sourceMappingURL=parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EACV,GAAG,EACH,YAAY,EAGZ,eAAe,EACf,UAAU,EACV,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAEpB,wBAAgB,KAAK,CAAC,CAAC,SAAS,UAAU,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC;AACnG,wBAAgB,KAAK,CAAC,CAAC,SAAS,UAAU,EAAE,EAAE,CAAC,SAAS,GAAG,EACzD,KAAK,EAAE,MAAM,EAAE,EACf,GAAG,MAAM,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,GACnB,iBAAiB,CAAC,CAAC,GAAG,CAAC,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC;AA8O/C,wBAAgB,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;AACrG,wBAAgB,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,EAAE,CAAC,SAAS,GAAG,EAC7D,KAAK,EAAE,MAAM,EAAE,EACf,GAAG,MAAM,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,GACnB,eAAe,CAAC,CAAC,GAAG,CAAC,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,256 @@
1
+ import type { z } from "zod";
2
+ export type Subcommand = {
3
+ /**
4
+ * - The subcommand name, use `kebab-case`.
5
+ * - Make sure to not duplicate commands and aliases.
6
+ *
7
+ * @example
8
+ * name: "test";
9
+ * name: "run-app";
10
+ */
11
+ name: string;
12
+ /**
13
+ * - The action is executed with the result of the parsed arguments.
14
+ * - To get typescript types use `setAction` instead of this.
15
+ *
16
+ * @example
17
+ * const helpCommand = createSubcommand({ name: "help", options: [...] });
18
+ * helpCommand.setAction(res => console.log(res));
19
+ */
20
+ action?: (results?: any) => void;
21
+ /**
22
+ * - The description of the subcommand.
23
+ * - Used for generating the help message.
24
+ */
25
+ description?: string;
26
+ /** - Used for generating the help message. */
27
+ placeholder?: string;
28
+ /**
29
+ * - Provide an example to show to the user.
30
+ * - Used for generating the help message.
31
+ */
32
+ example?: string;
33
+ /**
34
+ * - The aliases of the subcommand.
35
+ * - Make sure to not duplicate aliases and commands.
36
+ */
37
+ aliases?: string[];
38
+ /**
39
+ * - Allows positional arguments for this subcommand.
40
+ * - Unlike `arguments`, which are strictly typed, positional arguments are untyped and represented as a string array of
41
+ * variable length.
42
+ * - When enabled and `arguments` are provided, `arguments` will be parsed first. Any remaining arguments will be
43
+ * considered positional arguments and added to the `positional` property in the result.
44
+ */
45
+ allowPositional?: boolean;
46
+ /**
47
+ * - The options of the command.
48
+ * - Those options are specific to this subcommand.
49
+ */
50
+ options?: [Option, ...Option[]];
51
+ /**
52
+ * - Specifies a list of strictly typed arguments.
53
+ * - The order is important; for example, the first argument will be validated against the first specified type.
54
+ * - It is recommended to not use optional arguments as the parser will fill the arguments by order and can't determine
55
+ * which arguments are optional.
56
+ */
57
+ arguments?: [Argument, ...Argument[]];
58
+ };
59
+ export type Cli = Prettify<Omit<Subcommand, "name"> & {
60
+ /** - The name of the CLI program. */
61
+ cliName: string;
62
+ /**
63
+ * - The usage of the CLI program.
64
+ * - Used for generating the help message.
65
+ */
66
+ usage?: string;
67
+ }>;
68
+ export type Option = {
69
+ /**
70
+ * - The name of the option, use `CamelCase`.
71
+ * - For example: the syntax for the option `rootPath` is `--root-path`.
72
+ */
73
+ name: string;
74
+ /**
75
+ * - The will be used to validate the user input.
76
+ *
77
+ * @example
78
+ * type: z.boolean().default(false);
79
+ * type: z.coerce.number(); // will be coerced to number by Zod
80
+ * type: z.preprocess(parseStringToArrFn, z.array(z.coerce.number())); // array of numbers
81
+ *
82
+ * @see https://zod.dev/?id=types
83
+ */
84
+ type: z.ZodTypeAny;
85
+ /**
86
+ * - The description of the option.
87
+ * - Used for generating the help message.
88
+ */
89
+ description?: string;
90
+ /** - Used for generating the help message. */
91
+ placeholder?: string;
92
+ /**
93
+ * - The example of using the option.
94
+ * - Used for generating the help message.
95
+ */
96
+ example?: string;
97
+ /**
98
+ * - The aliases of the option, use `CamelCase`.
99
+ * - Here you can specify short names or flags.
100
+ * - Make sure to not duplicate aliases.
101
+ */
102
+ aliases?: [string, ...string[]];
103
+ };
104
+ export type Argument = {
105
+ /** - The name of the argument. */
106
+ name: string;
107
+ /**
108
+ * - The will be used to validate the user input.
109
+ *
110
+ * @example
111
+ * type: z.boolean();
112
+ * type: z.coerce.number(); // will be coerced to number by Zod
113
+ * type: z.preprocess(ParseStringToArrFn, z.array(z.coerce.number())); // array of numbers
114
+ *
115
+ * @see https://zod.dev/?id=types
116
+ */
117
+ type: z.ZodTypeAny;
118
+ /**
119
+ * - The description of the argument.
120
+ * - Used for generating the help message.
121
+ */
122
+ description?: string;
123
+ /**
124
+ * - The example of using the argument.
125
+ * - Used for generating the help message.
126
+ */
127
+ example?: string;
128
+ };
129
+ export type ColorFnType = (...text: unknown[]) => string;
130
+ export type PrintHelpOpt = {
131
+ /**
132
+ * - **Optional** `boolean`
133
+ * - Whether to print colors or not.
134
+ * - Default: `true`
135
+ */
136
+ colors?: boolean;
137
+ /**
138
+ * - **Optional** `object`
139
+ * - The colors to use for the help message.
140
+ */
141
+ customColors?: {
142
+ title?: ColorFnType;
143
+ description?: ColorFnType;
144
+ default?: ColorFnType;
145
+ optional?: ColorFnType;
146
+ exampleTitle?: ColorFnType;
147
+ example?: ColorFnType;
148
+ command?: ColorFnType;
149
+ option?: ColorFnType;
150
+ argument?: ColorFnType;
151
+ placeholder?: ColorFnType;
152
+ punctuation?: ColorFnType;
153
+ };
154
+ };
155
+ export type _Info = {
156
+ /**
157
+ * - The raw argument as it was passed in
158
+ * - For options that have a default value and are not passed in, the raw argument will be `undefined`
159
+ */
160
+ rawArg?: string;
161
+ /**
162
+ * - The raw value of the argument as it was passed in
163
+ * - It will be empty string for `boolean` options. E.g. `--help` or `-h`
164
+ * - For options that have a default value and are not passed in, the raw value will be `undefined`
165
+ */
166
+ rawValue?: string;
167
+ /**
168
+ * - The source value of the argument:
169
+ * - `cli`: The argument was passed in by the user
170
+ * - `default`: The argument was not passed in and has a default value
171
+ */
172
+ source: "cli" | "default";
173
+ };
174
+ /**
175
+ * - Infer the options type from a subcommand.
176
+ *
177
+ * @example
178
+ * const subcommand = createSubcommand({ name: "build", options: [...] });
179
+ * type OptionsType = InferOptionsType<typeof subcommand>;
180
+ */
181
+ export type InferOptionsType<T extends Partial<Subcommand>> = T["options"] extends infer U extends Option[] ? ToOptional<{
182
+ [K in U[number]["name"]]: z.infer<Extract<U[number], {
183
+ name: K;
184
+ }>["type"]>;
185
+ }> : undefined;
186
+ /**
187
+ * - Infer the arguments type from a subcommand.
188
+ *
189
+ * @example
190
+ * const subcommand = createSubcommand({ name: "build", arguments: [...] });
191
+ * type ArgumentsType = InferArgumentsType<typeof subcommand>;
192
+ */
193
+ export type InferArgumentsType<T extends Partial<Subcommand>> = T["arguments"] extends infer U extends Argument[] ? {
194
+ [K in keyof U]: U[K] extends {
195
+ type: z.ZodTypeAny;
196
+ } ? z.infer<U[K]["type"]> : never;
197
+ } : undefined;
198
+ /** `{ some props } & { other props }` => `{ some props, other props }` */
199
+ export type Prettify<T> = {
200
+ [K in keyof T]: T[K];
201
+ } & {};
202
+ /** Allow string type for literal union and get auto completion */
203
+ export type LiteralUnion<T extends string> = T | (string & {});
204
+ /** Extract the undefined properties from an object */
205
+ type UndefinedProperties<T> = {
206
+ [P in keyof T]-?: undefined extends T[P] ? P : never;
207
+ }[keyof T];
208
+ /** Make undefined properties optional? */
209
+ type ToOptional<T> = Prettify<Partial<Pick<T, UndefinedProperties<T>>> & Pick<T, Exclude<keyof T, UndefinedProperties<T>>>>;
210
+ export type OptionsArr2RecordType<T extends Option[] | undefined> = T extends Option[] ? ToOptional<{
211
+ [K in T[number]["name"]]: z.infer<Extract<T[number], {
212
+ name: K;
213
+ }>["type"]>;
214
+ }> : object;
215
+ export type ArgumentsArr2ArrType<T extends Argument[] | undefined> = T extends Argument[] ? {
216
+ arguments: {
217
+ [K in keyof T]: T[K] extends {
218
+ type: z.ZodTypeAny;
219
+ } ? z.infer<T[K]["type"]> : never;
220
+ };
221
+ } : object;
222
+ export type Positional<S extends Partial<Subcommand>> = S["allowPositional"] extends true ? {
223
+ positional: string[];
224
+ } : object;
225
+ export type Info<T extends Option[] | undefined> = T extends Option[] ? {
226
+ _info: ToOptional<{
227
+ [K in T[number]["name"]]: Extract<T[number], {
228
+ name: K;
229
+ }> extends infer U extends Option ? undefined extends z.infer<U["type"]> ? undefined | Prettify<_Info & U> : Prettify<_Info & U> : never;
230
+ }>;
231
+ } : object;
232
+ export type NoSubcommand = {
233
+ name: undefined;
234
+ };
235
+ export type ParseResult<S extends Partial<Subcommand>[]> = {
236
+ [K in keyof S]: Prettify<{
237
+ subcommand: S[K]["name"];
238
+ } & Positional<S[K]> & Info<S[K]["options"]> & OptionsArr2RecordType<S[K]["options"]> & ArgumentsArr2ArrType<S[K]["arguments"]>>;
239
+ }[number];
240
+ export type PrintMethods<N extends Subcommand["name"] | undefined> = {
241
+ printCliHelp: (options?: PrintHelpOpt) => void;
242
+ printSubcommandHelp: (subcommand: LiteralUnion<NonNullable<N>>, options?: PrintHelpOpt) => void;
243
+ };
244
+ export type UnSafeParseResult<S extends Partial<Subcommand>[]> = Prettify<ParseResult<S> & PrintMethods<S[number]["name"]>>;
245
+ export type SafeParseResult<S extends Partial<Subcommand>[]> = Prettify<({
246
+ success: false;
247
+ error: Error;
248
+ } | {
249
+ success: true;
250
+ data: ParseResult<S>;
251
+ }) & PrintMethods<S[number]["name"]>>;
252
+ export type ActionFn<T extends Subcommand | Cli> = {
253
+ setAction: (actions: (res: UnSafeParseResult<[T]>) => void) => void;
254
+ };
255
+ export {};
256
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,MAAM,MAAM,UAAU,GAAG;IACvB;;;;;;;OAOG;IACH,IAAI,EAAE,M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C,MAAM,CAAC,CAAC,CACjD,CAAC;AAEF,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,OAAO,CAAC,UAAU,CAAC,EAAE,IAAI,QAAQ,CACrE,CAAC;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAC/G,CAAC;AAEF,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,UAAU,GAAG,GAAG,IAAI;IACjD,SAAS,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,KAAK,IAAI,CAAC;CACrE,CAAC"}
@@ -0,0 +1,38 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * @param name - Should start with `'--'`
4
+ * @returns - The transformed name E.g. `--input-dir` -> `InputDir`
5
+ */
6
+ export declare function transformArg(name: string): string;
7
+ /** - Reverse of `transformArg`. E.g. `InputDir` -> `--input-dir` , `i` -> `-i` */
8
+ export declare function transformOptionToArg(name: string): string;
9
+ /** - Check if an arg string is a short arg. E.g. `-i` -> `true` */
10
+ export declare function isFlagArg(name: string): boolean;
11
+ /** - Check if an arg string is an options arg. E.g. `--input-dir` -> `true` , `-i` -> `true` */
12
+ export declare function isOptionArg(name: string | boolean): boolean;
13
+ /**
14
+ * - Transform option name to no name. E.g. `include` -> `noInclude`
15
+ * - For short name like `-i` it will be ignored
16
+ */
17
+ export declare function noName(name: string): string;
18
+ /** - Convert string to boolean. E.g. `"true"` -> `true` , `"false"` -> `false` */
19
+ export declare function stringToBoolean(str: string): boolean;
20
+ export declare function getOrdinalPlacement(index: number): string;
21
+ /** - Check if a schema is a boolean */
22
+ export declare function isBooleanSchema(schema: z.ZodTypeAny): boolean;
23
+ export declare function getDefaultValueFromSchema(schema: z.ZodTypeAny): unknown | undefined;
24
+ /** - Decouple flags E.g. `-rf` -> `-r, -f` */
25
+ export declare function decoupleFlags(args: string[]): string[];
26
+ /** Print */
27
+ export declare function print(...messages: string[]): boolean;
28
+ /** Print line */
29
+ export declare function println(...messages: string[]): void;
30
+ /** New line */
31
+ export declare function ln(count: number): string;
32
+ /** Space */
33
+ export declare function indent(count: number): string;
34
+ /** Add indent before each new line */
35
+ export declare function addIndentLn(message: string, indent?: string): string;
36
+ /** Concat strings */
37
+ export declare function concat(...messages: string[]): string;
38
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAIjD;AAED,kFAAkF;AAClF,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAIzD;AAED,mEAAmE;AACnE,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED,gGAAgG;AAChG,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,CAG3D;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG3C;AAED,kFAAkF;AAClF,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAIpD;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAiBzD;AAED,uCAAuC;AACvC,wBAAgB,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,GAAG,OAAO,CAe7D;AAED,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,GAAG,OAAO,GAAG,SAAS,CAYnF;AAED,8CAA8C;AAC9C,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAsBtD;AAED,YAAY;AACZ,wBAAgB,KAAK,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,WAE1C;AAED,iBAAiB;AACjB,wBAAgB,OAAO,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,QAG5C;AAED,eAAe;AACf,wBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,UAE/B;AAED,YAAY;AACZ,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,UAEnC;AAED,sCAAsC;AACtC,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,GAAE,MAAW,UAE/D;AAED,qBAAqB;AACrB,wBAAgB,MAAM,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,UAG3C"}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "zod-args-parser",
3
+ "version": "1.0.0",
4
+ "description": "A strictly typed command-line arguments parser powered by Zod.",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "tsx watch src/test.ts",
8
+ "build": "node scripts/build.mjs",
9
+ "test": "eslint src/** --fix && tsc --noEmit && tsx test/test.ts",
10
+ "prepare": "npm run test && npm run build"
11
+ },
12
+ "main": "./lib/commonjs/index.js",
13
+ "module": "./lib/module/index.js",
14
+ "types": "./lib/typescript/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "import": "./lib/module/index.js",
18
+ "require": "./lib/commonjs/index.js",
19
+ "default": "./lib/module/index",
20
+ "types": "./lib/typescript/index.d.ts"
21
+ }
22
+ },
23
+ "files": [
24
+ "lib",
25
+ "src"
26
+ ],
27
+ "dependencies": {
28
+ "chalk": "^5.3.0",
29
+ "zod": "^3.23.8",
30
+ "zod-args-parser": "file:zod-args-parser-1.0.0.tgz"
31
+ },
32
+ "devDependencies": {
33
+ "@babel/core": "^7.26.0",
34
+ "@babel/preset-env": "^7.26.0",
35
+ "@babel/preset-typescript": "^7.26.0",
36
+ "@eslint/js": "^9.14.0",
37
+ "@types/babel__core": "^7.20.5",
38
+ "@types/node": "^22.9.0",
39
+ "eslint": "^9.14.0",
40
+ "eslint-config-prettier": "^9.1.0",
41
+ "eslint-plugin-prettier": "^5.2.1",
42
+ "glob": "^11.0.0",
43
+ "globals": "^15.12.0",
44
+ "prettier": "^3.3.3",
45
+ "prettier-plugin-jsdoc": "^1.3.0",
46
+ "tsx": "^4.19.2",
47
+ "typescript": "^5.6.3",
48
+ "typescript-eslint": "^8.14.0"
49
+ }
50
+ }