zod-args-parser 1.0.10 → 1.0.12

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.
@@ -68,7 +68,7 @@ Register-ArgumentCompleter -CommandName '${cli.cliName}' -ParameterName 'argumen
68
68
  }`;}function generateZshAutocompleteScript(...params){const[cli,...subcommands]=params;const genArguments=options=>{return options?.map(option=>`'${(0,_utils.transformOptionToArg)(option.name)}[${option.description??""}]'`).join(" \\\n ");};const genSubCommand=subcommand=>{const options=subcommand.options;if(!options||options.length===0)return"";return`${subcommand.name})
69
69
  _arguments \\
70
70
  ${genArguments(options)} \\
71
- '1: :_files' \\
71
+ '*: :_files' \\
72
72
  && ret=0
73
73
  ;;`;};return`
74
74
  _${cli.cliName}_autocomplete() {
@@ -84,7 +84,9 @@ _${cli.cliName}_autocomplete() {
84
84
  case "$words[1]" in
85
85
  ${subcommands.map(genSubCommand).filter(Boolean).join("\n ")}
86
86
  *)
87
- _message "No options available for this command"
87
+ _arguments \
88
+ '*: :_files' \
89
+ && ret=0
88
90
  ;;
89
91
  esac
90
92
  ;;
@@ -1 +1 @@
1
- {"version":3,"names":["_utils","require","generateBashAutocompleteScript","params","cli","subcommands","mappedCommands","reduce","acc","subcommand","name","options","map","option","transformOptionToArg","aliases","switchCase","key","Object","entries","length","join","cliName","keys","generatePowerShellAutocompleteScript","subcommandsStr","cliOptionsStr","optionsStr","forEach","a","functionInfo","description","example","generateZshAutocompleteScript","genArguments","genSubCommand","filter","Boolean"],"sourceRoot":"../../src","sources":["autocomplete.ts"],"sourcesContent":["import { transformOptionToArg } from \"./utils.js\";\n\nimport type { Cli, Option, Subcommand } from \"./types.js\";\n\n/**\n * - Generate bash autocomplete script for your CLI\n * - The generated script should be added to your `.bash_profile` or `.bashrc` file:\n *\n * - Run: `nano $HOME/.bash_profile` or `nano $HOME/.bashrc`\n * - Add the following line: `source <generated script path>`\n * - Save and reopen bash to take effect\n */\nexport function generateBashAutocompleteScript(...params: [Cli, ...Subcommand[]]): string {\n const [cli, ...subcommands] = params;\n\n type MappedCommands = Record<string, { options: string[]; aliases: string[] }>;\n\n const mappedCommands = subcommands.reduce((acc: MappedCommands, subcommand) => {\n acc[subcommand.name] = {\n options: subcommand.options?.map(option => transformOptionToArg(option.name)) ?? [],\n aliases: subcommand.aliases ?? [],\n };\n return acc;\n }, {});\n\n let switchCase = \"\";\n for (const [key, { options, aliases }] of Object.entries(mappedCommands)) {\n switchCase += ` ${key}${aliases.length ? \"|\" : \"\"}${aliases.join(\"|\")})\\n`;\n switchCase += ` opts=\"${options.join(\" \")}\"\\n`;\n switchCase += \" ;;\\n\";\n }\n\n if (cli.options?.length) {\n switchCase += ` \"-\"*)\\n`;\n switchCase += ` opts=\"${cli.options.map(option => transformOptionToArg(option.name)).join(\" \")}\"\\n`;\n switchCase += \" ;;\\n\";\n }\n\n return `_${cli.cliName}_autocomplete() {\n local cur prev commands opts subcommand used_opts filtered_opts\n\n cur=\"\\${COMP_WORDS[COMP_CWORD]}\"\n prev=\"\\${COMP_WORDS[COMP_CWORD-1]}\"\n subcommand=\"\\${COMP_WORDS[1]}\"\n\n commands=\"${Object.keys(mappedCommands).join(\" \")}\"\n\n case \"$subcommand\" in\n${switchCase}\n esac\n\n used_opts=\"\"\n if [[ \" \\${commands[@]} \" =~ \" $subcommand \" ]]; then\n for word in \"\\${COMP_WORDS[@]:2}\"; do\n if [[ \"$word\" =~ ^- ]]; then\n used_opts+=\" $word\"\n fi\n done\n fi\n\n if [[ -n \"$opts\" ]]; then\n filtered_opts=\"\"\n for opt in $opts; do\n if [[ ! \" $used_opts \" =~ \" $opt \" ]]; then\n filtered_opts+=\"$opt \"\n fi\n done\n COMPREPLY=( $(compgen -W \"$filtered_opts\" -- \"$cur\") )\n return\n fi\n\n if [[ \"\\${COMP_CWORD}\" -eq 1 ]]; then\n COMPREPLY=( $(compgen -W \"$commands\" -- \"$cur\") )\n fi\n}\n\ncomplete -F _${cli.cliName}_autocomplete ${cli.cliName}\n`;\n}\n\n/**\n * - Generates a PowerShell autocomplete script for your CLI.\n * - The script assumes that your CLI is available as a `.ps1` file in the environment variable. For example:\n * `cliName.ps1`.\n * - This should return a path to your script: `(Get-Command <cliName>.ps1).Source`\n * - The generated script should be added to your `profile.ps1` file:\n *\n * - Run: `notepad $profile`\n * - Add the following line: `. \"<generated script path>\"`\n * - Save and reopen powershell to take effect\n */\nexport function generatePowerShellAutocompleteScript(...params: [Cli, ...Subcommand[]]): string {\n const [cli, ...subcommands] = params;\n\n type MappedCommands = Record<string, { options: string[]; aliases: string[] }>;\n\n const mappedCommands = subcommands.reduce((acc: MappedCommands, subcommand) => {\n acc[subcommand.name] = {\n options: subcommand.options?.map(option => transformOptionToArg(option.name)) ?? [],\n aliases: subcommand.aliases ?? [],\n };\n return acc;\n }, {});\n\n const subcommandsStr = Object.keys(mappedCommands)\n .map(key => `'${key}'`)\n .join(\", \");\n const cliOptionsStr = cli.options?.map(option => `'${transformOptionToArg(option.name)}'`).join(\", \") || \"\";\n\n let switchCase = \"switch ($subcommand) {\\n\";\n for (const [key, { options, aliases }] of Object.entries(mappedCommands)) {\n const optionsStr = options.map(option => `'${option}'`).join(\", \");\n switchCase += ` '${key}' { @(${optionsStr}) }\\n`;\n aliases.forEach(a => (switchCase += ` '${a}' { @(${optionsStr}) }\\n`));\n }\n switchCase += ` default { @(${cliOptionsStr}) }\\n }`;\n\n let functionInfo = \"\";\n if (cli.description) {\n functionInfo = `<#\\n.DESCRIPTION\\n${cli.description}\\n${cli.example ? `\\n.EXAMPLE\\n${cli.example}` : \"\"}\\n#>`;\n }\n\n return `${functionInfo}\nfunction ${cli.cliName} {\n param(\n [Parameter(Position = 0, Mandatory = $false)]\n [string]$subcommand,\n [Parameter(Position = 1, ValueFromRemainingArguments = $true)]\n [string[]]$arguments\n )\n $scriptPath = (Get-Command '${cli.cliName}.ps1').Source\n if ($scriptPath) {\n $argumentList = @($subcommand) + ($arguments | Where-Object { $_ -notin '--', '--%' }) | Where-Object { $_ -ne '' }\n & $scriptPath @argumentList\n return\n }\n Write-Error \"Could not find '${cli.cliName}.ps1' script\"\n}\n\nRegister-ArgumentCompleter -CommandName '${cli.cliName}' -ParameterName 'subcommand' -ScriptBlock {\n param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)\n $subcommands = @(${subcommandsStr}${subcommandsStr && cliOptionsStr ? \", \" : \"\"}${cliOptionsStr})\n $subcommands | Where-Object { $_ -like \"$wordToComplete*\" }\n}\n\nRegister-ArgumentCompleter -CommandName '${cli.cliName}' -ParameterName 'arguments' -ScriptBlock {\n param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)\n $subcommand = $commandAst.CommandElements[1].Value\n $arguments = ${switchCase}\n $arguments | Where-Object { $_ -like \"$wordToComplete*\" }\n}`;\n}\n\n/**\n * - Generates a ZSH autocomplete script for your CLI.\n * - The generated script should be added to your `~/.zshrc` or `~/.zsh_profile` file:\n *\n * - Run: `nano $HOME/.zshrc` or `nano $HOME/.zsh_profile`\n * - Add the following line: `source <generated script path>`\n * - Save and reopen zsh to take effect\n */\nexport function generateZshAutocompleteScript(...params: [Cli, ...Subcommand[]]): string {\n const [cli, ...subcommands] = params;\n\n const genArguments = (options: Option[]) => {\n return options\n ?.map(option => `'${transformOptionToArg(option.name)}[${option.description ?? \"\"}]'`)\n .join(\" \\\\\\n \");\n };\n\n const genSubCommand = (subcommand: Subcommand) => {\n const options = subcommand.options;\n if (!options || options.length === 0) return \"\";\n return `${subcommand.name})\n _arguments \\\\\n ${genArguments(options)} \\\\\n '1: :_files' \\\\\n && ret=0\n ;;`;\n };\n\n return `\n_${cli.cliName}_autocomplete() {\n local ret=1\n\n _arguments -C \\\\\n '1: :_${cli.cliName}_commands' \\\\\n '*:: :->subcmds' \\\\\n && ret=0\n\n case $state in\n subcmds)\n case \"$words[1]\" in\n ${subcommands.map(genSubCommand).filter(Boolean).join(\"\\n \")}\n *)\n _message \"No options available for this command\"\n ;;\n esac\n ;;\n esac\n\n return $ret\n}\n \n_${cli.cliName}_commands() {\n local -a commands=(\n ${subcommands.map(subcommand => `\"${subcommand.name}:${subcommand.description ?? \"\"}\"`).join(\"\\n \")}\n )\n\n _describe -t subcommands 'subcommand' commands\n}\n\ncompdef _${cli.cliName}_autocomplete ${cli.cliName}\n`;\n}\n"],"mappings":"kSAAA,IAAAA,MAAA,CAAAC,OAAA,eAYO,QAAS,CAAAC,8BAA8BA,CAAC,GAAGC,MAA8B,CAAU,CACxF,KAAM,CAACC,GAAG,CAAE,GAAGC,WAAW,CAAC,CAAGF,MAAM,CAIpC,KAAM,CAAAG,cAAc,CAAGD,WAAW,CAACE,MAAM,CAAC,CAACC,GAAmB,CAAEC,UAAU,GAAK,CAC7ED,GAAG,CAACC,UAAU,CAACC,IAAI,CAAC,CAAG,CACrBC,OAAO,CAAEF,UAAU,CAACE,OAAO,EAAEC,GAAG,CAACC,MAAM,EAAI,GAAAC,2BAAoB,EAACD,MAAM,CAACH,IAAI,CAAC,CAAC,EAAI,EAAE,CACnFK,OAAO,CAAEN,UAAU,CAACM,OAAO,EAAI,EACjC,CAAC,CACD,MAAO,CAAAP,GAAG,CACZ,CAAC,CAAE,CAAC,CAAC,CAAC,CAEN,GAAI,CAAAQ,UAAU,CAAG,EAAE,CACnB,IAAK,KAAM,CAACC,GAAG,CAAE,CAAEN,OAAO,CAAEI,OAAQ,CAAC,CAAC,EAAI,CAAAG,MAAM,CAACC,OAAO,CAACb,cAAc,CAAC,CAAE,CACxEU,UAAU,EAAI,OAAOC,GAAG,GAAGF,OAAO,CAACK,MAAM,CAAG,GAAG,CAAG,EAAE,GAAGL,OAAO,CAACM,IAAI,CAAC,GAAG,CAAC,KAAK,CAC7EL,UAAU,EAAI,eAAeL,OAAO,CAACU,IAAI,CAAC,GAAG,CAAC,KAAK,CACnDL,UAAU,EAAI,YAAY,CAC5B,CAEA,GAAIZ,GAAG,CAACO,OAAO,EAAES,MAAM,CAAE,CACvBJ,UAAU,EAAI,aAA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,CAAC,CAACV,IAAI,CAAC,QAAQ,CAAC;AAC1G;AACA;AACA;AACA;AACA;AACA,WAAWjB,GAAG,CAACkB,OAAO,iBAAiBlB,GAAG,CAACkB,OAAO;AAClD,CAAC,CACD","ignoreList":[]}
1
+ {"version":3,"names":["_utils","require","generateBashAutocompleteScript","params","cli","subcommands","mappedCommands","reduce","acc","subcommand","name","options","map","option","transformOptionToArg","aliases","switchCase","key","Object","entries","length","join","cliName","keys","generatePowerShellAutocompleteScript","subcommandsStr","cliOptionsStr","optionsStr","forEach","a","functionInfo","description","example","generateZshAutocompleteScript","genArguments","genSubCommand","filter","Boolean"],"sourceRoot":"../../src","sources":["autocomplete.ts"],"sourcesContent":["import { transformOptionToArg } from \"./utils.js\";\n\nimport type { Cli, Option, Subcommand } from \"./types.js\";\n\n/**\n * - Generate bash autocomplete script for your CLI\n * - The generated script should be added to your `.bash_profile` or `.bashrc` file:\n *\n * - Run: `nano $HOME/.bash_profile` or `nano $HOME/.bashrc`\n * - Add the following line: `source <generated script path>`\n * - Save and reopen bash to take effect\n */\nexport function generateBashAutocompleteScript(...params: [Cli, ...Subcommand[]]): string {\n const [cli, ...subcommands] = params;\n\n type MappedCommands = Record<string, { options: string[]; aliases: string[] }>;\n\n const mappedCommands = subcommands.reduce((acc: MappedCommands, subcommand) => {\n acc[subcommand.name] = {\n options: subcommand.options?.map(option => transformOptionToArg(option.name)) ?? [],\n aliases: subcommand.aliases ?? [],\n };\n return acc;\n }, {});\n\n let switchCase = \"\";\n for (const [key, { options, aliases }] of Object.entries(mappedCommands)) {\n switchCase += ` ${key}${aliases.length ? \"|\" : \"\"}${aliases.join(\"|\")})\\n`;\n switchCase += ` opts=\"${options.join(\" \")}\"\\n`;\n switchCase += \" ;;\\n\";\n }\n\n if (cli.options?.length) {\n switchCase += ` \"-\"*)\\n`;\n switchCase += ` opts=\"${cli.options.map(option => transformOptionToArg(option.name)).join(\" \")}\"\\n`;\n switchCase += \" ;;\\n\";\n }\n\n return `_${cli.cliName}_autocomplete() {\n local cur prev commands opts subcommand used_opts filtered_opts\n\n cur=\"\\${COMP_WORDS[COMP_CWORD]}\"\n prev=\"\\${COMP_WORDS[COMP_CWORD-1]}\"\n subcommand=\"\\${COMP_WORDS[1]}\"\n\n commands=\"${Object.keys(mappedCommands).join(\" \")}\"\n\n case \"$subcommand\" in\n${switchCase}\n esac\n\n used_opts=\"\"\n if [[ \" \\${commands[@]} \" =~ \" $subcommand \" ]]; then\n for word in \"\\${COMP_WORDS[@]:2}\"; do\n if [[ \"$word\" =~ ^- ]]; then\n used_opts+=\" $word\"\n fi\n done\n fi\n\n if [[ -n \"$opts\" ]]; then\n filtered_opts=\"\"\n for opt in $opts; do\n if [[ ! \" $used_opts \" =~ \" $opt \" ]]; then\n filtered_opts+=\"$opt \"\n fi\n done\n COMPREPLY=( $(compgen -W \"$filtered_opts\" -- \"$cur\") )\n return\n fi\n\n if [[ \"\\${COMP_CWORD}\" -eq 1 ]]; then\n COMPREPLY=( $(compgen -W \"$commands\" -- \"$cur\") )\n fi\n}\n\ncomplete -F _${cli.cliName}_autocomplete ${cli.cliName}\n`;\n}\n\n/**\n * - Generates a PowerShell autocomplete script for your CLI.\n * - The script assumes that your CLI is available as a `.ps1` file in the environment variable. For example:\n * `cliName.ps1`.\n * - This should return a path to your script: `(Get-Command <cliName>.ps1).Source`\n * - The generated script should be added to your `profile.ps1` file:\n *\n * - Run: `notepad $profile`\n * - Add the following line: `. \"<generated script path>\"`\n * - Save and reopen powershell to take effect\n */\nexport function generatePowerShellAutocompleteScript(...params: [Cli, ...Subcommand[]]): string {\n const [cli, ...subcommands] = params;\n\n type MappedCommands = Record<string, { options: string[]; aliases: string[] }>;\n\n const mappedCommands = subcommands.reduce((acc: MappedCommands, subcommand) => {\n acc[subcommand.name] = {\n options: subcommand.options?.map(option => transformOptionToArg(option.name)) ?? [],\n aliases: subcommand.aliases ?? [],\n };\n return acc;\n }, {});\n\n const subcommandsStr = Object.keys(mappedCommands)\n .map(key => `'${key}'`)\n .join(\", \");\n const cliOptionsStr = cli.options?.map(option => `'${transformOptionToArg(option.name)}'`).join(\", \") || \"\";\n\n let switchCase = \"switch ($subcommand) {\\n\";\n for (const [key, { options, aliases }] of Object.entries(mappedCommands)) {\n const optionsStr = options.map(option => `'${option}'`).join(\", \");\n switchCase += ` '${key}' { @(${optionsStr}) }\\n`;\n aliases.forEach(a => (switchCase += ` '${a}' { @(${optionsStr}) }\\n`));\n }\n switchCase += ` default { @(${cliOptionsStr}) }\\n }`;\n\n let functionInfo = \"\";\n if (cli.description) {\n functionInfo = `<#\\n.DESCRIPTION\\n${cli.description}\\n${cli.example ? `\\n.EXAMPLE\\n${cli.example}` : \"\"}\\n#>`;\n }\n\n return `${functionInfo}\nfunction ${cli.cliName} {\n param(\n [Parameter(Position = 0, Mandatory = $false)]\n [string]$subcommand,\n [Parameter(Position = 1, ValueFromRemainingArguments = $true)]\n [string[]]$arguments\n )\n $scriptPath = (Get-Command '${cli.cliName}.ps1').Source\n if ($scriptPath) {\n $argumentList = @($subcommand) + ($arguments | Where-Object { $_ -notin '--', '--%' }) | Where-Object { $_ -ne '' }\n & $scriptPath @argumentList\n return\n }\n Write-Error \"Could not find '${cli.cliName}.ps1' script\"\n}\n\nRegister-ArgumentCompleter -CommandName '${cli.cliName}' -ParameterName 'subcommand' -ScriptBlock {\n param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)\n $subcommands = @(${subcommandsStr}${subcommandsStr && cliOptionsStr ? \", \" : \"\"}${cliOptionsStr})\n $subcommands | Where-Object { $_ -like \"$wordToComplete*\" }\n}\n\nRegister-ArgumentCompleter -CommandName '${cli.cliName}' -ParameterName 'arguments' -ScriptBlock {\n param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)\n $subcommand = $commandAst.CommandElements[1].Value\n $arguments = ${switchCase}\n $arguments | Where-Object { $_ -like \"$wordToComplete*\" }\n}`;\n}\n\n/**\n * - Generates a ZSH autocomplete script for your CLI.\n * - The generated script should be added to your `~/.zshrc` or `~/.zsh_profile` file:\n *\n * - Run: `nano $HOME/.zshrc` or `nano $HOME/.zsh_profile`\n * - Add the following line: `source <generated script path>`\n * - Save and reopen zsh to take effect\n */\nexport function generateZshAutocompleteScript(...params: [Cli, ...Subcommand[]]): string {\n const [cli, ...subcommands] = params;\n\n const genArguments = (options: Option[]) => {\n return options\n ?.map(option => `'${transformOptionToArg(option.name)}[${option.description ?? \"\"}]'`)\n .join(\" \\\\\\n \");\n };\n\n const genSubCommand = (subcommand: Subcommand) => {\n const options = subcommand.options;\n if (!options || options.length === 0) return \"\";\n return `${subcommand.name})\n _arguments \\\\\n ${genArguments(options)} \\\\\n '*: :_files' \\\\\n && ret=0\n ;;`;\n };\n\n return `\n_${cli.cliName}_autocomplete() {\n local ret=1\n\n _arguments -C \\\\\n '1: :_${cli.cliName}_commands' \\\\\n '*:: :->subcmds' \\\\\n && ret=0\n\n case $state in\n subcmds)\n case \"$words[1]\" in\n ${subcommands.map(genSubCommand).filter(Boolean).join(\"\\n \")}\n *)\n _arguments \\\n '*: :_files' \\\n && ret=0\n ;;\n esac\n ;;\n esac\n\n return $ret\n}\n \n_${cli.cliName}_commands() {\n local -a commands=(\n ${subcommands.map(subcommand => `\"${subcommand.name}:${subcommand.description ?? \"\"}\"`).join(\"\\n \")}\n )\n\n _describe -t subcommands 'subcommand' commands\n}\n\ncompdef _${cli.cliName}_autocomplete ${cli.cliName}\n`;\n}\n"],"mappings":"kSAAA,IAAAA,MAAA,CAAAC,OAAA,eAYO,QAAS,CAAAC,8BAA8BA,CAAC,GAAGC,MAA8B,CAAU,CACxF,KAAM,CAACC,GAAG,CAAE,GAAGC,WAAW,CAAC,CAAGF,MAAM,CAIpC,KAAM,CAAAG,cAAc,CAAGD,WAAW,CAACE,MAAM,CAAC,CAACC,GAAmB,CAAEC,UAAU,GAAK,CAC7ED,GAAG,CAACC,UAAU,CAACC,IAAI,CAAC,CAAG,CACrBC,OAAO,CAAEF,UAAU,CA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1B,UAAsB,EAAK,CAChD,KAAM,CAAAE,OAAO,CAAGF,UAAU,CAACE,OAAO,CAClC,GAAI,CAACA,OAAO,EAAIA,OAAO,CAACS,MAAM,GAAK,CAAC,CAAE,MAAO,EAAE,CAC/C,MAAO,GAAGX,UAAU,CAACC,IAAI;AAC7B;AACA,cAAcwB,YAAY,CAACvB,OAAO,CAAC;AACnC;AACA;AACA,aAAa,CACX,CAAC,CAED,MAAO;AACT,GAAGP,GAAG,CAACkB,OAAO;AACd;AACA;AACA;AACA,YAAYlB,GAAG,CAACkB,OAAO;AACvB;AACA;AACA;AACA;AACA;AACA;AACA,UAAUjB,WAAW,CAACO,GAAG,CAACuB,aAAa,CAAC,CAACC,MAAM,CAACC,OAAO,CAAC,CAAChB,IAAI,CAAC,YAAY,CAAC;AAC3E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAGjB,GAAG,CAACkB,OAAO;AACd;AACA,MAAMjB,WAAW,CAACO,GAAG,CAACH,UAAU,EAAI,IAAIA,UAAU,CAACC,IAAI,IAAID,UAAU,CAACsB,WAAW,EAAI,EAAE,GAAG,CAAC,CAACV,IAAI,CAAC,QAAQ,CAAC;AAC1G;AACA;AACA;AACA;AACA;AACA,WAAWjB,GAAG,CAACkB,OAAO,iBAAiBlB,GAAG,CAACkB,OAAO;AAClD,CAAC,CACD","ignoreList":[]}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.createArguments=createArguments;exports.createCli=createCli;exports.createOptions=createOptions;exports.createSubcommand=createSubcommand;Object.defineProperty(exports,"generateBashAutocompleteScript",{enumerable:true,get:function(){return _autocomplete.generateBashAutocompleteScript;}});Object.defineProperty(exports,"generatePowerShellAutocompleteScript",{enumerable:true,get:function(){return _autocomplete.generatePowerShellAutocompleteScript;}});Object.defineProperty(exports,"parse",{enumerable:true,get:function(){return _parser.parse;}});exports.printSubcommandHelp=exports.printCliHelp=void 0;Object.defineProperty(exports,"safeParse",{enumerable:true,get:function(){return _parser.safeParse;}});var _help=require("./help.js");var _parser=require("./parser.js");var _autocomplete=require("./autocomplete.js");function createCli(input){const setAction=action=>{input.action=action;};return Object.assign(input,{setAction});}function createSubcommand(input){const setAction=action=>{input.action=action;};return Object.assign(input,{setAction});}function createOptions(options){return options;}function createArguments(args){return args;}const{printCliHelp,printSubcommandHelp}=_help.help;exports.printSubcommandHelp=printSubcommandHelp;exports.printCliHelp=printCliHelp;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.createArguments=createArguments;exports.createCli=createCli;exports.createOptions=createOptions;exports.createSubcommand=createSubcommand;Object.defineProperty(exports,"generateBashAutocompleteScript",{enumerable:true,get:function(){return _autocomplete.generateBashAutocompleteScript;}});Object.defineProperty(exports,"generatePowerShellAutocompleteScript",{enumerable:true,get:function(){return _autocomplete.generatePowerShellAutocompleteScript;}});Object.defineProperty(exports,"generateZshAutocompleteScript",{enumerable:true,get:function(){return _autocomplete.generateZshAutocompleteScript;}});Object.defineProperty(exports,"parse",{enumerable:true,get:function(){return _parser.parse;}});exports.printSubcommandHelp=exports.printCliHelp=void 0;Object.defineProperty(exports,"safeParse",{enumerable:true,get:function(){return _parser.safeParse;}});var _help=require("./help.js");var _parser=require("./parser.js");var _autocomplete=require("./autocomplete.js");function createCli(input){const setAction=action=>{input.action=action;};return Object.assign(input,{setAction});}function createSubcommand(input){const setAction=action=>{input.action=action;};return Object.assign(input,{setAction});}function createOptions(options){return options;}function createArguments(args){return args;}const{printCliHelp,printSubcommandHelp}=_help.help;exports.printSubcommandHelp=printSubcommandHelp;exports.printCliHelp=printCliHelp;
@@ -1 +1 @@
1
- {"version":3,"names":["_help","require","_parser","_autocomplete","createCli","input","setAction","action","Object","assign","createSubcommand","createOptions","options","createArguments","args","printCliHelp","printSubcommandHelp","help","exports"],"sourceRoot":"../../src","sources":["index.ts"],"sourcesContent":["import { help } from \"./help.js\";\n\nimport type {\n ActionFn,\n Argument,\n CheckDuplicatedOptions,\n Cli,\n Option,\n Prettify,\n Subcommand,\n UnSafeParseResult,\n} from \"./types.js\";\n\n/**\n * - Insures that there is no extra keys in `obj` compared to `shape`\n * - Also checks objects in arrays useful for the keys `options` and `arguments`\n */\ntype Exact<Obj extends object, Shape extends object> = {\n [K in keyof Obj]: K extends keyof Shape\n ? Obj[K] extends infer ObjArr extends object[]\n ? Required<Shape>[K] extends infer ShapeArr extends object[]\n ? ExactObjArr<ObjArr, ShapeArr[number]>\n : Obj[K]\n : Obj[K]\n : never;\n};\n\n/** - Insures that there is no extra keys in `obj` compared to `shape` */\ntype ExactKeys<T extends object, U extends object> = { [K in keyof T]: K extends keyof U ? T[K] : never };\n\n/** - Insures that there is no extra keys in the objects in an array compared to `shape` */\ntype ExactObjArr<ObjArr extends object[], ShapeObj extends object> = {\n [K in keyof ObjArr]: ExactKeys<ObjArr[K], ShapeObj>;\n};\n\n/**\n * - Insures that there are no duplicated options\n * - Disallow extra keys\n */\ntype CliInput<T extends Cli> = CheckDuplicatedOptions<T> extends T ? Exact<T, Cli> : CheckDuplicatedOptions<T>;\n\nexport function createCli<const T extends Cli>(input: CliInput<T>) {\n const setAction = (action: (res: UnSafeParseResult<[T]>) => void) => {\n input.action = action;\n };\n\n return Object.assign(input, { setAction }) as Prettify<CliInput<T> & ActionFn<T>>;\n}\n\n/**\n * - Insures that there are no duplicated options\n * - Disallow extra keys\n */\ntype SubcommandInput<T extends Subcommand> =\n CheckDuplicatedOptions<T> extends T ? Exact<T, Subcommand> : CheckDuplicatedOptions<T>;\n\nexport function createSubcommand<const T extends Subcommand>(input: SubcommandInput<T>) {\n const setAction = (action: (res: UnSafeParseResult<[T]>) => void) => {\n input.action = action;\n };\n\n return Object.assign(input, { setAction }) as Prettify<SubcommandInput<T> & ActionFn<T>>;\n}\n\n/** - Insures that there are no duplicated options */\ntype CheckOptionsInput<T extends Option[]> =\n CheckDuplicatedOptions<{ options: T }> extends infer Err extends string ? Err : T;\n\nexport function createOptions<const T extends [Option, ...Option[]]>(options: CheckOptionsInput<T>) {\n return options;\n}\n\nexport function createArguments<const T extends [Argument, ...Argument[]]>(args: T) {\n return args;\n}\n\nconst { printCliHelp, printSubcommandHelp } = help;\nexport { printCliHelp, printSubcommandHelp };\n\nexport { parse, safeParse } from \"./parser.js\";\n\nexport { generateBashAutocompleteScript, generatePowerShellAutocompleteScript } from \"./autocomplete.js\";\n\nexport type * from \"./types.js\";\n"],"mappings":"gxBAAA,IAAAA,KAAA,CAAAC,OAAA,cA+EA,IAAAC,OAAA,CAAAD,OAAA,gBAEA,IAAAE,aAAA,CAAAF,OAAA,sBAxCO,QAAS,CAAAG,SAASA,CAAsBC,KAAkB,CAAE,CACjE,KAAM,CAAAC,SAAS,CAAIC,MAA6C,EAAK,CACnEF,KAAK,CAACE,MAAM,CAAGA,MAAM,CACvB,CAAC,CAED,MAAO,CAAAC,MAAM,CAACC,MAAM,CAACJ,KAAK,CAAE,CAAEC,SAAU,CAAC,CAAC,CAC5C,CASO,QAAS,CAAAI,gBAAgBA,CAA6BL,KAAyB,CAAE,CACtF,KAAM,CAAAC,SAAS,CAAIC,MAA6C,EAAK,CACnEF,KAAK,CAACE,MAAM,CAAGA,MAAM,CACvB,CAAC,CAED,MAAO,CAAAC,MAAM,CAACC,MAAM,CAACJ,KAAK,CAAE,CAAEC,SAAU,CAAC,CAAC,CAC5C,CAMO,QAAS,CAAAK,aAAaA,CAAwCC,OAA6B,CAAE,CAClG,MAAO,CAAAA,OAAO,CAChB,CAEO,QAAS,CAAAC,eAAeA,CAA4CC,IAAO,CAAE,CAClF,MAAO,CAAAA,IAAI,CACb,CAEA,KAAM,CAAEC,YAAY,CAAEC,mBAAoB,CAAC,CAAGC,UAAI,CAACC,OAAA,CAAAF,mBAAA,CAAAA,mBAAA,CAAAE,OAAA,CAAAH,YAAA,CAAAA,YAAA","ignoreList":[]}
1
+ {"version":3,"names":["_help","require","_parser","_autocomplete","createCli","input","setAction","action","Object","assign","createSubcommand","createOptions","options","createArguments","args","printCliHelp","printSubcommandHelp","help","exports"],"sourceRoot":"../../src","sources":["index.ts"],"sourcesContent":["import { help } from \"./help.js\";\n\nimport type {\n ActionFn,\n Argument,\n CheckDuplicatedOptions,\n Cli,\n Option,\n Prettify,\n Subcommand,\n UnSafeParseResult,\n} from \"./types.js\";\n\n/**\n * - Insures that there is no extra keys in `obj` compared to `shape`\n * - Also checks objects in arrays useful for the keys `options` and `arguments`\n */\ntype Exact<Obj extends object, Shape extends object> = {\n [K in keyof Obj]: K extends keyof Shape\n ? Obj[K] extends infer ObjArr extends object[]\n ? Required<Shape>[K] extends infer ShapeArr extends object[]\n ? ExactObjArr<ObjArr, ShapeArr[number]>\n : Obj[K]\n : Obj[K]\n : never;\n};\n\n/** - Insures that there is no extra keys in `obj` compared to `shape` */\ntype ExactKeys<T extends object, U extends object> = { [K in keyof T]: K extends keyof U ? T[K] : never };\n\n/** - Insures that there is no extra keys in the objects in an array compared to `shape` */\ntype ExactObjArr<ObjArr extends object[], ShapeObj extends object> = {\n [K in keyof ObjArr]: ExactKeys<ObjArr[K], ShapeObj>;\n};\n\n/**\n * - Insures that there are no duplicated options\n * - Disallow extra keys\n */\ntype CliInput<T extends Cli> = CheckDuplicatedOptions<T> extends T ? Exact<T, Cli> : CheckDuplicatedOptions<T>;\n\nexport function createCli<const T extends Cli>(input: CliInput<T>) {\n const setAction = (action: (res: UnSafeParseResult<[T]>) => void) => {\n input.action = action;\n };\n\n return Object.assign(input, { setAction }) as Prettify<CliInput<T> & ActionFn<T>>;\n}\n\n/**\n * - Insures that there are no duplicated options\n * - Disallow extra keys\n */\ntype SubcommandInput<T extends Subcommand> =\n CheckDuplicatedOptions<T> extends T ? Exact<T, Subcommand> : CheckDuplicatedOptions<T>;\n\nexport function createSubcommand<const T extends Subcommand>(input: SubcommandInput<T>) {\n const setAction = (action: (res: UnSafeParseResult<[T]>) => void) => {\n input.action = action;\n };\n\n return Object.assign(input, { setAction }) as Prettify<SubcommandInput<T> & ActionFn<T>>;\n}\n\n/** - Insures that there are no duplicated options */\ntype CheckOptionsInput<T extends Option[]> =\n CheckDuplicatedOptions<{ options: T }> extends infer Err extends string ? Err : T;\n\nexport function createOptions<const T extends [Option, ...Option[]]>(options: CheckOptionsInput<T>) {\n return options;\n}\n\nexport function createArguments<const T extends [Argument, ...Argument[]]>(args: T) {\n return args;\n}\n\nconst { printCliHelp, printSubcommandHelp } = help;\nexport { printCliHelp, printSubcommandHelp };\n\nexport { parse, safeParse } from \"./parser.js\";\n\nexport {\n generateBashAutocompleteScript,\n generateZshAutocompleteScript,\n generatePowerShellAutocompleteScript,\n} from \"./autocomplete.js\";\n\nexport type * from \"./types.js\";\n"],"mappings":"q6BAAA,IAAAA,KAAA,CAAAC,OAAA,cA+EA,IAAAC,OAAA,CAAAD,OAAA,gBAEA,IAAAE,aAAA,CAAAF,OAAA,sBAxCO,QAAS,CAAAG,SAASA,CAAsBC,KAAkB,CAAE,CACjE,KAAM,CAAAC,SAAS,CAAIC,MAA6C,EAAK,CACnEF,KAAK,CAACE,MAAM,CAAGA,MAAM,CACvB,CAAC,CAED,MAAO,CAAAC,MAAM,CAACC,MAAM,CAACJ,KAAK,CAAE,CAAEC,SAAU,CAAC,CAAC,CAC5C,CASO,QAAS,CAAAI,gBAAgBA,CAA6BL,KAAyB,CAAE,CACtF,KAAM,CAAAC,SAAS,CAAIC,MAA6C,EAAK,CACnEF,KAAK,CAACE,MAAM,CAAGA,MAAM,CACvB,CAAC,CAED,MAAO,CAAAC,MAAM,CAACC,MAAM,CAACJ,KAAK,CAAE,CAAEC,SAAU,CAAC,CAAC,CAC5C,CAMO,QAAS,CAAAK,aAAaA,CAAwCC,OAA6B,CAAE,CAClG,MAAO,CAAAA,OAAO,CAChB,CAEO,QAAS,CAAAC,eAAeA,CAA4CC,IAAO,CAAE,CAClF,MAAO,CAAAA,IAAI,CACb,CAEA,KAAM,CAAEC,YAAY,CAAEC,mBAAoB,CAAC,CAAGC,UAAI,CAACC,OAAA,CAAAF,mBAAA,CAAAA,mBAAA,CAAAE,OAAA,CAAAH,YAAA,CAAAA,YAAA","ignoreList":[]}
@@ -68,7 +68,7 @@ Register-ArgumentCompleter -CommandName '${cli.cliName}' -ParameterName 'argumen
68
68
  }`;}export function generateZshAutocompleteScript(...params){const[cli,...subcommands]=params;const genArguments=options=>{return options?.map(option=>`'${transformOptionToArg(option.name)}[${option.description??""}]'`).join(" \\\n ");};const genSubCommand=subcommand=>{const options=subcommand.options;if(!options||options.length===0)return"";return`${subcommand.name})
69
69
  _arguments \\
70
70
  ${genArguments(options)} \\
71
- '1: :_files' \\
71
+ '*: :_files' \\
72
72
  && ret=0
73
73
  ;;`;};return`
74
74
  _${cli.cliName}_autocomplete() {
@@ -84,7 +84,9 @@ _${cli.cliName}_autocomplete() {
84
84
  case "$words[1]" in
85
85
  ${subcommands.map(genSubCommand).filter(Boolean).join("\n ")}
86
86
  *)
87
- _message "No options available for this command"
87
+ _arguments \
88
+ '*: :_files' \
89
+ && ret=0
88
90
  ;;
89
91
  esac
90
92
  ;;
@@ -1 +1 @@
1
- {"version":3,"names":["transformOptionToArg","generateBashAutocompleteScript","params","cli","subcommands","mappedCommands","reduce","acc","subcommand","name","options","map","option","aliases","switchCase","key","Object","entries","length","join","cliName","keys","generatePowerShellAutocompleteScript","subcommandsStr","cliOptionsStr","optionsStr","forEach","a","functionInfo","description","example","generateZshAutocompleteScript","genArguments","genSubCommand","filter","Boolean"],"sourceRoot":"../../src","sources":["autocomplete.ts"],"sourcesContent":["import { transformOptionToArg } from \"./utils.js\";\n\nimport type { Cli, Option, Subcommand } from \"./types.js\";\n\n/**\n * - Generate bash autocomplete script for your CLI\n * - The generated script should be added to your `.bash_profile` or `.bashrc` file:\n *\n * - Run: `nano $HOME/.bash_profile` or `nano $HOME/.bashrc`\n * - Add the following line: `source <generated script path>`\n * - Save and reopen bash to take effect\n */\nexport function generateBashAutocompleteScript(...params: [Cli, ...Subcommand[]]): string {\n const [cli, ...subcommands] = params;\n\n type MappedCommands = Record<string, { options: string[]; aliases: string[] }>;\n\n const mappedCommands = subcommands.reduce((acc: MappedCommands, subcommand) => {\n acc[subcommand.name] = {\n options: subcommand.options?.map(option => transformOptionToArg(option.name)) ?? [],\n aliases: subcommand.aliases ?? [],\n };\n return acc;\n }, {});\n\n let switchCase = \"\";\n for (const [key, { options, aliases }] of Object.entries(mappedCommands)) {\n switchCase += ` ${key}${aliases.length ? \"|\" : \"\"}${aliases.join(\"|\")})\\n`;\n switchCase += ` opts=\"${options.join(\" \")}\"\\n`;\n switchCase += \" ;;\\n\";\n }\n\n if (cli.options?.length) {\n switchCase += ` \"-\"*)\\n`;\n switchCase += ` opts=\"${cli.options.map(option => transformOptionToArg(option.name)).join(\" \")}\"\\n`;\n switchCase += \" ;;\\n\";\n }\n\n return `_${cli.cliName}_autocomplete() {\n local cur prev commands opts subcommand used_opts filtered_opts\n\n cur=\"\\${COMP_WORDS[COMP_CWORD]}\"\n prev=\"\\${COMP_WORDS[COMP_CWORD-1]}\"\n subcommand=\"\\${COMP_WORDS[1]}\"\n\n commands=\"${Object.keys(mappedCommands).join(\" \")}\"\n\n case \"$subcommand\" in\n${switchCase}\n esac\n\n used_opts=\"\"\n if [[ \" \\${commands[@]} \" =~ \" $subcommand \" ]]; then\n for word in \"\\${COMP_WORDS[@]:2}\"; do\n if [[ \"$word\" =~ ^- ]]; then\n used_opts+=\" $word\"\n fi\n done\n fi\n\n if [[ -n \"$opts\" ]]; then\n filtered_opts=\"\"\n for opt in $opts; do\n if [[ ! \" $used_opts \" =~ \" $opt \" ]]; then\n filtered_opts+=\"$opt \"\n fi\n done\n COMPREPLY=( $(compgen -W \"$filtered_opts\" -- \"$cur\") )\n return\n fi\n\n if [[ \"\\${COMP_CWORD}\" -eq 1 ]]; then\n COMPREPLY=( $(compgen -W \"$commands\" -- \"$cur\") )\n fi\n}\n\ncomplete -F _${cli.cliName}_autocomplete ${cli.cliName}\n`;\n}\n\n/**\n * - Generates a PowerShell autocomplete script for your CLI.\n * - The script assumes that your CLI is available as a `.ps1` file in the environment variable. For example:\n * `cliName.ps1`.\n * - This should return a path to your script: `(Get-Command <cliName>.ps1).Source`\n * - The generated script should be added to your `profile.ps1` file:\n *\n * - Run: `notepad $profile`\n * - Add the following line: `. \"<generated script path>\"`\n * - Save and reopen powershell to take effect\n */\nexport function generatePowerShellAutocompleteScript(...params: [Cli, ...Subcommand[]]): string {\n const [cli, ...subcommands] = params;\n\n type MappedCommands = Record<string, { options: string[]; aliases: string[] }>;\n\n const mappedCommands = subcommands.reduce((acc: MappedCommands, subcommand) => {\n acc[subcommand.name] = {\n options: subcommand.options?.map(option => transformOptionToArg(option.name)) ?? [],\n aliases: subcommand.aliases ?? [],\n };\n return acc;\n }, {});\n\n const subcommandsStr = Object.keys(mappedCommands)\n .map(key => `'${key}'`)\n .join(\", \");\n const cliOptionsStr = cli.options?.map(option => `'${transformOptionToArg(option.name)}'`).join(\", \") || \"\";\n\n let switchCase = \"switch ($subcommand) {\\n\";\n for (const [key, { options, aliases }] of Object.entries(mappedCommands)) {\n const optionsStr = options.map(option => `'${option}'`).join(\", \");\n switchCase += ` '${key}' { @(${optionsStr}) }\\n`;\n aliases.forEach(a => (switchCase += ` '${a}' { @(${optionsStr}) }\\n`));\n }\n switchCase += ` default { @(${cliOptionsStr}) }\\n }`;\n\n let functionInfo = \"\";\n if (cli.description) {\n functionInfo = `<#\\n.DESCRIPTION\\n${cli.description}\\n${cli.example ? `\\n.EXAMPLE\\n${cli.example}` : \"\"}\\n#>`;\n }\n\n return `${functionInfo}\nfunction ${cli.cliName} {\n param(\n [Parameter(Position = 0, Mandatory = $false)]\n [string]$subcommand,\n [Parameter(Position = 1, ValueFromRemainingArguments = $true)]\n [string[]]$arguments\n )\n $scriptPath = (Get-Command '${cli.cliName}.ps1').Source\n if ($scriptPath) {\n $argumentList = @($subcommand) + ($arguments | Where-Object { $_ -notin '--', '--%' }) | Where-Object { $_ -ne '' }\n & $scriptPath @argumentList\n return\n }\n Write-Error \"Could not find '${cli.cliName}.ps1' script\"\n}\n\nRegister-ArgumentCompleter -CommandName '${cli.cliName}' -ParameterName 'subcommand' -ScriptBlock {\n param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)\n $subcommands = @(${subcommandsStr}${subcommandsStr && cliOptionsStr ? \", \" : \"\"}${cliOptionsStr})\n $subcommands | Where-Object { $_ -like \"$wordToComplete*\" }\n}\n\nRegister-ArgumentCompleter -CommandName '${cli.cliName}' -ParameterName 'arguments' -ScriptBlock {\n param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)\n $subcommand = $commandAst.CommandElements[1].Value\n $arguments = ${switchCase}\n $arguments | Where-Object { $_ -like \"$wordToComplete*\" }\n}`;\n}\n\n/**\n * - Generates a ZSH autocomplete script for your CLI.\n * - The generated script should be added to your `~/.zshrc` or `~/.zsh_profile` file:\n *\n * - Run: `nano $HOME/.zshrc` or `nano $HOME/.zsh_profile`\n * - Add the following line: `source <generated script path>`\n * - Save and reopen zsh to take effect\n */\nexport function generateZshAutocompleteScript(...params: [Cli, ...Subcommand[]]): string {\n const [cli, ...subcommands] = params;\n\n const genArguments = (options: Option[]) => {\n return options\n ?.map(option => `'${transformOptionToArg(option.name)}[${option.description ?? \"\"}]'`)\n .join(\" \\\\\\n \");\n };\n\n const genSubCommand = (subcommand: Subcommand) => {\n const options = subcommand.options;\n if (!options || options.length === 0) return \"\";\n return `${subcommand.name})\n _arguments \\\\\n ${genArguments(options)} \\\\\n '1: :_files' \\\\\n && ret=0\n ;;`;\n };\n\n return `\n_${cli.cliName}_autocomplete() {\n local ret=1\n\n _arguments -C \\\\\n '1: :_${cli.cliName}_commands' \\\\\n '*:: :->subcmds' \\\\\n && ret=0\n\n case $state in\n subcmds)\n case \"$words[1]\" in\n ${subcommands.map(genSubCommand).filter(Boolean).join(\"\\n \")}\n *)\n _message \"No options available for this command\"\n ;;\n esac\n ;;\n esac\n\n return $ret\n}\n \n_${cli.cliName}_commands() {\n local -a commands=(\n ${subcommands.map(subcommand => `\"${subcommand.name}:${subcommand.description ?? \"\"}\"`).join(\"\\n \")}\n )\n\n _describe -t subcommands 'subcommand' commands\n}\n\ncompdef _${cli.cliName}_autocomplete ${cli.cliName}\n`;\n}\n"],"mappings":"AAAA,OAASA,oBAAoB,KAAQ,YAAY,CAYjD,MAAO,SAAS,CAAAC,8BAA8BA,CAAC,GAAGC,MAA8B,CAAU,CACxF,KAAM,CAACC,GAAG,CAAE,GAAGC,WAAW,CAAC,CAAGF,MAAM,CAIpC,KAAM,CAAAG,cAAc,CAAGD,WAAW,CAACE,MAAM,CAAC,CAACC,GAAmB,CAAEC,UAAU,GAAK,CAC7ED,GAAG,CAACC,UAAU,CAACC,IAAI,CAAC,CAAG,CACrBC,OAAO,CAAEF,UAAU,CAACE,OAAO,EAAEC,GAAG,CAACC,MAAM,EAAIZ,oBAAoB,CAACY,MAAM,CAACH,IAAI,CAAC,CAAC,EAAI,EAAE,CACnFI,OAAO,CAAEL,UAAU,CAACK,OAAO,EAAI,EACjC,CAAC,CACD,MAAO,CAAAN,GAAG,CACZ,CAAC,CAAE,CAAC,CAAC,CAAC,CAEN,GAAI,CAAAO,UAAU,CAAG,EAAE,CACnB,IAAK,KAAM,CAACC,GAAG,CAAE,CAAEL,OAAO,CAAEG,OAAQ,CAAC,CAAC,EAAI,CAAAG,MAAM,CAACC,OAAO,CAACZ,cAAc,CAAC,CAAE,CACxES,UAAU,EAAI,OAAOC,GAAG,GAAGF,OAAO,CAACK,MAAM,CAAG,GAAG,CAAG,EAAE,GAAGL,OAAO,CAACM,IAAI,CAAC,GAAG,CAAC,KAAK,CAC7EL,UAAU,EAAI,eAAeJ,OAAO,CAACS,IAAI,CAAC,GAAG,CAAC,KAAK,CACnDL,UAAU,EAAI,YAAY,CAC5B,CAEA,GAAIX,GAAG,CAACO,OAAO,EAAEQ,MAAM,CAAE,CACvBJ,UAAU,EAAI,aAAa,CAC3BA,UAAU,EAAI,eAAeX,GAAG,CAACO,OAAO,CAACC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A;AACA,WAAWhB,GAAG,CAACiB,OAAO,iBAAiBjB,GAAG,CAACiB,OAAO;AAClD,CAAC,CACD","ignoreList":[]}
1
+ {"version":3,"names":["transformOptionToArg","generateBashAutocompleteScript","params","cli","subcommands","mappedCommands","reduce","acc","subcommand","name","options","map","option","aliases","switchCase","key","Object","entries","length","join","cliName","keys","generatePowerShellAutocompleteScript","subcommandsStr","cliOptionsStr","optionsStr","forEach","a","functionInfo","description","example","generateZshAutocompleteScript","genArguments","genSubCommand","filter","Boolean"],"sourceRoot":"../../src","sources":["autocomplete.ts"],"sourcesContent":["import { transformOptionToArg } from \"./utils.js\";\n\nimport type { Cli, Option, Subcommand } from \"./types.js\";\n\n/**\n * - Generate bash autocomplete script for your CLI\n * - The generated script should be added to your `.bash_profile` or `.bashrc` file:\n *\n * - Run: `nano $HOME/.bash_profile` or `nano $HOME/.bashrc`\n * - Add the following line: `source <generated script path>`\n * - Save and reopen bash to take effect\n */\nexport function generateBashAutocompleteScript(...params: [Cli, ...Subcommand[]]): string {\n const [cli, ...subcommands] = params;\n\n type MappedCommands = Record<string, { options: string[]; aliases: string[] }>;\n\n const mappedCommands = subcommands.reduce((acc: MappedCommands, subcommand) => {\n acc[subcommand.name] = {\n options: subcommand.options?.map(option => transformOptionToArg(option.name)) ?? [],\n aliases: subcommand.aliases ?? [],\n };\n return acc;\n }, {});\n\n let switchCase = \"\";\n for (const [key, { options, aliases }] of Object.entries(mappedCommands)) {\n switchCase += ` ${key}${aliases.length ? \"|\" : \"\"}${aliases.join(\"|\")})\\n`;\n switchCase += ` opts=\"${options.join(\" \")}\"\\n`;\n switchCase += \" ;;\\n\";\n }\n\n if (cli.options?.length) {\n switchCase += ` \"-\"*)\\n`;\n switchCase += ` opts=\"${cli.options.map(option => transformOptionToArg(option.name)).join(\" \")}\"\\n`;\n switchCase += \" ;;\\n\";\n }\n\n return `_${cli.cliName}_autocomplete() {\n local cur prev commands opts subcommand used_opts filtered_opts\n\n cur=\"\\${COMP_WORDS[COMP_CWORD]}\"\n prev=\"\\${COMP_WORDS[COMP_CWORD-1]}\"\n subcommand=\"\\${COMP_WORDS[1]}\"\n\n commands=\"${Object.keys(mappedCommands).join(\" \")}\"\n\n case \"$subcommand\" in\n${switchCase}\n esac\n\n used_opts=\"\"\n if [[ \" \\${commands[@]} \" =~ \" $subcommand \" ]]; then\n for word in \"\\${COMP_WORDS[@]:2}\"; do\n if [[ \"$word\" =~ ^- ]]; then\n used_opts+=\" $word\"\n fi\n done\n fi\n\n if [[ -n \"$opts\" ]]; then\n filtered_opts=\"\"\n for opt in $opts; do\n if [[ ! \" $used_opts \" =~ \" $opt \" ]]; then\n filtered_opts+=\"$opt \"\n fi\n done\n COMPREPLY=( $(compgen -W \"$filtered_opts\" -- \"$cur\") )\n return\n fi\n\n if [[ \"\\${COMP_CWORD}\" -eq 1 ]]; then\n COMPREPLY=( $(compgen -W \"$commands\" -- \"$cur\") )\n fi\n}\n\ncomplete -F _${cli.cliName}_autocomplete ${cli.cliName}\n`;\n}\n\n/**\n * - Generates a PowerShell autocomplete script for your CLI.\n * - The script assumes that your CLI is available as a `.ps1` file in the environment variable. For example:\n * `cliName.ps1`.\n * - This should return a path to your script: `(Get-Command <cliName>.ps1).Source`\n * - The generated script should be added to your `profile.ps1` file:\n *\n * - Run: `notepad $profile`\n * - Add the following line: `. \"<generated script path>\"`\n * - Save and reopen powershell to take effect\n */\nexport function generatePowerShellAutocompleteScript(...params: [Cli, ...Subcommand[]]): string {\n const [cli, ...subcommands] = params;\n\n type MappedCommands = Record<string, { options: string[]; aliases: string[] }>;\n\n const mappedCommands = subcommands.reduce((acc: MappedCommands, subcommand) => {\n acc[subcommand.name] = {\n options: subcommand.options?.map(option => transformOptionToArg(option.name)) ?? [],\n aliases: subcommand.aliases ?? [],\n };\n return acc;\n }, {});\n\n const subcommandsStr = Object.keys(mappedCommands)\n .map(key => `'${key}'`)\n .join(\", \");\n const cliOptionsStr = cli.options?.map(option => `'${transformOptionToArg(option.name)}'`).join(\", \") || \"\";\n\n let switchCase = \"switch ($subcommand) {\\n\";\n for (const [key, { options, aliases }] of Object.entries(mappedCommands)) {\n const optionsStr = options.map(option => `'${option}'`).join(\", \");\n switchCase += ` '${key}' { @(${optionsStr}) }\\n`;\n aliases.forEach(a => (switchCase += ` '${a}' { @(${optionsStr}) }\\n`));\n }\n switchCase += ` default { @(${cliOptionsStr}) }\\n }`;\n\n let functionInfo = \"\";\n if (cli.description) {\n functionInfo = `<#\\n.DESCRIPTION\\n${cli.description}\\n${cli.example ? `\\n.EXAMPLE\\n${cli.example}` : \"\"}\\n#>`;\n }\n\n return `${functionInfo}\nfunction ${cli.cliName} {\n param(\n [Parameter(Position = 0, Mandatory = $false)]\n [string]$subcommand,\n [Parameter(Position = 1, ValueFromRemainingArguments = $true)]\n [string[]]$arguments\n )\n $scriptPath = (Get-Command '${cli.cliName}.ps1').Source\n if ($scriptPath) {\n $argumentList = @($subcommand) + ($arguments | Where-Object { $_ -notin '--', '--%' }) | Where-Object { $_ -ne '' }\n & $scriptPath @argumentList\n return\n }\n Write-Error \"Could not find '${cli.cliName}.ps1' script\"\n}\n\nRegister-ArgumentCompleter -CommandName '${cli.cliName}' -ParameterName 'subcommand' -ScriptBlock {\n param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)\n $subcommands = @(${subcommandsStr}${subcommandsStr && cliOptionsStr ? \", \" : \"\"}${cliOptionsStr})\n $subcommands | Where-Object { $_ -like \"$wordToComplete*\" }\n}\n\nRegister-ArgumentCompleter -CommandName '${cli.cliName}' -ParameterName 'arguments' -ScriptBlock {\n param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)\n $subcommand = $commandAst.CommandElements[1].Value\n $arguments = ${switchCase}\n $arguments | Where-Object { $_ -like \"$wordToComplete*\" }\n}`;\n}\n\n/**\n * - Generates a ZSH autocomplete script for your CLI.\n * - The generated script should be added to your `~/.zshrc` or `~/.zsh_profile` file:\n *\n * - Run: `nano $HOME/.zshrc` or `nano $HOME/.zsh_profile`\n * - Add the following line: `source <generated script path>`\n * - Save and reopen zsh to take effect\n */\nexport function generateZshAutocompleteScript(...params: [Cli, ...Subcommand[]]): string {\n const [cli, ...subcommands] = params;\n\n const genArguments = (options: Option[]) => {\n return options\n ?.map(option => `'${transformOptionToArg(option.name)}[${option.description ?? \"\"}]'`)\n .join(\" \\\\\\n \");\n };\n\n const genSubCommand = (subcommand: Subcommand) => {\n const options = subcommand.options;\n if (!options || options.length === 0) return \"\";\n return `${subcommand.name})\n _arguments \\\\\n ${genArguments(options)} \\\\\n '*: :_files' \\\\\n && ret=0\n ;;`;\n };\n\n return `\n_${cli.cliName}_autocomplete() {\n local ret=1\n\n _arguments -C \\\\\n '1: :_${cli.cliName}_commands' \\\\\n '*:: :->subcmds' \\\\\n && ret=0\n\n case $state in\n subcmds)\n case \"$words[1]\" in\n ${subcommands.map(genSubCommand).filter(Boolean).join(\"\\n \")}\n *)\n _arguments \\\n '*: :_files' \\\n && ret=0\n ;;\n esac\n ;;\n esac\n\n return $ret\n}\n \n_${cli.cliName}_commands() {\n local -a commands=(\n ${subcommands.map(subcommand => `\"${subcommand.name}:${subcommand.description ?? \"\"}\"`).join(\"\\n \")}\n )\n\n _describe -t subcommands 'subcommand' commands\n}\n\ncompdef _${cli.cliName}_autocomplete ${cli.cliName}\n`;\n}\n"],"mappings":"AAAA,OAASA,oBAAoB,KAAQ,YAAY,CAYjD,MAAO,SAAS,CAAAC,8BAA8BA,CAAC,GAAGC,MAA8B,CAAU,CACxF,KAAM,CAACC,GAAG,CAAE,GAAGC,WAAW,CAAC,CAAGF,MAAM,CAIpC,KAAM,CAAAG,cAAc,CAAGD,WAAW,CAACE,MAAM,CAAC,CAACC,GAAmB,CAAEC,UAAU,GAAK,CAC7ED,GAAG,CAACC,UAAU,CAACC,IAAI,CAAC,CAAG,CACrBC,OAAO,CAAEF,UAAU,CAACE,OAAO,EAAEC,GAAG,CAACC,MAAM,EAAIZ,oBAAoB,CAACY,MAAM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I,CAACA,OAAO,EAAIA,OAAO,CAACQ,MAAM,GAAK,CAAC,CAAE,MAAO,EAAE,CAC/C,MAAO,GAAGV,UAAU,CAACC,IAAI;AAC7B;AACA,cAAcuB,YAAY,CAACtB,OAAO,CAAC;AACnC;AACA;AACA,aAAa,CACX,CAAC,CAED,MAAO;AACT,GAAGP,GAAG,CAACiB,OAAO;AACd;AACA;AACA;AACA,YAAYjB,GAAG,CAACiB,OAAO;AACvB;AACA;AACA;AACA;AACA;AACA;AACA,UAAUhB,WAAW,CAACO,GAAG,CAACsB,aAAa,CAAC,CAACC,MAAM,CAACC,OAAO,CAAC,CAAChB,IAAI,CAAC,YAAY,CAAC;AAC3E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAGhB,GAAG,CAACiB,OAAO;AACd;AACA,MAAMhB,WAAW,CAACO,GAAG,CAACH,UAAU,EAAI,IAAIA,UAAU,CAACC,IAAI,IAAID,UAAU,CAACqB,WAAW,EAAI,EAAE,GAAG,CAAC,CAACV,IAAI,CAAC,QAAQ,CAAC;AAC1G;AACA;AACA;AACA;AACA;AACA,WAAWhB,GAAG,CAACiB,OAAO,iBAAiBjB,GAAG,CAACiB,OAAO;AAClD,CAAC,CACD","ignoreList":[]}
@@ -1 +1 @@
1
- import{help}from"./help.js";export function createCli(input){const setAction=action=>{input.action=action;};return Object.assign(input,{setAction});}export function createSubcommand(input){const setAction=action=>{input.action=action;};return Object.assign(input,{setAction});}export function createOptions(options){return options;}export function createArguments(args){return args;}const{printCliHelp,printSubcommandHelp}=help;export{printCliHelp,printSubcommandHelp};export{parse,safeParse}from"./parser.js";export{generateBashAutocompleteScript,generatePowerShellAutocompleteScript}from"./autocomplete.js";
1
+ import{help}from"./help.js";export function createCli(input){const setAction=action=>{input.action=action;};return Object.assign(input,{setAction});}export function createSubcommand(input){const setAction=action=>{input.action=action;};return Object.assign(input,{setAction});}export function createOptions(options){return options;}export function createArguments(args){return args;}const{printCliHelp,printSubcommandHelp}=help;export{printCliHelp,printSubcommandHelp};export{parse,safeParse}from"./parser.js";export{generateBashAutocompleteScript,generateZshAutocompleteScript,generatePowerShellAutocompleteScript}from"./autocomplete.js";
@@ -1 +1 @@
1
- {"version":3,"names":["help","createCli","input","setAction","action","Object","assign","createSubcommand","createOptions","options","createArguments","args","printCliHelp","printSubcommandHelp","parse","safeParse","generateBashAutocompleteScript","generatePowerShellAutocompleteScript"],"sourceRoot":"../../src","sources":["index.ts"],"sourcesContent":["import { help } from \"./help.js\";\n\nimport type {\n ActionFn,\n Argument,\n CheckDuplicatedOptions,\n Cli,\n Option,\n Prettify,\n Subcommand,\n UnSafeParseResult,\n} from \"./types.js\";\n\n/**\n * - Insures that there is no extra keys in `obj` compared to `shape`\n * - Also checks objects in arrays useful for the keys `options` and `arguments`\n */\ntype Exact<Obj extends object, Shape extends object> = {\n [K in keyof Obj]: K extends keyof Shape\n ? Obj[K] extends infer ObjArr extends object[]\n ? Required<Shape>[K] extends infer ShapeArr extends object[]\n ? ExactObjArr<ObjArr, ShapeArr[number]>\n : Obj[K]\n : Obj[K]\n : never;\n};\n\n/** - Insures that there is no extra keys in `obj` compared to `shape` */\ntype ExactKeys<T extends object, U extends object> = { [K in keyof T]: K extends keyof U ? T[K] : never };\n\n/** - Insures that there is no extra keys in the objects in an array compared to `shape` */\ntype ExactObjArr<ObjArr extends object[], ShapeObj extends object> = {\n [K in keyof ObjArr]: ExactKeys<ObjArr[K], ShapeObj>;\n};\n\n/**\n * - Insures that there are no duplicated options\n * - Disallow extra keys\n */\ntype CliInput<T extends Cli> = CheckDuplicatedOptions<T> extends T ? Exact<T, Cli> : CheckDuplicatedOptions<T>;\n\nexport function createCli<const T extends Cli>(input: CliInput<T>) {\n const setAction = (action: (res: UnSafeParseResult<[T]>) => void) => {\n input.action = action;\n };\n\n return Object.assign(input, { setAction }) as Prettify<CliInput<T> & ActionFn<T>>;\n}\n\n/**\n * - Insures that there are no duplicated options\n * - Disallow extra keys\n */\ntype SubcommandInput<T extends Subcommand> =\n CheckDuplicatedOptions<T> extends T ? Exact<T, Subcommand> : CheckDuplicatedOptions<T>;\n\nexport function createSubcommand<const T extends Subcommand>(input: SubcommandInput<T>) {\n const setAction = (action: (res: UnSafeParseResult<[T]>) => void) => {\n input.action = action;\n };\n\n return Object.assign(input, { setAction }) as Prettify<SubcommandInput<T> & ActionFn<T>>;\n}\n\n/** - Insures that there are no duplicated options */\ntype CheckOptionsInput<T extends Option[]> =\n CheckDuplicatedOptions<{ options: T }> extends infer Err extends string ? Err : T;\n\nexport function createOptions<const T extends [Option, ...Option[]]>(options: CheckOptionsInput<T>) {\n return options;\n}\n\nexport function createArguments<const T extends [Argument, ...Argument[]]>(args: T) {\n return args;\n}\n\nconst { printCliHelp, printSubcommandHelp } = help;\nexport { printCliHelp, printSubcommandHelp };\n\nexport { parse, safeParse } from \"./parser.js\";\n\nexport { generateBashAutocompleteScript, generatePowerShellAutocompleteScript } from \"./autocomplete.js\";\n\nexport type * from \"./types.js\";\n"],"mappings":"AAAA,OAASA,IAAI,KAAQ,WAAW,CAyChC,MAAO,SAAS,CAAAC,SAASA,CAAsBC,KAAkB,CAAE,CACjE,KAAM,CAAAC,SAAS,CAAIC,MAA6C,EAAK,CACnEF,KAAK,CAACE,MAAM,CAAGA,MAAM,CACvB,CAAC,CAED,MAAO,CAAAC,MAAM,CAACC,MAAM,CAACJ,KAAK,CAAE,CAAEC,SAAU,CAAC,CAAC,CAC5C,CASA,MAAO,SAAS,CAAAI,gBAAgBA,CAA6BL,KAAyB,CAAE,CACtF,KAAM,CAAAC,SAAS,CAAIC,MAA6C,EAAK,CACnEF,KAAK,CAACE,MAAM,CAAGA,MAAM,CACvB,CAAC,CAED,MAAO,CAAAC,MAAM,CAACC,MAAM,CAACJ,KAAK,CAAE,CAAEC,SAAU,CAAC,CAAC,CAC5C,CAMA,MAAO,SAAS,CAAAK,aAAaA,CAAwCC,OAA6B,CAAE,CAClG,MAAO,CAAAA,OAAO,CAChB,CAEA,MAAO,SAAS,CAAAC,eAAeA,CAA4CC,IAAO,CAAE,CAClF,MAAO,CAAAA,IAAI,CACb,CAEA,KAAM,CAAEC,YAAY,CAAEC,mBAAoB,CAAC,CAAGb,IAAI,CAClD,OAASY,YAAY,CAAEC,mBAAmB,EAE1C,OAASC,KAAK,CAAEC,SAAS,KAAQ,aAAa,CAE9C,OAASC,8BAA8B,CAAEC,oCAAoC,KAAQ,mBAAmB","ignoreList":[]}
1
+ {"version":3,"names":["help","createCli","input","setAction","action","Object","assign","createSubcommand","createOptions","options","createArguments","args","printCliHelp","printSubcommandHelp","parse","safeParse","generateBashAutocompleteScript","generateZshAutocompleteScript","generatePowerShellAutocompleteScript"],"sourceRoot":"../../src","sources":["index.ts"],"sourcesContent":["import { help } from \"./help.js\";\n\nimport type {\n ActionFn,\n Argument,\n CheckDuplicatedOptions,\n Cli,\n Option,\n Prettify,\n Subcommand,\n UnSafeParseResult,\n} from \"./types.js\";\n\n/**\n * - Insures that there is no extra keys in `obj` compared to `shape`\n * - Also checks objects in arrays useful for the keys `options` and `arguments`\n */\ntype Exact<Obj extends object, Shape extends object> = {\n [K in keyof Obj]: K extends keyof Shape\n ? Obj[K] extends infer ObjArr extends object[]\n ? Required<Shape>[K] extends infer ShapeArr extends object[]\n ? ExactObjArr<ObjArr, ShapeArr[number]>\n : Obj[K]\n : Obj[K]\n : never;\n};\n\n/** - Insures that there is no extra keys in `obj` compared to `shape` */\ntype ExactKeys<T extends object, U extends object> = { [K in keyof T]: K extends keyof U ? T[K] : never };\n\n/** - Insures that there is no extra keys in the objects in an array compared to `shape` */\ntype ExactObjArr<ObjArr extends object[], ShapeObj extends object> = {\n [K in keyof ObjArr]: ExactKeys<ObjArr[K], ShapeObj>;\n};\n\n/**\n * - Insures that there are no duplicated options\n * - Disallow extra keys\n */\ntype CliInput<T extends Cli> = CheckDuplicatedOptions<T> extends T ? Exact<T, Cli> : CheckDuplicatedOptions<T>;\n\nexport function createCli<const T extends Cli>(input: CliInput<T>) {\n const setAction = (action: (res: UnSafeParseResult<[T]>) => void) => {\n input.action = action;\n };\n\n return Object.assign(input, { setAction }) as Prettify<CliInput<T> & ActionFn<T>>;\n}\n\n/**\n * - Insures that there are no duplicated options\n * - Disallow extra keys\n */\ntype SubcommandInput<T extends Subcommand> =\n CheckDuplicatedOptions<T> extends T ? Exact<T, Subcommand> : CheckDuplicatedOptions<T>;\n\nexport function createSubcommand<const T extends Subcommand>(input: SubcommandInput<T>) {\n const setAction = (action: (res: UnSafeParseResult<[T]>) => void) => {\n input.action = action;\n };\n\n return Object.assign(input, { setAction }) as Prettify<SubcommandInput<T> & ActionFn<T>>;\n}\n\n/** - Insures that there are no duplicated options */\ntype CheckOptionsInput<T extends Option[]> =\n CheckDuplicatedOptions<{ options: T }> extends infer Err extends string ? Err : T;\n\nexport function createOptions<const T extends [Option, ...Option[]]>(options: CheckOptionsInput<T>) {\n return options;\n}\n\nexport function createArguments<const T extends [Argument, ...Argument[]]>(args: T) {\n return args;\n}\n\nconst { printCliHelp, printSubcommandHelp } = help;\nexport { printCliHelp, printSubcommandHelp };\n\nexport { parse, safeParse } from \"./parser.js\";\n\nexport {\n generateBashAutocompleteScript,\n generateZshAutocompleteScript,\n generatePowerShellAutocompleteScript,\n} from \"./autocomplete.js\";\n\nexport type * from \"./types.js\";\n"],"mappings":"AAAA,OAASA,IAAI,KAAQ,WAAW,CAyChC,MAAO,SAAS,CAAAC,SAASA,CAAsBC,KAAkB,CAAE,CACjE,KAAM,CAAAC,SAAS,CAAIC,MAA6C,EAAK,CACnEF,KAAK,CAACE,MAAM,CAAGA,MAAM,CACvB,CAAC,CAED,MAAO,CAAAC,MAAM,CAACC,MAAM,CAACJ,KAAK,CAAE,CAAEC,SAAU,CAAC,CAAC,CAC5C,CASA,MAAO,SAAS,CAAAI,gBAAgBA,CAA6BL,KAAyB,CAAE,CACtF,KAAM,CAAAC,SAAS,CAAIC,MAA6C,EAAK,CACnEF,KAAK,CAACE,MAAM,CAAGA,MAAM,CACvB,CAAC,CAED,MAAO,CAAAC,MAAM,CAACC,MAAM,CAACJ,KAAK,CAAE,CAAEC,SAAU,CAAC,CAAC,CAC5C,CAMA,MAAO,SAAS,CAAAK,aAAaA,CAAwCC,OAA6B,CAAE,CAClG,MAAO,CAAAA,OAAO,CAChB,CAEA,MAAO,SAAS,CAAAC,eAAeA,CAA4CC,IAAO,CAAE,CAClF,MAAO,CAAAA,IAAI,CACb,CAEA,KAAM,CAAEC,YAAY,CAAEC,mBAAoB,CAAC,CAAGb,IAAI,CAClD,OAASY,YAAY,CAAEC,mBAAmB,EAE1C,OAASC,KAAK,CAAEC,SAAS,KAAQ,aAAa,CAE9C,OACEC,8BAA8B,CAC9BC,6BAA6B,CAC7BC,oCAAoC,KAC/B,mBAAmB","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"autocomplete.d.ts","sourceRoot":"","sources":["../../src/autocomplete.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAU,UAAU,EAAE,MAAM,YAAY,CAAC;AAE1D;;;;;;;GAOG;AACH,wBAAgB,8BAA8B,CAAC,GAAG,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,UAAU,EAAE,CAAC,GAAG,MAAM,CAkExF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oCAAoC,CAAC,GAAG,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,UAAU,EAAE,CAAC,GAAG,MAAM,CA4D9F;AAED;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAAC,GAAG,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,UAAU,EAAE,CAAC,GAAG,MAAM,CAqDvF"}
1
+ {"version":3,"file":"autocomplete.d.ts","sourceRoot":"","sources":["../../src/autocomplete.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAU,UAAU,EAAE,MAAM,YAAY,CAAC;AAE1D;;;;;;;GAOG;AACH,wBAAgB,8BAA8B,CAAC,GAAG,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,UAAU,EAAE,CAAC,GAAG,MAAM,CAkExF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oCAAoC,CAAC,GAAG,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,UAAU,EAAE,CAAC,GAAG,MAAM,CA4D9F;AAED;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAAC,GAAG,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,UAAU,EAAE,CAAC,GAAG,MAAM,CAuDvF"}
@@ -35,6 +35,6 @@ export declare function createArguments<const T extends [Argument, ...Argument[]
35
35
  declare const printCliHelp: (params: [Cli, ...Subcommand[]], printOptions?: import("./types.js").PrintHelpOpt) => void, printSubcommandHelp: (subcommand: Subcommand, printOptions?: import("./types.js").PrintHelpOpt, cliName?: string) => void;
36
36
  export { printCliHelp, printSubcommandHelp };
37
37
  export { parse, safeParse } from "./parser.js";
38
- export { generateBashAutocompleteScript, generatePowerShellAutocompleteScript } from "./autocomplete.js";
38
+ export { generateBashAutocompleteScript, generateZshAutocompleteScript, generatePowerShellAutocompleteScript, } from "./autocomplete.js";
39
39
  export type * from "./types.js";
40
40
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,QAAQ,EACR,QAAQ,EACR,sBAAsB,EACtB,GAAG,EACH,MAAM,EACN,QAAQ,EACR,UAAU,EAEX,MAAM,YAAY,CAAC;AAEpB;;;GAGG;AACH,KAAK,KAAK,CAAC,GAAG,SAAS,MAAM,EAAE,KAAK,SAAS,MAAM,IAAI;KACpD,CAAC,IAAI,MAAM,GAAG,GAAG,CAAC,SAAS,MAAM,KAAK,GACnC,GAAG,CAAC,CAAC,CAAC,SAAS,MAAM,MAAM,SAAS,MAAM,EAAE,GAC1C,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAA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,EAAE,eAAe,CAAC,CAAC,CAAC,GAKtC,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CACzF;AAED,qDAAqD;AACrD,KAAK,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAAE,IACvC,sBAAsB,CAAC;IAAE,OAAO,EAAE,CAAC,CAAA;CAAE,CAAC,SAAS,MAAM,GAAG,SAAS,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC;AAEpF,wBAAgB,aAAa,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,wBAEjG;AAED,wBAAgB,eAAe,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,QAAQ,EAAE,GAAG,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,KAEjF;AAED,QAAA,MAAQ,YAAY,8FAAE,mBAAmB,sGAAS,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,CAAC;AAE7C,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EACL,8BAA8B,EAC9B,6BAA6B,EAC7B,oCAAoC,GACrC,MAAM,mBAAmB,CAAC;AAE3B,mBAAmB,YAAY,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod-args-parser",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "A strictly typed command-line arguments parser powered by Zod.",
5
5
  "author": "Ahmed ALABSI <alabsi91@gmail>",
6
6
  "license": "MIT",
@@ -174,7 +174,7 @@ export function generateZshAutocompleteScript(...params: [Cli, ...Subcommand[]])
174
174
  return `${subcommand.name})
175
175
  _arguments \\
176
176
  ${genArguments(options)} \\
177
- '1: :_files' \\
177
+ '*: :_files' \\
178
178
  && ret=0
179
179
  ;;`;
180
180
  };
@@ -193,7 +193,9 @@ _${cli.cliName}_autocomplete() {
193
193
  case "$words[1]" in
194
194
  ${subcommands.map(genSubCommand).filter(Boolean).join("\n ")}
195
195
  *)
196
- _message "No options available for this command"
196
+ _arguments \
197
+ '*: :_files' \
198
+ && ret=0
197
199
  ;;
198
200
  esac
199
201
  ;;
package/src/index.ts CHANGED
@@ -79,6 +79,10 @@ export { printCliHelp, printSubcommandHelp };
79
79
 
80
80
  export { parse, safeParse } from "./parser.js";
81
81
 
82
- export { generateBashAutocompleteScript, generatePowerShellAutocompleteScript } from "./autocomplete.js";
82
+ export {
83
+ generateBashAutocompleteScript,
84
+ generateZshAutocompleteScript,
85
+ generatePowerShellAutocompleteScript,
86
+ } from "./autocomplete.js";
83
87
 
84
88
  export type * from "./types.js";