zod-args-parser 1.0.11 → 1.0.13

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,a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AG,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,U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a,CAAI1B,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":[]}
@@ -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,U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,CAC9B,CAAC,CAED,KAAM,CAAAc,aAAa,CAAIzB,UAAsB,EAAK,CAChD,KAAM,CAAAE,OAAO,CAAGF,UAAU,CAACE,OAAO,CAClC,GAAI,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,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
+ {"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,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,CAAC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C3E;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
- {"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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod-args-parser",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
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
  ;;