@politty/zod 0.3.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/{arg-registry-DdEs3jd0.d.ts → arg-registry-Dvi0co21.d.ts} +9 -2
- package/dist/argv-parser-CawJSYjw.js +1 -0
- package/dist/augment.d.ts +4 -2
- package/dist/cli-main-C7vClSAF.js +2 -0
- package/dist/cli-main-dbj7bXjm.js +1 -0
- package/dist/cli-run-CitZgzLl.js +1 -0
- package/dist/cli.js +1 -1
- package/dist/completion-CizQSJgq.js +1 -0
- package/dist/completion-nNzHfI1i.js +116 -0
- package/dist/completion.d.ts +2 -2
- package/dist/completion.js +1 -1
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +47 -47
- package/dist/dynamic-DG-l9V-y.js +1 -0
- package/dist/dynamic-DbvYJg3o.js +6 -0
- package/dist/field-meta-D9ySul7J.js +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +1 -1
- package/dist/log-collector-uhRWYT-z.js +1 -0
- package/dist/prompt-clack.d.ts +1 -1
- package/dist/prompt-clack.js +1 -1
- package/dist/prompt-inquirer.d.ts +1 -1
- package/dist/prompt-inquirer.js +1 -1
- package/dist/prompt.d.ts +1 -1
- package/dist/prompt.js +1 -1
- package/dist/register-TbOCQNeI.js +1 -0
- package/dist/runner-BKyUtmoD.js +1 -0
- package/dist/runner-CBG2DbVY.js +30 -0
- package/dist/schema-extractor-fZZ2_WAZ.js +1 -0
- package/dist/{schema-ohwvrBGz.js → schema-tWeEQULd.js} +1 -1
- package/dist/skill.d.ts +3 -3
- package/dist/skill.js +2 -2
- package/dist/{subcommand-router-D8GTMXYL.js → subcommand-router-DR2KBQAt.js} +1 -1
- package/dist/{with-completion-command-Bi7v_Wlq.d.ts → with-completion-command-BKHwbzEc.d.ts} +1 -1
- package/dist/{with-completion-command-CZ9qcezN.js → with-completion-command-DG-C9_0Z.js} +2 -2
- package/package.json +2 -2
- package/dist/cli-main-DWQYfxFO.js +0 -2
- package/dist/cli-main-X_a3vjMI.js +0 -1
- package/dist/cli-run-BfhO1D3b.js +0 -1
- package/dist/completion-CDwNvtfE.js +0 -1
- package/dist/completion-DwBjO-3Q.js +0 -116
- package/dist/dynamic-BBr42fJH.js +0 -1
- package/dist/dynamic-BK6Tq_FR.js +0 -6
- package/dist/field-meta-D7G8a7IG.js +0 -1
- package/dist/log-collector-DICKib75.js +0 -1
- package/dist/register-D0mDOOyc.js +0 -1
- package/dist/runner-DPQ3GQA7.js +0 -1
- package/dist/runner-DtJbfhOs.js +0 -30
- package/dist/schema-extractor-QpSHJvwI.js +0 -1
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./schema-extractor-QpSHJvwI.js";import{n as t}from"./command-tLHaJHe6.js";import{c as n}from"./subcommand-router-D8GTMXYL.js";import{a as r,i,n as a,o,r as s,s as c}from"./with-completion-command-CZ9qcezN.js";import{c as l,d as u,f as d,g as f,h as p,i as m,l as h,m as g,p as _,s as v,t as y,u as ee}from"./dynamic-BK6Tq_FR.js";import{existsSync as b,mkdirSync as x,readFileSync as S,realpathSync as C,renameSync as te,rmSync as ne,statSync as w,writeFileSync as re}from"node:fs";import{dirname as T,extname as ie,isAbsolute as ae,join as E,relative as oe,resolve as se}from"node:path";import{promisify as ce}from"node:util";import{execFile as le}from"node:child_process";function ue(e,t,n=[],r=!1){if(t.length===0)return;let i=de(e,n);for(let e of t)e.set(fe(e,i,r))}function de(e,t){let n=new Map,r=new Set;for(let t of[...e.options,...e.positionals])r.add(t.name);let i=(e,t)=>{for(let i of e){if(n.has(i.name)||t&&r.has(i.name))continue;let e=i.valueCompletion;e?.type===`choices`&&e.choices&&e.choices.length>0&&n.set(i.name,e.choices)}};return i([...e.options,...e.positionals],!1),i(t,!0),n}function fe(e,t,n=!1){let{spec:r}=e,i=r.dependsOn;if(i.length===0)throw Error(`Field "${e.describe}": completion.custom.expand.dependsOn must list at least one sibling arg.`);let a=[];for(let n of i){if(n===e.name)throw Error(`Field "${e.describe}": completion.custom.expand.dependsOn cannot reference the field itself ("${n}").`);let r=t.get(n);if(!r)throw Error(`Field "${e.describe}": completion.custom.expand.dependsOn references "${n}", which is not a sibling arg with a static \`choices\`/enum schema on the same command. Chaining expand specs is not supported.`);a.push([...r])}if(n)return{type:`expand`,dependsOn:i,table:[]};let o=[];for(let t of me(a)){let n={};i.forEach((e,r)=>{n[e]=t[r]});let a;try{a=r.enumerate(n)}catch(t){let r=t instanceof Error?t.message:String(t);throw Error(`Field "${e.describe}": completion.custom.expand.enumerate threw for deps=${JSON.stringify(n)}: ${r}`)}let s=pe(a);s.length!==0&&o.push({key:t,candidates:s})}return{type:`expand`,dependsOn:i,table:o}}function pe(e){let t=[],n=new Set;for(let r of e){let e=typeof r==`string`?r:r.value;if(n.has(e))continue;n.add(e);let i={value:e};typeof r!=`string`&&r.description!==void 0&&(i.description=r.description),t.push(i)}return t}function*me(e){if(e.length===0){yield[];return}let t=Array.from({length:e.length}).fill(0);for(;;){yield t.map((t,n)=>e[n][t]);let n=e.length-1;for(;n>=0&&(t[n]++,!(t[n]<e[n].length));)t[n]=0,n--;if(n<0)return}}function he(e,t,n,r){let i=v(e);if(i?.type===`pending-expand`){t.push({name:e.name,describe:n,set:r,spec:i.spec});return}i!==void 0&&r(i)}function D(e){return e.replace(/[^a-zA-Z0-9_]/g,`_`)}function O(e){let t=e.toUpperCase();return/^[A-Z_]/.test(t)?`${t}_BIN`:`_${t}_BIN`}function k(e,t,n){return`__${e}_expand_${t}__${D(n)}`}function ge(e,t){return[`__${e}_invoke_complete() {`,` local _shell="$1"; shift`,` "\${${O(e)}:-${t}}" __complete --shell "$_shell" -- "$@" 2>/dev/null`,`}`]}function A(e){return e.filter(e=>!e.name.startsWith(`__`))}function j(e){let t=[];for(let n of A(e))if(t.push({name:n.name,description:n.description}),n.aliases)for(let e of n.aliases)t.push({name:e,description:n.description});return t}function _e(e,t){let n=e.type===`boolean`&&e.negation===!0,r={name:e.name,cliName:e.cliName,alias:e.alias,negation:e.negationDisplay,negationDescription:e.negationDescription,description:e.description,takesValue:e.type!==`boolean`,valueType:e.type,required:e.required,defaultNegationAccepted:n};return he(e,t,`--${e.cliName}`,e=>{r.valueCompletion=e}),r}function ve(t){return t.args?e(t.args).fields.filter(e=>e.positional):[]}function ye(e,t){return e.filter(e=>!e.positional).map(e=>_e(e,t))}function be(e,t){return e.filter(e=>e.positional).map((e,n)=>{let r={name:e.name,cliName:e.cliName,position:n,description:e.description,required:e.required,variadic:e.type===`array`};return he(e,t,`<${e.cliName}>`,e=>{r.valueCompletion=e}),r})}function xe(t,r,i=[],a=!1){let o=[];if(r.subCommands)for(let[e,t]of Object.entries(r.subCommands)){let r=n(t);r?o.push(xe(e,r,i,a)):o.push({name:e,description:`(lazy loaded)`,subcommands:[],options:[],positionals:[]})}let s=[],c=r.args?e(r.args).fields:[],l={name:t,description:r.description,aliases:r.aliases,subcommands:o,options:ye(c,s),positionals:be(c,s)};return ue(l,s,i,a),l}function M(e,t,n){return e?`${e}${n}${t}`:t}function Se(e,t){let n=[t.name,...t.aliases??[]];return e.flatMap(e=>n.map(t=>M(e,t,`:`)))}function Ce(e,t){let n=[],r=A(e.subcommands).length>0;for(let i of e.options){if(!i.takesValue)continue;let a=r&&i.isGlobal===!0?h(i.cliName,i.alias):P(i,e.options);a.length!==0&&n.push({parentPath:t,tokens:a})}for(let r of A(e.subcommands))for(let e of[r.name,...r.aliases??[]])n.push(...Ce(r,M(t,e,`:`)));return n}function we(e,t){return Ce(e,t).map(e=>` ${e.tokens.map(t=>`${e.parentPath}:${t}`).join(`|`)}) return 0 ;;`)}function N(e,t=``,n=``){let r=[];for(let i of A(e.subcommands)){let e=M(n,D(i.name),`_`);for(let n of[i.name,...i.aliases??[]]){let a=M(t,n,`:`);r.push(...N(i,a,e)),r.push({pathStr:a,funcSuffix:e,lookupPattern:`${t}:${n}`})}}return r}function Te(e){return e.map(e=>` ${e.lookupPattern}) return 0 ;;`)}function Ee(e,t){return e.map(e=>` ${e.pathStr}) __${t}_complete_${e.funcSuffix} ;;`)}function De(e,t){let n=e.isGlobal?`_global_arg_values`:`_arg_values`;return t===`bash`?`${n}_${D(e.fieldName)}="$3"`:`${n}[${e.fieldName}]="$3"`}function Oe(e,t){let n=[];for(let r of e){if(r.isPositional||!r.optionTokens||r.optionTokens.length===0)continue;let e=r.pathStrs.flatMap(e=>r.optionTokens.map(t=>`${e}:${t}`)).join(`|`);n.push(` ${e}) ${De(r,t)} ;;`)}return n}function ke(e,t){let n=[];for(let r of e){if(!r.isPositional)continue;let e=r.pathStrs.map(e=>`${e}:${r.position}`).join(`|`);n.push(` ${e}) ${De(r,t)} ;;`)}return n}function Ae(e,t){let n=[];for(let r of e){if(r.optionTokens.length===0)continue;let e=r.pathStrs.flatMap(e=>r.optionTokens.map(t=>`${e}:${t}`)).join(`|`),i=D(r.fieldName),a=r.isGlobal?`_global_used_field_keys`:`_used_field_keys`,o=t===`bash`?`${a}_${i}`:`${a}[${i}]`,s=t===`bash`?`_global_arr_seen_${i}`:`_global_arr_seen[${i}]`,c=`${o}=" $_k "`,l=`${o}+=" $_k "`,u=`${s}=1`;n.push(` ${e})`),n.push(` if [[ "$3" == *=* ]]; then`),n.push(' local _k="${3%%=*}"'),r.isGlobal?(n.push(` if [[ -n "$_k" ]]; then`),n.push(` if [[ -z "\${${s}:-}" ]]; then`),n.push(` ${c}`),n.push(` ${u}`),n.push(` else`),n.push(` ${l}`),n.push(` fi`),n.push(` fi`)):n.push(` [[ -n "$_k" ]] && ${l}`),n.push(` fi`),n.push(` ;;`)}return n}function P(e,t){let n=h(e.cliName,e.alias);if(e.isGlobal===!0){let e=new Set;for(let n of t)if(n.isGlobal!==!0)for(let t of u(n.cliName,n.alias))e.add(t);return n.filter(t=>!e.has(t))}let r=ee(t);return r.size===0?n:n.filter(t=>!t.startsWith(`-`)||t.startsWith(`--`)||!r.has(t)?!0:e.alias?.includes(t.slice(1))===!0)}function je(e){let t=[];return Me(e,[],[``],[],`root`,t),t}function Me(e,t,n,r,i,a){let o=n[0];for(let s of e.options){let c=s.valueCompletion;if(c?.type===`expand`){let l=s.valueType===`array`;a.push({path:t,pathStr:o,pathStrs:n,intermediatePathStrs:r,funcSuffix:i,fieldName:s.name,isGlobal:s.isGlobal===!0,isPositional:!1,isArrayOption:l,optionTokens:l?P(s,e.options):[],vc:c})}}for(let s of e.positionals){let e=s.valueCompletion;e?.type===`expand`&&a.push({path:t,pathStr:o,pathStrs:n,intermediatePathStrs:r,funcSuffix:i,fieldName:s.name,isGlobal:!1,isPositional:!0,isArrayOption:!1,optionTokens:[],vc:e})}for(let o of A(e.subcommands))Me(o,[...t,o.name],Se(n,o),[...r,...n],i===`root`?D(o.name):`${i}_${D(o.name)}`,a)}function Ne(e,t,n=[]){let r=Pe(e),i=new Map,a=(e,t,n)=>{let r=i.get(e);r||(r={ref:t,pathStrs:[],seen:new Set},i.set(e,r));for(let e of n)r.seen.has(e)||(r.seen.add(e),r.pathStrs.push(e))},o=(e,t,n)=>{let i=new Map,a=(e,t)=>{if(t.length===0)return;let n=t.join(` `),r=i.get(n);r||(r={tokens:t,paths:[]},i.set(n,r)),r.paths.push(e)};for(let n of t){let t=r.get(n);if(!t)continue;let i=new Set;for(let e of t.options)if(e.isGlobal!==!0)for(let t of u(e.cliName,e.alias))i.add(t);a(n,e.filter(e=>!i.has(e)))}for(let t of n)a(t,e);return i},s=(e,t,n)=>{let r=h(t.cliName,t.alias),i=o(r,n.pathStrs,n.intermediatePathStrs);for(let[t,n]of i)a(`g::${e}::${t}`,{fieldName:e,isGlobal:!0,isPositional:!1,optionTokens:n.tokens},n.paths)};for(let e of t){let t=r.get(e.pathStr);if(t)for(let r of e.vc.dependsOn){if(e.isGlobal){let t=n.find(e=>e.name===r);if(!t)continue;s(r,t,e);continue}let i=t.positionals.findIndex(e=>e.name===r);if(i>=0){a(`lp::${e.pathStr}::${r}`,{fieldName:r,isGlobal:!1,isPositional:!0,position:i},e.pathStrs);continue}let o=t.options.find(e=>e.name===r);if(o){if(o.isGlobal===!0){s(r,o,e);continue}a(`lo::${e.pathStr}::${r}`,{fieldName:r,isGlobal:!1,isPositional:!1,optionTokens:P(o,t.options)},e.pathStrs)}}}let c=[];for(let e of i.values())e.pathStrs.length!==0&&c.push({...e.ref,pathStr:e.pathStrs[0],pathStrs:e.pathStrs});return c}function Pe(e){let t=new Map,n=(e,r)=>{for(let n of r)t.set(n,e);for(let t of A(e.subcommands))n(t,Se(r,t))};return n(e,[``]),t}function F(e){for(let t of e.options)if(t.valueCompletion?.type===`dynamic`)return!0;for(let t of e.positionals)if(t.valueCompletion?.type===`dynamic`)return!0;for(let t of e.subcommands)if(F(t))return!0;return!1}function Fe(e,t){let n=new Set(e.options.map(e=>e.name)),r=t.filter(e=>!n.has(e.name));e.options=[...e.options,...r];for(let n of e.subcommands)Fe(n,t)}function I(t,n,r,i=!1){let a=[];if(r){let t=[];a=ye(e(r).fields,t).map(e=>(e.isGlobal=!0,e)),ue({name:n,subcommands:[],options:a,positionals:[]},t,[],i)}let o=xe(n,t,a,i);return r?Fe(o,a):a=o.options,{command:o,programName:n,globalOptions:a}}function L(e){try{return Math.floor(w(e).mtimeMs/1e3).toString()}catch{return`0`}}function Ie(e){return e.replace(/\r?\n/g,` `)}function Le(e){if(!e||/[/\\\0]/.test(e))return null;let t=process.env.PATH??``;for(let n of t.split(`:`)){if(!n)continue;let t=E(n,e);try{if(w(t).isFile())return t}catch{}}return null}function R(e,t){return t||process.env[O(D(e))]||(Le(e)??process.argv[1]??``)}function z(e){let t=R(e.programName,e.binPath),n=[`# politty-completion-version: 1`,`# politty-bin-sig: ${L(t)}`,`# politty-bin-path: ${Ie(t)}`,`# program: ${e.programName}`];return e.programVersion&&n.push(`# program-version: ${e.programVersion}`),n.push(`# shell: ${e.shell}`),n}function Re(e){let{programName:t,binPath:n}=e,r=D(t),i=O(r),a=R(t,n),o=L(a),s=p(a),c=`__${r}_self_refresh`;return[`${c}() {`,` local _self _bin _sig`," _self=${BASH_SOURCE[0]:-}",` [[ -n "$_self" && -f "$_self" ]] || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qF "# politty-completion-version:" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# program: ${t}" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# shell: bash" || return 1`,` _bin="\${${i}:-$(type -P ${t} 2>/dev/null)}"`,` [[ -n "$_bin" ]] || return 1`,` _sig=${f(`$_bin`,{shell:`posix`})} || return 1`,` [[ "$_sig" != "${o}" || "$_bin" != ${s} ]] || return 1`,` "$_bin" __refresh-completion bash "$_self" --static 2>/dev/null || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-sig: $_sig" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-path: $_bin" || return 1`,` source "$_self" 2>/dev/null || return 1`,` return 0`,`}`,`if ${c}; then`,` unset -f ${c}`,` return 0 2>/dev/null || true`,`else`,` unset -f ${c}`,`fi`,``]}function ze(e){let{programName:t,binPath:n}=e,r=D(t),i=O(r),a=`_${t}`,o=R(t,n),s=L(o),c=p(o),l=`__${r}_self_refresh`;return[`${l}() {`,` emulate -L zsh`,` setopt local_options no_aliases`,` local _self _bin _sig`,' _self="${(%):-%x}"',` [[ -n "$_self" && -f "$_self" ]] || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qF "# politty-completion-version:" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# program: ${t}" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# shell: zsh" || return 1`,` _bin="\${${i}:-$(whence -p ${t} 2>/dev/null)}"`,` [[ -n "$_bin" ]] || return 1`,` _sig=${f(`$_bin`,{shell:`posix`})} || return 1`,` [[ "$_sig" != "${s}" || "$_bin" != ${c} ]] || return 1`,` "$_bin" __refresh-completion zsh "$_self" --static 2>/dev/null || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-sig: $_sig" || return 1`,` head -n 8 "$_self" 2>/dev/null | grep -qxF "# politty-bin-path: $_bin" || return 1`,` source "$_self" 2>/dev/null || return 1`,` ${a} "$@"`,` return 0`,`}`,`if ${l} "$@"; then`,` unfunction ${l} 2>/dev/null`,` return 0 2>/dev/null || true`,`else`,` unfunction ${l} 2>/dev/null`,`fi`,``]}function Be(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`).replace(/`/g,"\\`")}function Ve(e){let t=``,n=new TextEncoder().encode(e);for(let e of n)t+=e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122?String.fromCharCode(e):`_${e.toString(16).toUpperCase().padStart(2,`0`)}`;return t}function He(e,t,n,r){if(!e)return[];switch(e.type){case`expand`:{if(!r)throw Error(`bashValueLines: expand variant requires a location`);let e=k(n,r.funcSuffix,r.fieldName),i=[`local _enc_key='' _enc_v`];r.resolvedDeps.forEach((e,t)=>{let r=D(e.name),a=e.isGlobal?`_global_arg_values_${r}`:`_arg_values_${r}`;i.push(`_enc_v="\${${a}:-}"`),i.push(t===0?`_enc_key="$(__${n}_enc "$_enc_v")"`:`_enc_key+="_$(__${n}_enc "$_enc_v")"`)});let a=t?'"${_inline_prefix}${_c}"':`"$_c"`,o=r.isGlobal?`\${_global_used_field_keys_${D(r.fieldName)}:-}`:`\${_used_field_keys_${D(r.fieldName)}:-}`,s=r.isArrayOption?[` if [[ -n "$_ck" && " ${o} " == *" $_ck "* ]]; then continue; fi`]:[];return[`compopt +o default 2>/dev/null`,...i,`local _varname=${e}__\${_enc_key}`,'local _raw="${!_varname:-}"',`if [[ -n "$_raw" ]]; then`,` local -a _vals=()`,` local _line`,` while IFS= read -r _line; do _vals+=("$_line"); done <<< "$_raw"`,` local _c _ck _seen_keys=" " _had_key=0`,' for _c in "${_vals[@]}"; do',` [[ -z "$_c" ]] && continue`,` if [[ "$_c" == *=* ]]; then`,' _ck="${_c%%=*}"',...s,` if [[ "$_cur" != *=* ]]; then`,` [[ "$_seen_keys" == *" $_ck "* ]] && continue`,` _seen_keys+="$_ck "`,' _c="${_ck}="',` _had_key=1`,` elif [[ "$_c" != *=?* ]]; then`,` continue`,` fi`,` fi`,` [[ "$_c" == "$_cur"* ]] && COMPREPLY+=(${a})`,` done`,` if (( _had_key )); then compopt -o nospace 2>/dev/null; fi`,`fi`,'if (( ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi']}case`dynamic`:return[`local _dyn_out`,`_dyn_out=$(__${n}_invoke_complete bash "\${_words[@]}")`,`__${n}_apply_dynamic_output "$_dyn_out"`];case`choices`:{let n=[`local -a _choices=(${e.choices.map(e=>`"${Be(e)}"`).join(` `)})`,`COMPREPLY=()`,'local _c; for _c in "${_choices[@]}"; do [[ "$_c" == "$_cur"* ]] && COMPREPLY+=("${_inline_prefix}${_c}"); done'];return t&&n.push(`compopt -o nospace`),n.push(`compopt +o default 2>/dev/null`),n}case`file`:return e.matcher?.length?Ue(e.matcher.map(e=>`[[ "\${_f##*/}" == ${e} ]]`).join(` || `)):e.extensions?.length?Ue(e.extensions.map(e=>`[[ "$_f" == *".${e}" ]]`).join(` || `)):[`COMPREPLY=($(compgen -P "$_inline_prefix" -f -- "$_cur"))`,`compopt -o filenames`];case`directory`:return[`COMPREPLY=($(compgen -P "$_inline_prefix" -d -- "$_cur"))`,`compopt -o filenames`];case`command`:return[`COMPREPLY=($(compgen -P "$_inline_prefix" -W "$(${e.shellCommand})" -- "$_cur"))`];case`none`:return[`compopt +o default 2>/dev/null`];case`runtime-expand`:return[]}}function B(e){return`unset $(compgen -v ${e} 2>/dev/null) 2>/dev/null`}function Ue(e){return[`local -a _all_entries=($(compgen -f -- "$_cur"))`,'for _f in "${_all_entries[@]}"; do',` if [[ -d "$_f" ]]; then`,' COMPREPLY+=("${_inline_prefix}$_f")',` elif ${e}; then`,' COMPREPLY+=("${_inline_prefix}$_f")',` fi`,`done`,`compopt -o filenames`,`compopt +o default 2>/dev/null`]}function We(e,t,n,r,i){let a=[];for(let o of e){if(!o.takesValue||!o.valueCompletion)continue;let s=He(o.valueCompletion,n,r,{funcSuffix:i,...d(o,e,t)});if(s.length===0)continue;let c=P(o,e);if(c.length!==0){a.push(` ${c.join(`|`)})`);for(let e of s)a.push(` ${e}`);a.push(` return ;;`)}}return a}function V(e,t,n,r=[]){if(e.length===0)return[];let i=[];i.push(` case "$_pos_count" in`);for(let a of e){a.variadic?i.push(` ${a.position}|*)`):i.push(` ${a.position})`);for(let o of He(a.valueCompletion,!1,t,{funcSuffix:n,..._(a,r,e)}))i.push(` ${o}`);i.push(` ;;`)}return i.push(` esac`),i}function Ge(e,t,n,r,i){let a=[`COMPREPLY=($(compgen -W "${e}" -- "$_cur"))`,`compopt +o default 2>/dev/null`];return t.length===0?a:[`local -a _sub_names=(${e})`,`local _sub_name _sub_match=0`,'for _sub_name in "${_sub_names[@]}"; do',` [[ "$_sub_name" == "$_cur"* ]] && _sub_match=1 && break`,`done`,`if (( _sub_match )); then`,...a.map(e=>` ${e}`),`else`,...V(t,n,r,i),`fi`]}function Ke(e,t,n,r){if(!e.some(e=>e.takesValue&&e.valueCompletion))return[];let i=[],a=We(e,t,!1,n,r);a.length>0&&(i.push(` if [[ -z "$_inline_prefix" ]]; then`),i.push(` case "$_prev" in`),i.push(...a),i.push(` esac`),i.push(` fi`));let o=We(e,t,!0,n,r);return o.length>0&&(i.push(` if [[ -n "$_inline_prefix" ]]; then`),i.push(' case "${_inline_prefix%=}" in'),i.push(...o),i.push(` esac`),i.push(` fi`)),i}function qe(e,t){let n=[];for(let r of e){if(r.valueType===`array`){n.push(` _avail+=(--${r.cliName})`);continue}let i=g(r.cliName,r.alias,r.negation,{isGlobal:r.isGlobal===!0,frameOptions:e}),a=`__${t}_not_used ${i.join(` `)}`,o=r.negation?[r.cliName,r.negation]:[r.cliName];for(let e of o)i.includes(`"--${e}"`)&&n.push(` ${a} && _avail+=(--${e})`)}return n.push(` if (( ! _any_opt_used )); then`),n.push(` _avail+=(--help --help-all --help-json)`),n.push(` fi`),n}function Je(e,t,n){let r=[...n,e.name],i=r.map(D).join(`_`),a=`__${t}_complete_${i}`,o=A(e.subcommands),s=[];for(let e of o)s.push(...Je(e,t,r));s.push(`${a}() {`),s.push(...Ke(e.options,e.positionals,t,i));let c=r.join(`:`);if(s.push(` if [[ -z "$_inline_prefix" ]] && __${t}_opt_takes_value "${c}" "$_prev"; then return; fi`),s.push(` if [[ -n "$_inline_prefix" ]] && __${t}_opt_takes_value "${c}" "\${_inline_prefix%=}"; then return; fi`),e.positionals.length>0?(s.push(` if (( _after_dd )); then`),s.push(...V(e.positionals,t,i,e.options).map(e=>` ${e}`)),s.push(` return`),s.push(` fi`)):s.push(` if (( _after_dd )); then return; fi`),s.push(` if [[ "$_cur" == -* ]]; then`),s.push(` local -a _avail=()`),s.push(...qe(e.options,t)),s.push(' COMPREPLY=($(compgen -W "${_avail[*]}" -- "$_cur"))'),s.push(` compopt +o default 2>/dev/null`),s.push(` return`),s.push(` fi`),o.length>0){let n=j(e.subcommands).map(e=>e.name).join(` `);s.push(...Ge(n,e.positionals,t,i,e.options).map(e=>` ${e}`))}else e.positionals.length>0&&s.push(...V(e.positionals,t,i,e.options));return s.push(`}`),s.push(``),s}function Ye(e,t){let{programName:n}=t,r=I(e,n,t.globalArgsSchema),i=D(n),a=t.staticWorker?`${i}_${D(t.staticWorker.functionSuffix)}`:i,o=t.staticWorker!==void 0,s=r.command,c=A(s.subcommands),u=je(s),d=Ne(s,u,r.globalOptions),f=[];f.push(...z({programName:n,shell:`bash`,binPath:t.binPath,programVersion:t.programVersion})),f.push(`# politty-completion-mode: ${o?`worker`:`static`}`),o&&f.push(`# politty-completion-worker: true`),f.push(`# Generated by politty`),f.push(``),o||f.push(...Re({programName:n,binPath:t.binPath}));let p=u.length>0,h=u.filter(e=>e.isArrayOption),g=h.length>0;p&&(f.push(`__${a}_enc() {`),f.push(` local LC_ALL=C`),f.push(` local _s=$1 _r='' _c _i`),f.push(" for (( _i=0; _i<${#_s}; _i++ )); do"),f.push(" _c=${_s:_i:1}"),f.push(` case "$_c" in`),f.push(` [a-zA-Z0-9]) _r+="$_c" ;;`),f.push(` *) printf -v _r '%s_%02X' "$_r" "'$_c" ;;`),f.push(` esac`),f.push(` done`),f.push(` printf '%s' "$_r"`),f.push(`}`),f.push(``));for(let e of u){let t=k(a,e.funcSuffix,e.fieldName);for(let n of e.vc.table){let e=n.key.map(Ve).join(`_`),r=n.candidates.map(e=>e.value).join(`
|
|
2
|
-
`);f.push(`${t}__${e}=${l(r)}`)}f.push(``)}F(s)&&(f.push(...ge(a,n)),f.push(``),f.push(`__${a}_apply_dynamic_output() {`),f.push(` local _raw="$1"`),f.push(` COMPREPLY=()`),f.push(` local _directive=0`),f.push(` local -a _lines=()`),f.push(` local _line`),f.push(` while IFS= read -r _line; do _lines+=("$_line"); done <<< "$_raw"`),f.push(" local _last=$((${#_lines[@]} - 1))"),f.push(' if (( _last >= 0 )) && [[ "${_lines[$_last]}" =~ ^:[0-9]+$ ]]; then'),f.push(' _directive="${_lines[$_last]#:}"'),f.push(` unset '_lines[_last]'`),f.push(` fi`),f.push(' for _line in "${_lines[@]}"; do'),f.push(` [[ -z "$_line" ]] && continue`),f.push(` COMPREPLY+=("$_line")`),f.push(` done`),f.push(' local _ip="${_inline_prefix:-}"'),f.push(` if (( _directive & ${m.DirectoryCompletion} )); then`),f.push(` compopt +o default 2>/dev/null`),f.push(` compopt -o filenames 2>/dev/null`),f.push(` local _d`),f.push(' while IFS= read -r _d; do COMPREPLY+=("${_ip}${_d}"); done < <(compgen -d -- "$_cur")'),f.push(' if (( ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),f.push(` elif (( _directive & ${m.FileCompletion} )); then`),f.push(' if (( ${#COMPREPLY[@]} > 0 )) || [[ -n "$_ip" ]]; then'),f.push(` compopt -o filenames 2>/dev/null`),f.push(` local _f`),f.push(' while IFS= read -r _f; do COMPREPLY+=("${_ip}${_f}"); done < <(compgen -f -- "$_cur")'),f.push(` else`),f.push(` compopt -o default 2>/dev/null`),f.push(` fi`),f.push(` else`),f.push(` if (( _directive & ${m.NoFileCompletion} )); then`),f.push(` compopt +o default 2>/dev/null`),f.push(' if (( ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),f.push(` fi`),f.push(` fi`),f.push(` if (( _directive & ${m.NoSpace} )); then`),f.push(` compopt -o nospace 2>/dev/null`),f.push(` fi`),f.push(`}`),f.push(``)),f.push(`__${a}_not_used() {`),f.push(' for _u in "${_used_opts[@]}"; do'),f.push(` for _chk in "$@"; do`),f.push(` [[ "$_u" == "$_chk" ]] && return 1`),f.push(` done`),f.push(` done`),f.push(` return 0`),f.push(`}`),f.push(``),f.push(`__${a}_opt_takes_value() {`),f.push(` case "$1:$2" in`),f.push(...we(s,``)),f.push(` esac`),f.push(` return 1`),f.push(`}`),f.push(``),p&&(f.push(`__${a}_track_opt() {`),f.push(` case "$1:$2" in`),f.push(...Oe(d,`bash`)),f.push(` esac`),f.push(`}`),f.push(``),f.push(`__${a}_track_pos() {`),f.push(` case "$1:$2" in`),f.push(...ke(d,`bash`)),f.push(` esac`),f.push(`}`),f.push(``)),g&&(f.push(`__${a}_track_array_expand() {`),f.push(` case "$1:$2" in`),f.push(...Ae(h,`bash`)),f.push(` esac`),f.push(`}`),f.push(``));let _=N(s);_.length>0&&(f.push(`__${a}_is_subcmd() {`),f.push(` case "$1:$2" in`),f.push(...Te(_)),f.push(` esac`),f.push(` return 1`),f.push(`}`),f.push(``));for(let e of c)f.push(...Je(e,a,[]));if(f.push(`__${a}_complete_root() {`),f.push(...Ke(s.options,s.positionals,a,`root`)),f.push(` if [[ -z "$_inline_prefix" ]] && __${a}_opt_takes_value "" "$_prev"; then return; fi`),f.push(` if [[ -n "$_inline_prefix" ]] && __${a}_opt_takes_value "" "\${_inline_prefix%=}"; then return; fi`),s.positionals.length>0?(f.push(` if (( _after_dd )); then`),f.push(...V(s.positionals,a,`root`,s.options).map(e=>` ${e}`)),f.push(` return`),f.push(` fi`)):f.push(` if (( _after_dd )); then return; fi`),f.push(` if [[ "$_cur" == -* ]]; then`),f.push(` local -a _avail=()`),f.push(...qe(s.options,a)),f.push(' COMPREPLY=($(compgen -W "${_avail[*]}" -- "$_cur"))'),f.push(` compopt +o default 2>/dev/null`),c.length>0){f.push(` else`);let e=j(s.subcommands).map(e=>e.name).join(` `);f.push(...Ge(e,s.positionals,a,`root`,s.options).map(e=>` ${e}`))}else s.positionals.length>0&&(f.push(` else`),f.push(...V(s.positionals,a,`root`,s.options).map(e=>` ${e}`)));f.push(` fi`),f.push(`}`),f.push(``);let v=Ee(_,a).join(`
|
|
3
|
-
`);f.push(`_${a}_completions() {`),f.push(` COMPREPLY=()`),f.push(``),f.push(` # Rejoin words split by '=' in COMP_WORDBREAKS`),f.push(` local -a _words=()`),f.push(` local _i=1`),f.push(` while (( _i <= COMP_CWORD )); do`),f.push(' if [[ "${COMP_WORDS[_i]}" == "=" && ${#_words[@]} -gt 0 ]]; then'),f.push(' _words[${#_words[@]}-1]+="=${COMP_WORDS[_i+1]:-}"'),f.push(` (( _i += 2 ))`),f.push(` else`),f.push(' _words+=("${COMP_WORDS[_i]}")'),f.push(` (( _i++ ))`),f.push(` fi`),f.push(` done`),f.push(``),f.push(` local _cur=""`),f.push(' (( ${#_words[@]} > 0 )) && _cur="${_words[${#_words[@]}-1]}"'),f.push(` local _inline_prefix=""`),f.push(``),f.push(` local _prev=""`),f.push(' (( ${#_words[@]} > 1 )) && _prev="${_words[${#_words[@]}-2]}"'),f.push(``),f.push(` local _subcmd="" _after_dd=0 _pos_count=0 _skip_next=0`),f.push(` local -a _used_opts=()`),f.push(` local _any_opt_used=0`),p&&(f.push(` ${B(`_arg_values_`)}`),f.push(` ${B(`_global_arg_values_`)}`)),g&&(f.push(` ${B(`_used_field_keys_`)}`),f.push(` ${B(`_global_used_field_keys_`)}`),f.push(` ${B(`_global_arr_seen_`)}`)),f.push(``),f.push(` local _j=0`),f.push(" while (( _j < ${#_words[@]} - 1 )); do"),f.push(' local _w="${_words[_j]}"'),f.push(` if (( _skip_next )); then _skip_next=0; (( _j++ )); continue; fi`),f.push(` if [[ "$_w" == "--" ]]; then _after_dd=1; (( _j++ )); continue; fi`);let y=p?`__${a}_track_pos "$_subcmd" "$_pos_count" "$_w"; `:``;f.push(` if (( _after_dd )); then ${y}(( _pos_count++ )); (( _j++ )); continue; fi`),f.push(` if [[ "$_w" == -*=* ]]; then`),f.push(' _used_opts+=("${_w%%=*}")'),f.push(` _any_opt_used=1`),p&&(f.push(` __${a}_track_opt "$_subcmd" "\${_w%%=*}" "\${_w#*=}"`),g&&f.push(` __${a}_track_array_expand "$_subcmd" "\${_w%%=*}" "\${_w#*=}"`)),f.push(` (( _j++ )); continue`),f.push(` fi`),f.push(` if [[ "$_w" == -* ]]; then`),f.push(` _used_opts+=("$_w")`),f.push(` _any_opt_used=1`),f.push(` if __${a}_opt_takes_value "$_subcmd" "$_w"; then`),f.push(' local _next="${_words[_j+1]:-}"'),f.push(` if [[ -n "$_next" && "$_next" != -* ]]; then _skip_next=1; fi`),p&&(f.push(` if (( _skip_next )); then`),f.push(` __${a}_track_opt "$_subcmd" "$_w" "$_next"`),g&&(f.push(" if (( _j + 2 < ${#_words[@]} )); then"),f.push(` __${a}_track_array_expand "$_subcmd" "$_w" "$_next"`),f.push(` fi`)),f.push(` fi`)),f.push(` fi`),f.push(` (( _j++ )); continue`),f.push(` fi`);let ee=g?`; ${B(`_arg_values_`)}; ${B(`_used_field_keys_`)}; ${B(`_global_arr_seen_`)}`:p?`; ${B(`_arg_values_`)}`:``,b=p?`__${a}_track_pos "$_subcmd" "$_pos_count" "$_w"; `:``;return _.length>0?f.push(` if __${a}_is_subcmd "$_subcmd" "$_w"; then _subcmd="\${_subcmd:+\${_subcmd}:}$_w"; _used_opts=(); _pos_count=0${ee}; else ${b}(( _pos_count++ )); fi`):(p&&f.push(` __${a}_track_pos "$_subcmd" "$_pos_count" "$_w"`),f.push(` (( _pos_count++ ))`)),f.push(` (( _j++ ))`),f.push(` done`),f.push(``),f.push(` if (( ! _after_dd )) && [[ "$_cur" == -*=* ]]; then`),f.push(' _inline_prefix="${_cur%%=*}="'),f.push(' _cur="${_cur#*=}"'),f.push(` fi`),f.push(``),f.push(` case "$_subcmd" in`),f.push(v),f.push(` *) __${a}_complete_root ;;`),f.push(` esac`),f.push(`}`),f.push(``),o||f.push(`complete -o default -F _${a}_completions ${n}`),f.push(``),{script:f.join(`
|
|
4
|
-
`),shell:`bash`,installInstructions:`# To enable auto-refreshing bash completions, add this to your ~/.bashrc:
|
|
5
|
-
eval "$(${n} completion bash --static)"
|
|
6
|
-
|
|
7
|
-
# For faster shell startup, save the script instead:
|
|
8
|
-
mkdir -p ~/.local/share/bash-completion/completions
|
|
9
|
-
${n} completion bash --static > ~/.local/share/bash-completion/completions/${n}
|
|
10
|
-
|
|
11
|
-
# Then reload your shell or run:
|
|
12
|
-
source ~/.bashrc`}}const Xe=ce(le),Ze={bash:`bash`,zsh:`zsh`,fish:`fish`},Qe=[`# politty-completion-version: 1`,`# politty-completion-mode: worker`,`# politty-completion-worker: true`];function $e(e){return Ze[e]}function et(e){return E(`dist`,`completion`,`${e}-worker.${$e(e)}`)}function tt(e){let t=Ze[e];return[`completion/${e}-worker.${t}`,`../completion/${e}-worker.${t}`,`dist/completion/${e}-worker.${t}`,`../dist/completion/${e}-worker.${t}`,`completion-worker.${e}`,`../completion-worker.${e}`]}function nt(e,t,n){if(n?.disabled)return[];let r=n?.relativePaths?.[t];return(r&&r.length>0?r:tt(t)).map(n=>n.replaceAll(`{shell}`,t).replaceAll(`{ext}`,Ze[t]).replaceAll(`{program}`,e))}function rt(e){try{let t=S(e,`utf8`),n=null;for(let e of t.split(`
|
|
13
|
-
`)){let t=e.match(/^# cmd-shim-target=(.+)$/);t&&(n=t[1])}return n}catch{return null}}function H(e,t){if(!t)return;e.add(T(se(t)));try{e.add(T(C(t)))}catch{}let n=rt(t);n&&H(e,n)}function it(e){return S(e,`utf8`).split(`
|
|
14
|
-
`,24).join(`
|
|
15
|
-
`)}function at(e,t){return[...Qe,`# program: ${e}`,`# shell: ${t}`]}function ot(e,t,n){let r=e.split(`
|
|
16
|
-
`).map(e=>e.trimEnd());return at(t,n).filter(e=>!r.includes(e))}function U(e,t,n){if(!b(e))throw Error(`Bundled completion worker does not exist: ${e}`);let r=ot(it(e),t,n);if(r.length>0)throw Error(`Invalid bundled completion worker ${e}: missing ${r.map(e=>JSON.stringify(e)).join(`, `)}`)}function st(e,t,n){try{return U(e,t,n),!0}catch{return!1}}function ct(e){let t=nt(e.programName,e.shell,e.bundledWorker);if(t.length===0)return null;let n=new Set;e.binPath!==void 0&&H(n,e.binPath),process.argv[1]&&H(n,process.argv[1]),H(n,R(e.programName,e.binPath));for(let n of t)if(ae(n)&&st(n,e.programName,e.shell))return n;for(let r of n)for(let n of t){if(ae(n))continue;let t=E(r,n);if(st(t,e.programName,e.shell))return t}return null}function W(e,t){return ae(e)?e:se(t,e)}function lt(e,t,n){let r=e.startsWith(`.`)||e.includes(`/`)||e.includes(`\\`)?W(e,n):e,i=ie(r).toLowerCase();return i===`.js`||i===`.mjs`||i===`.cjs`?{command:process.execPath,args:[r,...t]}:{command:r,args:[...t]}}async function ut(e,t,n){let r=lt(e,t,n.cwd);try{let{stdout:e,stderr:t}=await Xe(r.command,r.args,{cwd:n.cwd,env:{...process.env,...n.env},encoding:`utf8`,maxBuffer:10485760});return{stdout:e,stderr:t}}catch(e){let t=typeof e==`object`&&e&&`stderr`in e?String(e.stderr??``).trim():``,n=t?`\n${t}`:``;throw Error(`Command failed: ${r.command} ${r.args.join(` `)}${n}`,e instanceof Error?{cause:e}:void 0)}}function dt(e){let t=w(e);if(!t.isFile()||t.size===0)throw Error(`Generated bundled completion worker is empty: ${e}`);return t.size}function ft(e){return e<1024?`${e} B`:`${(e/1024).toFixed(1)} KiB`}function pt(e,t,n){let r=oe(n,e);console.log(`Generated bundled completion worker: ${r&&!r.startsWith(`..`)?r:e} (${ft(t)})`)}async function mt(e){let t=e.cwd??process.cwd(),n=W(e.outputPath??et(e.shell),t);x(T(n),{recursive:!0}),ne(n,{force:!0}),await ut(e.bin,[`__refresh-completion`,e.shell,n,`--static`,`--worker`],{cwd:t,env:e.env});let r=dt(n);U(n,e.programName,e.shell);let i;if(e.verify){let r=(await ut(e.bin,[`__completion-worker-path`,e.shell],{cwd:t,env:e.env})).stdout.split(/\r?\n/).map(e=>e.trim()).filter(Boolean);if(r.length!==1)throw Error(`Expected __completion-worker-path ${e.shell} to print exactly one path, got ${r.length}.`);i=W(r[0],t);let a=C(n),o=C(i);if(o!==a)throw Error(`Bundled completion worker path mismatch: generated ${a}, reported ${o}`)}return e.quiet||pt(n,r,t),{outputPath:n,size:r,...i!==void 0&&{reportedPath:i}}}function G(e){return p(`/${e}/node-compile-cache`)}function K(e){return e?p(`${e}/node-compile-cache`):void 0}function q(e,t){return e?p(`${e}/completion-worker.${t}`):void 0}function J(e,t){return p(`/${e}/completion-worker.${t}`)}function Y(e,t,n){return t?` ${e} ${t}`:` ${e} "\${XDG_CACHE_HOME:-$HOME/.cache}"${n}`}function ht(e,t){return e?` printf '%s\\n' ${e}`:[` set -l _cache_root "$XDG_CACHE_HOME"`,` test -n "$_cache_root"; or set _cache_root "$HOME/.cache"`,` printf '%s\\n' "$_cache_root"${t}`].join(`
|
|
17
|
-
`)}function gt(e,t){return nt(e.programName,t,e.bundledWorker).map(p).join(` `)}function _t(e){return`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`)}"`}function vt(e){return nt(e.programName,`fish`,e.bundledWorker).map(_t).join(` `)}function yt(e){return e.bundledWorker?.queryCommand===!0&&!e.bundledWorker.disabled}function bt(e,t){let{programName:n}=t,r=D(n),i=`${r}_worker`,a=O(i),o=O(r),s=p(n),c=Y(`printf '%s\\n'`,K(t.cacheDir),G(n)),l=Y(`printf '%s\\n'`,q(t.cacheDir,`bash`),J(n,`bash`)),u=gt(t,`bash`),d=yt(t),h=[];return h.push(...z({programName:n,shell:`bash`,binPath:t.binPath,programVersion:t.programVersion})),h.push(`# Generated by politty`),h.push(`# politty-completion-mode: dispatcher`),h.push(``),h.push(`__${r}_resolve_bin() {`),h.push(` if [[ -n "\${${o}:-}" ]]; then`),h.push(` printf '%s\\n' "\${${o}}"`),h.push(` return 0`),h.push(` fi`),h.push(` type -P ${s} 2>/dev/null`),h.push(`}`),h.push(``),h.push(`__${r}_node_compile_cache_dir() {`),h.push(' if [[ -n "${NODE_COMPILE_CACHE:-}" ]]; then'),h.push(` printf '%s\\n' "$NODE_COMPILE_CACHE"`),h.push(` return 0`),h.push(` fi`),h.push(c),h.push(`}`),h.push(``),h.push(`__${r}_static_worker_path() {`),h.push(l),h.push(`}`),h.push(``),h.push(`__${r}_worker_file_sig() {`),h.push(` local _worker="$1" _sig`),h.push(` _sig=${f(`$_worker`,{shell:`posix`,withSize:!0})} || return 1`),h.push(` printf '%s\\n' "$_sig"`),h.push(`}`),h.push(``),h.push(`__${r}_is_worker_file() {`),h.push(` local _worker="$1" _head`),h.push(` [[ -f "$_worker" ]] || return 1`),h.push(` _head="$(head -n 24 "$_worker" 2>/dev/null)" || return 1`),h.push(` _head=$'\\n'"$_head"$'\\n'`),h.push(` [[ "$_head" == *$'\\n'"# politty-completion-version: 1"$'\\n'* ]] || return 1`),h.push(` [[ "$_head" == *$'\\n'"# program: ${n}"$'\\n'* ]] || return 1`),h.push(` [[ "$_head" == *$'\\n'"# shell: bash"$'\\n'* ]] || return 1`),h.push(` [[ "$_head" == *$'\\n'"# politty-completion-mode: worker"$'\\n'* ]] || return 1`),h.push(` [[ "$_head" == *$'\\n'"# politty-completion-worker: true"$'\\n'* ]] || return 1`),h.push(`}`),h.push(``),h.push(`__${r}_load_worker() {`),h.push(` local _worker="$1" _sig _key`),h.push(` __${r}_is_worker_file "$_worker" || return 1`),h.push(` _sig="$(__${r}_worker_file_sig "$_worker")" || return 1`),h.push(` _key="$_worker:$_sig"`),h.push(` if [[ "\${__${r}_loaded_worker_key:-}" != "$_key" ]]; then`),h.push(` source "$_worker" 2>/dev/null || return 1`),h.push(` __${r}_loaded_worker_key="$_key"`),h.push(` fi`),h.push(` declare -F _${i}_completions >/dev/null 2>&1`),h.push(`}`),h.push(``),h.push(`__${r}_realpath() {`),h.push(` local _path="$1" _dir _target _limit=0`),h.push(` while [[ -L "$_path" && $_limit -lt 40 ]]; do`),h.push(` _dir="$(cd -P "$(dirname "$_path")" 2>/dev/null && pwd)" || return 1`),h.push(` _target="$(readlink "$_path")" || return 1`),h.push(` if [[ "$_target" == /* ]]; then _path="$_target"; else _path="$_dir/$_target"; fi`),h.push(` (( _limit++ ))`),h.push(` done`),h.push(` _dir="$(cd -P "$(dirname "$_path")" 2>/dev/null && pwd)" || return 1`),h.push(` printf '%s\\n' "$_dir/$(basename "$_path")"`),h.push(`}`),h.push(``),h.push(`__${r}_worker_from_dir() {`),h.push(` local _dir="$1" _rel _candidate`),u.length>0&&(h.push(` for _rel in ${u}; do`),h.push(` [[ "$_rel" == /* ]] && _candidate="$_rel" || _candidate="$_dir/$_rel"`),h.push(` if __${r}_is_worker_file "$_candidate"; then`),h.push(` printf '%s\\n' "$_candidate"`),h.push(` return 0`),h.push(` fi`),h.push(` done`)),h.push(` return 1`),h.push(`}`),h.push(``),h.push(`__${r}_cmd_shim_target() {`),h.push(` sed -n 's/^# cmd-shim-target=//p' "$1" 2>/dev/null | tail -n 1`),h.push(`}`),h.push(``),h.push(`__${r}_bundled_worker_path() {`),h.push(' local _bin="$1" _node_compile_cache="${2:-}" _real _dir _target _reported'),h.push(` _real="$(__${r}_realpath "$_bin" 2>/dev/null)" || _real=""`),h.push(` if [[ -n "$_real" ]]; then`),h.push(` _dir="$(dirname "$_real")"`),h.push(` __${r}_worker_from_dir "$_dir" && return 0`),h.push(` fi`),h.push(` _dir="$(dirname "$_bin")"`),h.push(` __${r}_worker_from_dir "$_dir" && return 0`),h.push(` _target="$(__${r}_cmd_shim_target "$_bin")"`),h.push(` if [[ -n "$_target" ]]; then`),h.push(` _real="$(__${r}_realpath "$_target" 2>/dev/null)" || _real="$_target"`),h.push(` _dir="$(dirname "$_real")"`),h.push(` __${r}_worker_from_dir "$_dir" && return 0`),h.push(` fi`),d&&(h.push(` if [[ "\${__${r}_queried_bin:-}" == "$_bin" && -n "\${__${r}_queried_worker:-}" ]] && __${r}_is_worker_file "\${__${r}_queried_worker}"; then`),h.push(` printf '%s\\n' "\${__${r}_queried_worker}"`),h.push(` return 0`),h.push(` fi`),h.push(` _reported="$(NODE_COMPILE_CACHE="$_node_compile_cache" "$_bin" __completion-worker-path bash 2>/dev/null)" || _reported=""`),h.push(` if [[ -n "$_reported" ]] && __${r}_is_worker_file "$_reported"; then`),h.push(` __${r}_queried_bin="$_bin"`),h.push(` __${r}_queried_worker="$_reported"`),h.push(` printf '%s\\n' "$_reported"`),h.push(` return 0`),h.push(` fi`)),h.push(` return 1`),h.push(`}`),h.push(``),h.push(`__${r}_bin_sig() {`),h.push(` local _bin="$1" _sig`),h.push(` _sig=${f(`$_bin`,{shell:`posix`})} || return 1`),h.push(` printf '%s\\n' "$_sig"`),h.push(`}`),h.push(``),h.push(`__${r}_worker_matches_bin() {`),h.push(` local _worker="$1" _sig="$2" _bin="$3" _head`),h.push(` [[ -f "$_worker" ]] || return 1`),h.push(` _head="$(head -n 12 "$_worker" 2>/dev/null)" || return 1`),h.push(` grep -qxF "# politty-bin-sig: $_sig" <<< "$_head" || return 1`),h.push(` grep -qxF "# politty-bin-path: $_bin" <<< "$_head" || return 1`),h.push(`}`),h.push(``),h.push(`__${r}_apply_dynamic_output() {`),h.push(` local _raw="$1" _cur="$2" _inline_prefix="$3"`),h.push(` COMPREPLY=()`),h.push(` local _directive=0`),h.push(` local -a _lines=() _exts=() _matchers=()`),h.push(` local _line`),h.push(` while IFS= read -r _line; do _lines+=("$_line"); done <<< "$_raw"`),h.push(" local _last=$((${#_lines[@]} - 1))"),h.push(' if (( _last >= 0 )) && [[ "${_lines[$_last]}" == :[0-9]* ]]; then'),h.push(` local -a _meta=()`),h.push(` IFS=$'\\t' read -r -a _meta <<< "\${_lines[$_last]}"`),h.push(` unset '_lines[_last]'`),h.push(' _directive="${_meta[0]#:}"'),h.push(` local _m`),h.push(' for _m in "${_meta[@]:1}"; do'),h.push(` if [[ "$_m" == @ext:* ]]; then`),h.push(` IFS=',' read -r -a _exts <<< "\${_m#@ext:}"`),h.push(` elif [[ "$_m" == @matcher:* ]]; then`),h.push(` IFS=',' read -r -a _matchers <<< "\${_m#@matcher:}"`),h.push(` fi`),h.push(` done`),h.push(` fi`),h.push(' for _line in "${_lines[@]}"; do'),h.push(` [[ -z "$_line" ]] && continue`),h.push(` COMPREPLY+=("$_line")`),h.push(` done`),h.push(' local _ip="${_inline_prefix:-}"'),h.push(" if (( ${#_exts[@]} > 0 || ${#_matchers[@]} > 0 )); then"),h.push(` local _need_empty=0`),h.push(` compopt +o default 2>/dev/null || _need_empty=1`),h.push(` compopt -o filenames 2>/dev/null`),h.push(` local _f _ext _pat _base _ok`),h.push(` while IFS= read -r _f; do`),h.push(` if [[ -d "$_f" ]]; then`),h.push(' COMPREPLY+=("${_ip}${_f}")'),h.push(` continue`),h.push(` fi`),h.push(` _ok=0`),h.push(" if (( ${#_exts[@]} > 0 )); then"),h.push(' for _ext in "${_exts[@]}"; do'),h.push(` [[ -n "$_ext" && "$_f" == *."$_ext" ]] && _ok=1`),h.push(` done`),h.push(` fi`),h.push(" if (( ${#_matchers[@]} > 0 )); then"),h.push(' _base="${_f##*/}"'),h.push(' for _pat in "${_matchers[@]}"; do'),h.push(` [[ -n "$_pat" && "$_base" == $_pat ]] && _ok=1`),h.push(` done`),h.push(` fi`),h.push(' (( _ok )) && COMPREPLY+=("${_ip}${_f}")'),h.push(` done < <(compgen -f -- "$_cur")`),h.push(' if (( _need_empty && ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),h.push(` elif (( _directive & ${m.DirectoryCompletion} )); then`),h.push(` local _need_empty=0`),h.push(` compopt +o default 2>/dev/null || _need_empty=1`),h.push(` compopt -o filenames 2>/dev/null`),h.push(` local _d`),h.push(' while IFS= read -r _d; do COMPREPLY+=("${_ip}${_d}"); done < <(compgen -d -- "$_cur")'),h.push(' if (( _need_empty && ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),h.push(` elif (( _directive & ${m.FileCompletion} )); then`),h.push(` compopt -o filenames 2>/dev/null`),h.push(` local _p`),h.push(' while IFS= read -r _p; do COMPREPLY+=("${_ip}${_p}"); done < <(compgen -f -- "$_cur")'),h.push(` elif (( _directive & ${m.NoFileCompletion} )); then`),h.push(` local _need_empty=0`),h.push(` compopt +o default 2>/dev/null || _need_empty=1`),h.push(' if (( _need_empty && ${#COMPREPLY[@]} == 0 )); then COMPREPLY=( "" ); fi'),h.push(` fi`),h.push(` if (( _directive & ${m.NoSpace} )); then`),h.push(` compopt -o nospace 2>/dev/null`),h.push(` fi`),h.push(`}`),h.push(``),h.push(`_${r}_completions() {`),h.push(` COMPREPLY=()`),h.push(` local -a _words=()`),h.push(` local _i=1`),h.push(` while (( _i <= COMP_CWORD )); do`),h.push(' if [[ "${COMP_WORDS[_i]}" == "=" && ${#_words[@]} -gt 0 ]]; then'),h.push(' _words[${#_words[@]}-1]+="=${COMP_WORDS[_i+1]:-}"'),h.push(` (( _i += 2 ))`),h.push(` else`),h.push(' _words+=("${COMP_WORDS[_i]}")'),h.push(` (( _i++ ))`),h.push(` fi`),h.push(` done`),h.push(` local _cur="" _inline_prefix=""`),h.push(' (( ${#_words[@]} > 0 )) && _cur="${_words[${#_words[@]}-1]}"'),h.push(` local _after_dd=0 _di=0`),h.push(" while (( _di < ${#_words[@]} - 1 )); do"),h.push(' [[ "${_words[_di]}" == "--" ]] && { _after_dd=1; break; }'),h.push(` (( _di++ ))`),h.push(` done`),h.push(` if (( ! _after_dd )) && [[ "$_cur" == -*=* ]]; then`),h.push(' _inline_prefix="${_cur%%=*}="'),h.push(' _cur="${_cur#*=}"'),h.push(` fi`),h.push(` local _bin _out _node_compile_cache _worker _bundled_worker _sig`),h.push(` _bin="$(__${r}_resolve_bin)" || _bin=""`),h.push(` [[ -n "$_bin" ]] || return 0`),h.push(` _node_compile_cache="$(__${r}_node_compile_cache_dir)" || _node_compile_cache=""`),h.push(` _bundled_worker="$(__${r}_bundled_worker_path "$_bin" "$_node_compile_cache")" || _bundled_worker=""`),h.push(` if [[ -n "$_bundled_worker" ]] && __${r}_load_worker "$_bundled_worker"; then`),h.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${a}="$_bin" _${i}_completions`),h.push(` return 0`),h.push(` fi`),h.push(` _worker="$(__${r}_static_worker_path)" || _worker=""`),h.push(` _sig="$(__${r}_bin_sig "$_bin")" || _sig=""`),h.push(` if [[ -n "$_worker" && -n "$_sig" ]]; then`),h.push(` if ! __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin"; then`),h.push(' mkdir -p "${_worker%/*}" 2>/dev/null'),h.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${o}="$_bin" "$_bin" __refresh-completion bash "$_worker" --static --worker 2>/dev/null`),h.push(` fi`),h.push(` if __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin" && __${r}_load_worker "$_worker"; then`),h.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${a}="$_bin" _${i}_completions`),h.push(` return 0`),h.push(` fi`),h.push(` fi`),h.push(' _out=$(NODE_COMPILE_CACHE="$_node_compile_cache" "$_bin" __complete --shell bash -- "${_words[@]}" 2>/dev/null) || return 0'),h.push(` __${r}_apply_dynamic_output "$_out" "$_cur" "$_inline_prefix"`),h.push(`}`),h.push(``),h.push(`complete -o default -F _${r}_completions ${n}`),h.push(``),{script:h.join(`
|
|
18
|
-
`),shell:`bash`,installInstructions:`# To enable dispatcher bash completions, add this to your ~/.bashrc:
|
|
19
|
-
eval "$(${n} completion bash)"
|
|
20
|
-
|
|
21
|
-
# To save the dispatcher script instead:
|
|
22
|
-
mkdir -p ~/.local/share/bash-completion/completions
|
|
23
|
-
${n} completion bash > ~/.local/share/bash-completion/completions/${n}
|
|
24
|
-
|
|
25
|
-
# To generate the older static script:
|
|
26
|
-
${n} completion bash --static`}}function xt(e,t){let{programName:n}=t,r=D(n),i=`${r}_worker`,a=O(i),o=O(r),s=p(n),c=`_${n}`,l=`"\${funcstack[1]:-}" == "${c}"`,u=Y(`print -r --`,K(t.cacheDir),G(n)),d=Y(`print -r --`,q(t.cacheDir,`zsh`),J(n,`zsh`)),h=gt(t,`zsh`),g=yt(t),_=[];return _.push(`#compdef ${n}`),_.push(...z({programName:n,shell:`zsh`,binPath:t.binPath,programVersion:t.programVersion})),_.push(`# Generated by politty`),_.push(`# politty-completion-mode: dispatcher`),_.push(``),_.push(`__${r}_resolve_bin() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` if [[ -n "\${${o}:-}" ]]; then`),_.push(` print -r -- "\${${o}}"`),_.push(` return 0`),_.push(` fi`),_.push(` whence -p ${s} 2>/dev/null`),_.push(`}`),_.push(``),_.push(`__${r}_node_compile_cache_dir() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(' if [[ -n "${NODE_COMPILE_CACHE:-}" ]]; then'),_.push(` print -r -- "$NODE_COMPILE_CACHE"`),_.push(` return 0`),_.push(` fi`),_.push(u),_.push(`}`),_.push(``),_.push(`__${r}_static_worker_path() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(d),_.push(`}`),_.push(``),_.push(`__${r}_worker_file_sig() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` local _worker="$1" _sig`),_.push(` _sig=${f(`$_worker`,{shell:`posix`,withSize:!0})} || return 1`),_.push(` print -r -- "$_sig"`),_.push(`}`),_.push(``),_.push(`__${r}_is_worker_file() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` local _worker="$1" _head`),_.push(` [[ -f "$_worker" ]] || return 1`),_.push(` _head="$(<$_worker)" || return 1`),_.push(` _head=$'\\n'"$_head"$'\\n'`),_.push(` [[ "$_head" == *$'\\n'"# politty-completion-version: 1"$'\\n'* ]] || return 1`),_.push(` [[ "$_head" == *$'\\n'"# program: ${n}"$'\\n'* ]] || return 1`),_.push(` [[ "$_head" == *$'\\n'"# shell: zsh"$'\\n'* ]] || return 1`),_.push(` [[ "$_head" == *$'\\n'"# politty-completion-mode: worker"$'\\n'* ]] || return 1`),_.push(` [[ "$_head" == *$'\\n'"# politty-completion-worker: true"$'\\n'* ]] || return 1`),_.push(`}`),_.push(``),_.push(`__${r}_load_worker() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` local _worker="$1" _sig _key`),_.push(` __${r}_is_worker_file "$_worker" || return 1`),_.push(` _sig="$(__${r}_worker_file_sig "$_worker")" || return 1`),_.push(` _key="$_worker:$_sig"`),_.push(` if [[ "\${__${r}_loaded_worker_key:-}" != "$_key" ]]; then`),_.push(` source "$_worker" 2>/dev/null || return 1`),_.push(` typeset -g __${r}_loaded_worker_key="$_key"`),_.push(` fi`),_.push(` (( $+functions[_${i}_completions] ))`),_.push(`}`),_.push(``),_.push(`__${r}_realpath() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` local _path="$1"`),_.push(` [[ -n "$_path" ]] || return 1`),_.push(' print -r -- "${_path:A}"'),_.push(`}`),_.push(``),_.push(`__${r}_worker_from_dir() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` local _dir="$1" _rel _candidate`),h.length>0&&(_.push(` for _rel in ${h}; do`),_.push(` [[ "$_rel" == /* ]] && _candidate="$_rel" || _candidate="$_dir/$_rel"`),_.push(` if __${r}_is_worker_file "$_candidate"; then`),_.push(` print -r -- "$_candidate"`),_.push(` return 0`),_.push(` fi`),_.push(` done`)),_.push(` return 1`),_.push(`}`),_.push(``),_.push(`__${r}_cmd_shim_target() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` [[ -f "$1" ]] || return 0`),_.push(` local _l _t=""`),_.push(' for _l in "${(@f)$(<$1)}"; do'),_.push(' [[ "$_l" == "# cmd-shim-target="* ]] && _t="${_l#\\# cmd-shim-target=}"'),_.push(` done`),_.push(` [[ -n "$_t" ]] && print -r -- "$_t"`),_.push(`}`),_.push(``),_.push(`__${r}_bundled_worker_path() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(' local _bin="$1" _node_compile_cache="${2:-}" _real _dir _target _reported'),_.push(` _real="$(__${r}_realpath "$_bin" 2>/dev/null)" || _real=""`),_.push(` if [[ -n "$_real" ]]; then`),_.push(' _dir="${_real:h}"'),_.push(` __${r}_worker_from_dir "$_dir" && return 0`),_.push(` fi`),_.push(' _dir="${_bin:h}"'),_.push(` __${r}_worker_from_dir "$_dir" && return 0`),_.push(` _target="$(__${r}_cmd_shim_target "$_bin")"`),_.push(` if [[ -n "$_target" ]]; then`),_.push(` _real="$(__${r}_realpath "$_target" 2>/dev/null)" || _real="$_target"`),_.push(' _dir="${_real:h}"'),_.push(` __${r}_worker_from_dir "$_dir" && return 0`),_.push(` fi`),g&&(_.push(` if [[ "\${__${r}_queried_bin:-}" == "$_bin" && -n "\${__${r}_queried_worker:-}" ]] && __${r}_is_worker_file "\${__${r}_queried_worker}"; then`),_.push(` print -r -- "\${__${r}_queried_worker}"`),_.push(` return 0`),_.push(` fi`),_.push(` _reported="$(NODE_COMPILE_CACHE="$_node_compile_cache" "$_bin" __completion-worker-path zsh 2>/dev/null)" || _reported=""`),_.push(` if [[ -n "$_reported" ]] && __${r}_is_worker_file "$_reported"; then`),_.push(` typeset -g __${r}_queried_bin="$_bin"`),_.push(` typeset -g __${r}_queried_worker="$_reported"`),_.push(` print -r -- "$_reported"`),_.push(` return 0`),_.push(` fi`)),_.push(` return 1`),_.push(`}`),_.push(``),_.push(`__${r}_bin_sig() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` local _bin="$1" _sig`),_.push(` _sig=${f(`$_bin`,{shell:`posix`})} || return 1`),_.push(` print -r -- "$_sig"`),_.push(`}`),_.push(``),_.push(`__${r}_worker_matches_bin() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` local _worker="$1" _sig="$2" _bin="$3" _head`),_.push(` [[ -f "$_worker" ]] || return 1`),_.push(` _head=$'\\n'"$(<$_worker)"$'\\n'`),_.push(` [[ "$_head" == *$'\\n'"# politty-bin-sig: $_sig"$'\\n'* ]] || return 1`),_.push(` [[ "$_head" == *$'\\n'"# politty-bin-path: $_bin"$'\\n'* ]] || return 1`),_.push(`}`),_.push(``),_.push(`__${r}_cdescribe() {`),_.push(` _describe "$@" 2>/dev/null && return 0`),_.push(` shift`),_.push(` local _cd_arr="$1"`),_.push(` shift`),_.push(' local -a _cd_vals=("${(@)${(P)_cd_arr}%%:*}")'),_.push(` compadd "$@" -a _cd_vals 2>/dev/null`),_.push(` return 0`),_.push(`}`),_.push(``),_.push(`__${r}_add_path_candidate() {`),_.push(` compadd -f -- "$1" 2>/dev/null && return 0`),_.push(` print -r -- "$1"`),_.push(`}`),_.push(``),_.push(`__${r}_apply_dynamic_output() {`),_.push(` local _raw="$1"`),_.push(` local _directive=0`),_.push(` local -a _vals _lines _exts _matchers`),_.push(` local _meta`),_.push(' _lines=("${(@f)_raw}")'),_.push(` local _last=$#_lines`),_.push(' if (( _last >= 1 )) && [[ "${_lines[$_last]}" == :<->* ]]; then'),_.push(' local _dline="${_lines[$_last]}"'),_.push(` _lines[$_last]=()`),_.push(` local -a _dfields`),_.push(' _dfields=("${(@ps:\\t:)_dline}")'),_.push(' _directive="${_dfields[1]#:}"'),_.push(` local _m`),_.push(' for _m in "${(@)_dfields[2,-1]}"; do'),_.push(` if [[ "$_m" == @ext:* ]]; then`),_.push(' _meta="${_m#@ext:}"'),_.push(' _exts=("${(@s:,:)_meta}")'),_.push(` elif [[ "$_m" == @matcher:* ]]; then`),_.push(' _meta="${_m#@matcher:}"'),_.push(' _matchers=("${(@s:,:)_meta}")'),_.push(` fi`),_.push(` done`),_.push(` fi`),_.push(` local _l`),_.push(' for _l in "${_lines[@]}"; do'),_.push(` [[ -z "$_l" ]] && continue`),_.push(` _vals+=("$_l")`),_.push(` done`),_.push(" if (( ${#_vals[@]} > 0 )); then"),_.push(` if (( _directive & ${m.NoSpace} )); then`),_.push(` __${r}_cdescribe 'completions' _vals -S ''`),_.push(` else`),_.push(` __${r}_cdescribe 'completions' _vals`),_.push(` fi`),_.push(` fi`),_.push(" if (( ${#_exts[@]} > 0 || ${#_matchers[@]} > 0 )); then"),_.push(` setopt local_options null_glob`),_.push(' local _cur="${words[CURRENT]:-}" _dir _prefix _f _out _ext _pat'),_.push(` if [[ -z "$_cur" || "$_cur" != */* ]]; then`),_.push(` _dir="."`),_.push(` _prefix="$_cur"`),_.push(` elif [[ "$_cur" == */ ]]; then`),_.push(' _dir="${_cur%/}"'),_.push(` _prefix=""`),_.push(` else`),_.push(' _dir="${_cur%/*}"'),_.push(' _prefix="${_cur##*/}"'),_.push(` fi`),_.push(` for _f in "$_dir"/"$_prefix"*(N/); do`),_.push(' _out="${_f#./}"'),_.push(` __${r}_add_path_candidate "$_out"`),_.push(` done`),_.push(` for _f in "$_dir"/"$_prefix"*(N.); do`),_.push(' _out="${_f#./}"'),_.push(' for _ext in "${_exts[@]}"; do'),_.push(` [[ -n "$_ext" && "$_out" == *."$_ext" ]] && { __${r}_add_path_candidate "$_out"; break; }`),_.push(` done`),_.push(` done`),_.push(' for _pat in "${_matchers[@]}"; do'),_.push(` [[ -n "$_pat" ]] || continue`),_.push(' for _f in "$_dir"/${~_pat}(N.); do'),_.push(' _out="${_f#./}"'),_.push(` [[ "$_out" == "$_cur"* ]] && __${r}_add_path_candidate "$_out"`),_.push(` done`),_.push(` done`),_.push(` elif (( _directive & ${m.DirectoryCompletion} )); then`),_.push(` _files -/`),_.push(` elif (( _directive & ${m.FileCompletion} )); then`),_.push(` _files`),_.push(` elif (( \${#_vals[@]} == 0 )) && ! (( _directive & ${m.NoFileCompletion} )); then`),_.push(` _files`),_.push(` fi`),_.push(`}`),_.push(``),_.push(`${c}() {`),_.push(` emulate -L zsh`),_.push(` setopt local_options no_aliases`),_.push(` local _bin _out _node_compile_cache _worker _bundled_worker _sig`),_.push(` _bin="$(__${r}_resolve_bin)"`),_.push(` [[ -n "$_bin" ]] || return 1`),_.push(` _node_compile_cache="$(__${r}_node_compile_cache_dir)"`),_.push(` _bundled_worker="$(__${r}_bundled_worker_path "$_bin" "$_node_compile_cache")"`),_.push(` if [[ -n "$_bundled_worker" ]] && __${r}_load_worker "$_bundled_worker"; then`),_.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${a}="$_bin" _${i}_completions "$@"`),_.push(` return 0`),_.push(` fi`),_.push(` _worker="$(__${r}_static_worker_path)"`),_.push(` _sig="$(__${r}_bin_sig "$_bin")"`),_.push(` if [[ -n "$_worker" && -n "$_sig" ]]; then`),_.push(` if ! __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin"; then`),_.push(' mkdir -p "${_worker%/*}" 2>/dev/null'),_.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${o}="$_bin" "$_bin" __refresh-completion zsh "$_worker" --static --worker 2>/dev/null`),_.push(` fi`),_.push(` if __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin" && __${r}_load_worker "$_worker"; then`),_.push(` NODE_COMPILE_CACHE="$_node_compile_cache" ${a}="$_bin" _${i}_completions "$@"`),_.push(` return 0`),_.push(` fi`),_.push(` fi`),_.push(' _out=$(NODE_COMPILE_CACHE="$_node_compile_cache" "$_bin" __complete --shell zsh -- "${(@)words[2,CURRENT]}" 2>/dev/null) || return 1'),_.push(` __${r}_apply_dynamic_output "$_out"`),_.push(`}`),_.push(``),_.push(`zstyle ':completion:*:*:${n}:*' file-patterns '%p:globbed-files *(-/):directories'`),_.push(``),_.push(`if [[ ${l} ]]; then`),_.push(` ${c} "$@"`),_.push(`else`),_.push(` compdef ${c} ${n}`),_.push(`fi`),_.push(``),{script:_.join(`
|
|
27
|
-
`),shell:`zsh`,installInstructions:`# To enable dispatcher zsh completions, add this to your ~/.zshrc after compinit:
|
|
28
|
-
eval "$(${n} completion zsh)"
|
|
29
|
-
|
|
30
|
-
# To save the dispatcher script in your fpath:
|
|
31
|
-
mkdir -p ~/.zsh/completions
|
|
32
|
-
${n} completion zsh > ~/.zsh/completions/_${n}
|
|
33
|
-
|
|
34
|
-
# Make sure your ~/.zshrc includes the fpath line before compinit:
|
|
35
|
-
fpath=(~/.zsh/completions $fpath)
|
|
36
|
-
autoload -Uz compinit && compinit
|
|
37
|
-
|
|
38
|
-
# To generate the older static script:
|
|
39
|
-
${n} completion zsh --static`}}function St(e,t){let{programName:n}=t,r=D(n),i=`${r}_worker`,a=O(i),o=O(r),s=p(n),c=ht(K(t.cacheDir),G(n)),l=ht(q(t.cacheDir,`fish`),J(n,`fish`)),u=vt(t),d=yt(t),h=[];return h.push(...z({programName:n,shell:`fish`,binPath:t.binPath,programVersion:t.programVersion})),h.push(`# Generated by politty`),h.push(`# politty-completion-mode: dispatcher`),h.push(``),h.push(`function __${r}_resolve_bin`),h.push(` if set -q ${o}; and test -n "$${o}"`),h.push(` printf '%s\\n' "$${o}"`),h.push(` return 0`),h.push(` end`),h.push(` set -l _bin (command -v ${s})`),h.push(` test -n "$_bin"; and test -x "$_bin"; and not test -d "$_bin"; and printf '%s\\n' "$_bin"`),h.push(`end`),h.push(``),h.push(`function __${r}_node_compile_cache_dir`),h.push(` if set -q NODE_COMPILE_CACHE; and test -n "$NODE_COMPILE_CACHE"`),h.push(` printf '%s\\n' "$NODE_COMPILE_CACHE"`),h.push(` return 0`),h.push(` end`),h.push(c),h.push(`end`),h.push(``),h.push(`function __${r}_static_worker_path`),h.push(l),h.push(`end`),h.push(``),h.push(`function __${r}_worker_file_sig`),h.push(` set -l _worker $argv[1]`),h.push(` set -l _sig ${f(`$_worker`,{shell:`fish`,withSize:!0})}`),h.push(` test -n "$_sig"; and printf '%s\\n' "$_sig"`),h.push(`end`),h.push(``),h.push(`function __${r}_is_worker_file`),h.push(` set -l _worker $argv[1]`),h.push(` test -f "$_worker"; or return 1`),h.push(` set -l _head (head -n 24 "$_worker" 2>/dev/null)`),h.push(` string match -q -- "# politty-completion-version: 1" $_head; or return 1`),h.push(` string match -q -- "# program: ${n}" $_head; or return 1`),h.push(` string match -q -- "# shell: fish" $_head; or return 1`),h.push(` string match -q -- "# politty-completion-mode: worker" $_head; or return 1`),h.push(` string match -q -- "# politty-completion-worker: true" $_head; or return 1`),h.push(`end`),h.push(``),h.push(`function __${r}_load_worker`),h.push(` set -l _worker $argv[1]`),h.push(` __${r}_is_worker_file "$_worker"; or return 1`),h.push(` set -l _sig (__${r}_worker_file_sig "$_worker")`),h.push(` test -n "$_sig"; or return 1`),h.push(` set -l _key "$_worker:$_sig"`),h.push(` if not set -q __${r}_loaded_worker_key; or test "$__${r}_loaded_worker_key" != "$_key"`),h.push(` source "$_worker" 2>/dev/null; or return 1`),h.push(` set -g __${r}_loaded_worker_key "$_key"`),h.push(` end`),h.push(` functions -q __fish_${i}_complete`),h.push(`end`),h.push(``),h.push(`function __${r}_realpath`),h.push(` set -l _path $argv[1]`),h.push(` set -l _old_pwd (pwd)`),h.push(` set -l _limit 0`),h.push(` while test -L "$_path"; and test $_limit -lt 40`),h.push(` set -l _dir (dirname "$_path")`),h.push(` if not cd "$_dir" 2>/dev/null`),h.push(` cd "$_old_pwd" 2>/dev/null`),h.push(` return 1`),h.push(` end`),h.push(` set -l _absdir (pwd -P)`),h.push(` cd "$_old_pwd" 2>/dev/null`),h.push(` test -n "$_absdir"; or return 1`),h.push(` set -l _target (readlink "$_path")`),h.push(` test -n "$_target"; or return 1`),h.push(` if string match -q '/*' -- "$_target"`),h.push(` set _path "$_target"`),h.push(` else`),h.push(` set _path "$_absdir/$_target"`),h.push(` end`),h.push(` set _limit (math $_limit + 1)`),h.push(` end`),h.push(` set -l _dir (dirname "$_path")`),h.push(` if not cd "$_dir" 2>/dev/null`),h.push(` cd "$_old_pwd" 2>/dev/null`),h.push(` return 1`),h.push(` end`),h.push(` set -l _absdir (pwd -P)`),h.push(` cd "$_old_pwd" 2>/dev/null`),h.push(` test -n "$_absdir"; or return 1`),h.push(` set -l _base (basename "$_path")`),h.push(` printf '%s\\n' "$_absdir/$_base"`),h.push(`end`),h.push(``),h.push(`function __${r}_worker_from_dir`),h.push(` set -l _dir $argv[1]`),u.length>0&&(h.push(` for _rel in ${u}`),h.push(` if string match -q '/*' -- "$_rel"`),h.push(` set _candidate "$_rel"`),h.push(` else`),h.push(` set _candidate "$_dir/$_rel"`),h.push(` end`),h.push(` if __${r}_is_worker_file "$_candidate"`),h.push(` printf '%s\\n' "$_candidate"`),h.push(` return 0`),h.push(` end`),h.push(` end`)),h.push(` return 1`),h.push(`end`),h.push(``),h.push(`function __${r}_cmd_shim_target`),h.push(` sed -n 's/^# cmd-shim-target=//p' "$argv[1]" 2>/dev/null | tail -n 1`),h.push(`end`),h.push(``),h.push(`function __${r}_bundled_worker_path`),h.push(` set -l _bin $argv[1]`),h.push(` set -l _node_compile_cache $argv[2]`),h.push(` set -l _real (__${r}_realpath "$_bin" 2>/dev/null)`),h.push(` if test -n "$_real"`),h.push(` set -l _dir (dirname "$_real")`),h.push(` __${r}_worker_from_dir "$_dir"; and return 0`),h.push(` end`),h.push(` set -l _dir (dirname "$_bin")`),h.push(` __${r}_worker_from_dir "$_dir"; and return 0`),h.push(` set -l _target (__${r}_cmd_shim_target "$_bin")`),h.push(` if test -n "$_target"`),h.push(` set _real (__${r}_realpath "$_target" 2>/dev/null)`),h.push(` test -n "$_real"; or set _real "$_target"`),h.push(` set _dir (dirname "$_real")`),h.push(` __${r}_worker_from_dir "$_dir"; and return 0`),h.push(` end`),d&&(h.push(` if set -q __${r}_queried_bin; and test "$__${r}_queried_bin" = "$_bin"; and test -n "$__${r}_queried_worker"; and __${r}_is_worker_file "$__${r}_queried_worker"`),h.push(` printf '%s\\n' "$__${r}_queried_worker"`),h.push(` return 0`),h.push(` end`),h.push(` set -l _reported (env NODE_COMPILE_CACHE="$_node_compile_cache" "$_bin" __completion-worker-path fish 2>/dev/null)`),h.push(` if test -n "$_reported"; and __${r}_is_worker_file "$_reported"`),h.push(` set -g __${r}_queried_bin "$_bin"`),h.push(` set -g __${r}_queried_worker "$_reported"`),h.push(` printf '%s\\n' "$_reported"`),h.push(` return 0`),h.push(` end`)),h.push(` return 1`),h.push(`end`),h.push(``),h.push(`function __${r}_bin_sig`),h.push(` set -l _bin $argv[1]`),h.push(` set -l _sig ${f(`$_bin`,{shell:`fish`})}`),h.push(` test -n "$_sig"; and printf '%s\\n' "$_sig"`),h.push(`end`),h.push(``),h.push(`function __${r}_worker_matches_bin`),h.push(` set -l _worker $argv[1]`),h.push(` set -l _sig $argv[2]`),h.push(` set -l _bin $argv[3]`),h.push(` test -f "$_worker"; or return 1`),h.push(` set -l _head (head -n 12 "$_worker" 2>/dev/null)`),h.push(` contains -- "# politty-bin-sig: $_sig" $_head; or return 1`),h.push(` contains -- "# politty-bin-path: $_bin" $_head; or return 1`),h.push(`end`),h.push(``),h.push(`function __${r}_apply_dynamic_output`),h.push(` set -l _cur $argv[1]`),h.push(` set -l _directive 0`),h.push(` set -l _emitted 0`),h.push(` set -l _exts`),h.push(` set -l _matchers`),h.push(` set -l _lines`),h.push(` while read -l _l`),h.push(` set -a _lines $_l`),h.push(` end`),h.push(` set -l _n (count $_lines)`),h.push(` if test $_n -ge 1; and string match -qr '^:[0-9]+' -- $_lines[$_n]`),h.push(` set -l _fields (string split \\t -- $_lines[$_n])`),h.push(` set -e _lines[$_n]`),h.push(` set _directive (string sub -s 2 -- $_fields[1])`),h.push(` for _f in $_fields[2..-1]`),h.push(` if string match -q '@ext:*' -- $_f`),h.push(` set _exts (string split , -- (string sub -s 6 -- $_f))`),h.push(` else if string match -q '@matcher:*' -- $_f`),h.push(` set _matchers (string split , -- (string sub -s 10 -- $_f))`),h.push(` end`),h.push(` end`),h.push(` end`),h.push(` for _l in $_lines`),h.push(` if test -n "$_l"`),h.push(` printf '%s\\n' $_l`),h.push(` set _emitted 1`),h.push(` end`),h.push(` end`),h.push(` if test (count $_exts) -gt 0; or test (count $_matchers) -gt 0`),h.push(` __fish_complete_directories "$_cur"`),h.push(` set -l _dir ""`),h.push(` if string match -q '*/*' "$_cur"`),h.push(` set _dir (string replace -r '[^/]*$' '' "$_cur")`),h.push(` end`),h.push(` for _f in "$_cur"*`),h.push(` test -f "$_f"; or continue`),h.push(` for _ext in $_exts`),h.push(` if string match -q -- "*.$_ext" "$_f"`),h.push(` printf '%s\\n' "$_f"`),h.push(` break`),h.push(` end`),h.push(` end`),h.push(` end`),h.push(` for _pat in $_matchers`),h.push(` for _f in "$_dir"$_pat`),h.push(` test -f "$_f"; and string match -q "$_cur*" "$_f"; and printf '%s\\n' "$_f"`),h.push(` end`),h.push(` end`),h.push(` else if test (math "bitand($_directive, ${m.DirectoryCompletion})") -ne 0`),h.push(` __fish_complete_directories "$_cur"`),h.push(` else if test (math "bitand($_directive, ${m.FileCompletion})") -ne 0`),h.push(` __fish_complete_path "$_cur"`),h.push(` else if test $_emitted -eq 0; and test (math "bitand($_directive, ${m.NoFileCompletion})") -eq 0`),h.push(` __fish_complete_path "$_cur"`),h.push(` end`),h.push(`end`),h.push(``),h.push(`function __fish_${r}_complete`),h.push(` set -l _bin (__${r}_resolve_bin)`),h.push(` test -n "$_bin"; or return 0`),h.push(` set -l _node_compile_cache (__${r}_node_compile_cache_dir)`),h.push(` set -l _bundled_worker (__${r}_bundled_worker_path "$_bin" "$_node_compile_cache")`),h.push(` if test -n "$_bundled_worker"; and __${r}_load_worker "$_bundled_worker"`),h.push(` set -lx ${a} "$_bin"`),h.push(` set -lx NODE_COMPILE_CACHE "$_node_compile_cache"`),h.push(` __fish_${i}_complete`),h.push(` return 0`),h.push(` end`),h.push(` set -l _worker (__${r}_static_worker_path)`),h.push(` set -l _sig (__${r}_bin_sig "$_bin")`),h.push(` if test -n "$_worker"; and test -n "$_sig"`),h.push(` if not __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin"`),h.push(` mkdir -p (dirname "$_worker") 2>/dev/null`),h.push(` env NODE_COMPILE_CACHE="$_node_compile_cache" ${o}="$_bin" $_bin __refresh-completion fish "$_worker" --static --worker 2>/dev/null`),h.push(` end`),h.push(` if __${r}_worker_matches_bin "$_worker" "$_sig" "$_bin"`),h.push(` if __${r}_load_worker "$_worker"`),h.push(` set -lx ${a} "$_bin"`),h.push(` set -lx NODE_COMPILE_CACHE "$_node_compile_cache"`),h.push(` __fish_${i}_complete`),h.push(` return 0`),h.push(` end`),h.push(` end`),h.push(` end`),h.push(` set -l _args (commandline -opc)`),h.push(` set -l _cur (commandline -ct)`),h.push(` if test (count $_args) -gt 0`),h.push(` set _args $_args[2..]`),h.push(` end`),h.push(` env NODE_COMPILE_CACHE="$_node_compile_cache" $_bin __complete --shell fish -- $_args "$_cur" 2>/dev/null | __${r}_apply_dynamic_output "$_cur"`),h.push(`end`),h.push(``),h.push(`complete -e -c ${n}`),h.push(`complete -c ${n} -f -a '(__fish_${r}_complete)'`),h.push(``),{script:h.join(`
|
|
40
|
-
`),shell:`fish`,installInstructions:`# To enable dispatcher fish completions, run:
|
|
41
|
-
${n} completion fish --install
|
|
42
|
-
|
|
43
|
-
# To generate the older static script:
|
|
44
|
-
${n} completion fish --static`}}function Ct(e,t){switch(I(e,t.programName,t.globalArgsSchema,!0),t.shell){case`bash`:return bt(e,t);case`zsh`:return xt(e,t);case`fish`:return St(e,t);default:throw Error(`Unsupported shell: ${t.shell}`)}}function X(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`)}function wt(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`).replace(/\*/g,`\\*`).replace(/\?/g,`\\?`).replace(/\[/g,`\\[`).replace(/]/g,`\\]`)}function Tt(e,t,n){if(!e)return[];switch(e.type){case`expand`:{if(!n)throw Error(`fishValueLines: expand variant requires a location`);let t=e=>{let t=D(e.name);return e.isGlobal?`$_global_arg_values_${t}`:`$_arg_values_${t}`},r=n.resolvedDeps.map(e=>`"${t(e)}"`).join(`\\x1f`),i=D(n.fieldName),a=n.isGlobal?`$_global_used_field_keys_${i}`:`$_used_field_keys_${i}`,o=[`switch ${r}`];for(let t of e.table){let e=t.key.map(e=>`"${wt(e)}"`).join(`\\x1f`);o.push(` case ${e}`);let r=[],i=[],s=new Set,c=(e,t)=>t?`printf '%s\\t%s\\n' "${X(e)}" "${X(t)}"`:`printf '%s\\n' "${X(e)}"`,l=(e,t)=>n.isArrayOption&&t.length>0?[` if not contains -- "${X(t)}" ${a}`,` ${e}`,` end`]:[` ${e}`];for(let e of t.candidates){let t=e.value.indexOf(`=`),n=t>0?e.value.slice(0,t):``,a=c(e.value,e.description);n.length>0&&e.value.length===t+1||i.push(...l(a,n)),n.length===0?r.push(` ${a}`):s.has(n)||(s.add(n),r.push(...l(c(`${n}=`,e.description),n)))}i.length!==r.length||i.some((e,t)=>e!==r[t])?(o.push(` if string match -q '*=*' -- "$_cur"`),o.push(...i),o.push(` else`),o.push(...r),o.push(` end`)):o.push(...i)}return o.push(`end`),o}case`dynamic`:return[`__${t}_invoke_complete fish $_args | __${t}_apply_dynamic_output "$_cur"`];case`choices`:return e.choices.map(e=>`echo "${X(e)}"`);case`file`:return e.matcher?.length?Et(e.matcher):e.extensions?.length?Dt(e.extensions):[`__fish_complete_path "$_cur"`];case`directory`:return[`__fish_complete_directories "$_cur"`];case`command`:return[`for _v in (${e.shellCommand})`,` echo "$_v"`,`end`];case`none`:return[];case`runtime-expand`:return[]}}function Et(e){return[`__fish_complete_directories "$_cur"`,`set -l _dir ""`,`if string match -q '*/*' "$_cur"`,` set _dir (string replace -r '[^/]*$' '' "$_cur")`,`end`,...e.flatMap(e=>[`for _f in "$_dir"${e}`,` test -f "$_f"; and string match -q "$_cur*" "$_f"; and echo "$_f"`,`end`])]}function Dt(e){let t=[];if(t.push(`__fish_complete_directories "$_cur"`),e.length>0){let n=e.map(e=>`string match -q -- "*.${e}" "$_f"`).join(`; or `);t.push(`for _f in "$_cur"*`),t.push(` test -f "$_f"; or continue`),t.push(` if ${n}`),t.push(` echo "$_f"`),t.push(` end`),t.push(`end`)}return t}function Ot(e,t,n){let r=[];for(let i of e){if(!i.takesValue||!i.valueCompletion)continue;let a=Tt(i.valueCompletion,n,d(i,e,t));if(a.length===0)continue;let o=P(i,e);if(o.length===0)continue;let s=o.map(e=>`test "$_prev" = "${e}"`).join(`; or `);r.push(` if ${s}`);for(let e of a)r.push(` ${e}`);r.push(` return`),r.push(` end`)}return r}function Z(e,t,n=[]){if(e.length===0)return[];let r=[];for(let i of e){let a=Tt(i.valueCompletion,t,_(i,n,e));if(a.length!==0){i.variadic?r.push(` if test $_pos_count -ge ${i.position}`):r.push(` if test $_pos_count -eq ${i.position}`);for(let e of a)r.push(` ${e}`);r.push(` return`),r.push(` end`)}}return r}function kt(e,t,n,r){let i=e.map(e=>`echo "${e.name}\t${X(e.description??``)}"`);return t.length===0?i:[`set -l _sub_match 0`,`for _sub_name in ${e.map(e=>`"${X(e.name)}"`).join(` `)}`,` test (string sub -l (string length -- "$_cur") -- "$_sub_name") = "$_cur"; and set _sub_match 1; and break`,`end`,`if test $_sub_match -eq 1`,...i.map(e=>` ${e}`),`else`,...Z(t,n,r),`end`]}function At(e,t){let n=[];for(let r of e){let i=X(r.description??``);if(r.valueType===`array`){n.push(` echo "--${r.cliName}\t${i}"`);continue}let a=g(r.cliName,r.alias,r.negation,{isGlobal:r.isGlobal===!0,frameOptions:e}),o=`__${t}_not_used ${a.join(` `)}`,s=r.negationDescription?X(r.negationDescription):i,c=[{name:r.cliName,desc:i}];r.negation&&c.push({name:r.negation,desc:s});for(let e of c)a.includes(`"--${e.name}"`)&&n.push(` ${o}; and echo "--${e.name}\t${e.desc}"`)}return n.push(` if test $_any_opt_used -eq 0`),n.push(` echo "--help Show help"`),n.push(` echo "--help-all Show help with all subcommand options"`),n.push(` echo "--help-json Show help as JSON"`),n.push(` end`),n}function jt(e,t,n){let r=[...n,e.name],i=`__${t}_complete_${r.map(D).join(`_`)}`,a=A(e.subcommands),o=[];for(let e of a)o.push(...jt(e,t,r));o.push(`function ${i} --no-scope-shadowing`),o.push(...Ot(e.options,e.positionals,t));let s=r.join(`:`);if(o.push(` if __${t}_opt_takes_value "${s}" "$_prev"; return; end`),e.positionals.length>0?(o.push(` if test $_after_dd -eq 1`),o.push(...Z(e.positionals,t,e.options).map(e=>` ${e}`)),o.push(` return`),o.push(` end`)):o.push(` if test $_after_dd -eq 1; return; end`),o.push(` if string match -q -- '-*' "$_cur"`),o.push(...At(e.options,t)),o.push(` return`),o.push(` end`),a.length>0){let n=j(e.subcommands);o.push(...kt(n,e.positionals,t,e.options).map(e=>` ${e}`))}else e.positionals.length>0&&o.push(...Z(e.positionals,t,e.options));return o.push(`end`),o.push(``),o}function Mt(e,t){let n=[];for(let r of Ce(e,t)){let e=r.tokens.map(e=>`"${r.parentPath}:${e}"`);n.push(` case ${e.join(` `)}`),n.push(` return 0`)}return n}function Nt(e,t){let{programName:n}=t,r=I(e,n,t.globalArgsSchema),i=D(n),a=t.staticWorker?`${i}_${D(t.staticWorker.functionSuffix)}`:i,o=t.staticWorker!==void 0,s=r.command,c=A(s.subcommands),l=je(s),u=Ne(s,l,r.globalOptions),d=l.length>0,p=l.filter(e=>e.isArrayOption),h=p.length>0,g=[];if(g.push(...z({programName:n,shell:`fish`,binPath:t.binPath,programVersion:t.programVersion})),g.push(`# politty-completion-mode: ${o?`worker`:`static`}`),o&&g.push(`# politty-completion-worker: true`),g.push(`# Generated by politty`),g.push(``),!o){let e=R(n,t.binPath),r=L(e),o=O(i),s=`__${a}_refresh_completion`;g.push(`function ${s} --no-scope-shadowing`),g.push(` set -l _bin $${o}`),g.push(` test -z "$_bin"; and set _bin (command -v ${n})`),g.push(` test -z "$_bin"; and return 1`),g.push(` set -l _sig ${f(`$_bin`,{shell:`fish`})}`),g.push(` test "$_sig" = "${r}"; and test "$_bin" = "${X(e)}"; and return 1`),g.push(` set -l _target (status current-filename)`),g.push(` test -n "$_target"; and test -f "$_target"; or return 1`),g.push(` "$_bin" __refresh-completion fish "$_target" --static 2>/dev/null`),g.push(` and source "$_target" 2>/dev/null`),g.push(` and return 0`),g.push(` return 1`),g.push(`end`),g.push(`${s}`),g.push(`set -l _politty_refreshed $status`),g.push(`functions -e ${s}`),g.push(`test $_politty_refreshed -eq 0; and return`),g.push(``)}if(F(s)&&(g.push(`function __${a}_invoke_complete`),g.push(` set -l _shell $argv[1]`),g.push(` set -l _argv $argv[2..]`),g.push(` set -l _bin ${n}`),g.push(` if set -q ${O(a)}`),g.push(` set _bin $${O(a)}`),g.push(` end`),g.push(` $_bin __complete --shell $_shell -- $_argv 2>/dev/null`),g.push(`end`),g.push(``),g.push(`function __${a}_apply_dynamic_output`),g.push(` set -l _cur $argv[1]`),g.push(` set -l _directive 0`),g.push(` set -l _emitted 0`),g.push(` set -l _prev ""`),g.push(` set -l _has_prev 0`),g.push(` while read -l _l`),g.push(` if test $_has_prev -eq 1`),g.push(` if test -n "$_prev"`),g.push(` printf '%s\\n' "$_prev"`),g.push(` set _emitted 1`),g.push(` end`),g.push(` end`),g.push(` set _prev $_l`),g.push(` set _has_prev 1`),g.push(` end`),g.push(` if test $_has_prev -eq 1`),g.push(` if string match -qr '^:[0-9]+$' -- $_prev`),g.push(` set _directive (string sub -s 2 -- $_prev)`),g.push(` else`),g.push(` if test -n "$_prev"`),g.push(` printf '%s\\n' "$_prev"`),g.push(` set _emitted 1`),g.push(` end`),g.push(` end`),g.push(` end`),g.push(` if test (math "bitand($_directive, ${m.DirectoryCompletion})") -ne 0`),g.push(` __fish_complete_directories "$_cur"`),g.push(` else if test (math "bitand($_directive, ${m.FileCompletion})") -ne 0`),g.push(` __fish_complete_path "$_cur"`),g.push(` else if test $_emitted -eq 0; and test (math "bitand($_directive, ${m.NoFileCompletion})") -eq 0`),g.push(` __fish_complete_path "$_cur"`),g.push(` end`),g.push(`end`),g.push(``)),g.push(`function __${a}_not_used --no-scope-shadowing`),g.push(` for _chk in $argv`),g.push(` if contains -- "$_chk" $_used_opts`),g.push(` return 1`),g.push(` end`),g.push(` end`),g.push(` return 0`),g.push(`end`),g.push(``),g.push(`function __${a}_opt_takes_value`),g.push(` switch "$argv[1]:$argv[2]"`),g.push(...Mt(s,``)),g.push(` end`),g.push(` return 1`),g.push(`end`),g.push(``),d){let e=e=>`${e.isGlobal?`_global_arg_values_`:`_arg_values_`}${D(e.fieldName)}`;g.push(`function __${a}_track_opt --no-scope-shadowing`),g.push(` switch "$argv[1]:$argv[2]"`);for(let t of u){if(t.isPositional||!t.optionTokens||t.optionTokens.length===0)continue;let n=t.pathStrs.flatMap(e=>t.optionTokens.map(t=>`"${e}:${t}"`)).join(` `);g.push(` case ${n}`),g.push(` set -g ${e(t)} "$argv[3]"`)}g.push(` end`),g.push(`end`),g.push(``),g.push(`function __${a}_track_pos --no-scope-shadowing`),g.push(` switch "$argv[1]:$argv[2]"`);for(let t of u){if(!t.isPositional)continue;let n=t.pathStrs.map(e=>`"${e}:${t.position}"`).join(` `);g.push(` case ${n}`),g.push(` set -g ${e(t)} "$argv[3]"`)}g.push(` end`),g.push(`end`),g.push(``)}if(h){g.push(`function __${a}_track_array_expand --no-scope-shadowing`),g.push(` switch "$argv[1]:$argv[2]"`);for(let e of p){if(e.optionTokens.length===0)continue;let t=e.pathStrs.flatMap(t=>e.optionTokens.map(e=>`"${t}:${e}"`)).join(` `),n=D(e.fieldName),r=e.isGlobal?`_global_used_field_keys_`:`_used_field_keys_`;g.push(` case ${t}`),g.push(` if string match -q '*=*' -- "$argv[3]"`),g.push(` set -l _k (string replace -r '=.*' '' -- "$argv[3]")`),g.push(` if test -n "$_k"`),e.isGlobal?(g.push(` if not set -q _global_arr_seen_${n}`),g.push(` set -g ${r}${n} "$_k"`),g.push(` set -g _global_arr_seen_${n} 1`),g.push(` else if not contains -- "$_k" $${r}${n}`),g.push(` set -ga ${r}${n} "$_k"`),g.push(` end`)):(g.push(` if not contains -- "$_k" $${r}${n}`),g.push(` set -ga ${r}${n} "$_k"`),g.push(` end`)),g.push(` end`),g.push(` end`)}g.push(` end`),g.push(`end`),g.push(``)}let _=N(s);if(_.length>0){g.push(`function __${a}_is_subcmd`),g.push(` switch "$argv[1]:$argv[2]"`);for(let e of _)g.push(` case "${e.lookupPattern}"`),g.push(` return 0`);g.push(` end`),g.push(` return 1`),g.push(`end`),g.push(``)}for(let e of c)g.push(...jt(e,a,[]));if(g.push(`function __${a}_complete_root --no-scope-shadowing`),g.push(...Ot(s.options,s.positionals,a)),g.push(` if __${a}_opt_takes_value "" "$_prev"; return; end`),s.positionals.length>0?(g.push(` if test $_after_dd -eq 1`),g.push(...Z(s.positionals,a,s.options).map(e=>` ${e}`)),g.push(` return`),g.push(` end`)):g.push(` if test $_after_dd -eq 1; return; end`),g.push(` if string match -q -- '-*' "$_cur"`),g.push(...At(s.options,a)),c.length>0){g.push(` else`);let e=j(s.subcommands);g.push(...kt(e,s.positionals,a,s.options).map(e=>` ${e}`))}else s.positionals.length>0&&(g.push(` else`),g.push(...Z(s.positionals,a,s.options)));if(g.push(` end`),g.push(`end`),g.push(``),g.push(`function __fish_${a}_complete`),g.push(` set -l _args (commandline -opc)`),g.push(` set -e _args[1]`),g.push(``),g.push(` set -l _ct (commandline -ct)`),g.push(` if test (count $_ct) -eq 0`),g.push(` set -a _args ""`),g.push(` else`),g.push(` set -a _args $_ct`),g.push(` end`),g.push(``),g.push(` set -l _cur ""`),g.push(` if test (count $_args) -gt 0`),g.push(` set _cur "$_args[-1]"`),g.push(` end`),g.push(``),g.push(` set -l _prev ""`),g.push(` if test (count $_args) -gt 1`),g.push(` set _prev "$_args[-2]"`),g.push(` end`),g.push(``),g.push(` set -l _subcmd "" ; set -l _after_dd 0 ; set -l _pos_count 0 ; set -l _skip_next 0`),g.push(` set -l _used_opts`),g.push(` set -l _any_opt_used 0`),g.push(``),d)for(let e of u)g.push(` set -e _arg_values_${D(e.fieldName)}`),g.push(` set -e _global_arg_values_${D(e.fieldName)}`);if(h)for(let e of p)g.push(` set -e _used_field_keys_${D(e.fieldName)}`),g.push(` set -e _global_used_field_keys_${D(e.fieldName)}`),g.push(` set -e _global_arr_seen_${D(e.fieldName)}`);g.push(` set -l _j 1`),g.push(` set -l _limit (math (count $_args) - 1)`),g.push(` while test $_j -le $_limit`),g.push(` set -l _w "$_args[$_j]"`),g.push(` if test $_skip_next -eq 1; set _skip_next 0; set _j (math $_j + 1); continue; end`),g.push(` if test "$_w" = "--"; set _after_dd 1; set _j (math $_j + 1); continue; end`);let v=d?`__${a}_track_pos "$_subcmd" "$_pos_count" "$_w"; `:``;if(g.push(` if test $_after_dd -eq 1; ${v}set _pos_count (math $_pos_count + 1); set _j (math $_j + 1); continue; end`),g.push(` if string match -q -- '-*=*' "$_w"`),g.push(` set -l _opt (string replace -r '=.*' '' -- "$_w")`),g.push(` set -a _used_opts "$_opt"`),g.push(` set _any_opt_used 1`),d&&(g.push(` set -l _val (string replace -r '^[^=]*=' '' -- "$_w")`),g.push(` __${a}_track_opt "$_subcmd" "$_opt" "$_val"`),h&&g.push(` __${a}_track_array_expand "$_subcmd" "$_opt" "$_val"`)),g.push(` set _j (math $_j + 1); continue`),g.push(` end`),g.push(` if string match -q -- '-*' "$_w"`),g.push(` set -a _used_opts "$_w"`),g.push(` set _any_opt_used 1`),g.push(` if __${a}_opt_takes_value "$_subcmd" "$_w"`),g.push(` set -l _next ""`),g.push(` set -l _next_idx (math $_j + 1)`),g.push(` if test $_next_idx -le (count $_args)`),g.push(` set _next "$_args[$_next_idx]"`),g.push(` end`),g.push(` if test -n "$_next"; and not string match -q -- '-*' "$_next"`),g.push(` set _skip_next 1`),d&&(g.push(` __${a}_track_opt "$_subcmd" "$_w" "$_next"`),h&&(g.push(` if test $_j -lt $_limit`),g.push(` __${a}_track_array_expand "$_subcmd" "$_w" "$_next"`),g.push(` end`))),g.push(` end`),g.push(` end`),g.push(` set _j (math $_j + 1); continue`),g.push(` end`),_.length>0){if(g.push(` if __${a}_is_subcmd "$_subcmd" "$_w"`),g.push(` test -n "$_subcmd"; and set _subcmd "$_subcmd:$_w"; or set _subcmd "$_w"`),g.push(` set _used_opts; set _pos_count 0`),d){for(let e of u)g.push(` set -e _arg_values_${D(e.fieldName)}`);if(h)for(let e of p)g.push(` set -e _used_field_keys_${D(e.fieldName)}`),g.push(` set -e _global_arr_seen_${D(e.fieldName)}`)}g.push(` else`),d&&g.push(` __${a}_track_pos "$_subcmd" "$_pos_count" "$_w"`),g.push(` set _pos_count (math $_pos_count + 1)`),g.push(` end`)}else d&&g.push(` __${a}_track_pos "$_subcmd" "$_pos_count" "$_w"`),g.push(` set _pos_count (math $_pos_count + 1)`);g.push(` set _j (math $_j + 1)`),g.push(` end`),g.push(``),g.push(` switch "$_subcmd"`);for(let e of _)g.push(` case "${e.pathStr}"; __${a}_complete_${e.funcSuffix}`);return g.push(` case '*'; __${a}_complete_root`),g.push(` end`),g.push(`end`),g.push(``),o||(g.push(`# Clear existing completions`),g.push(`complete -e -c ${n}`),g.push(``),g.push(`# Register completion`),g.push(`complete -c ${n} -f -a '(__fish_${a}_complete)'`)),g.push(``),{script:g.join(`
|
|
45
|
-
`),shell:`fish`,installInstructions:`# To enable auto-refreshing fish completions, run:
|
|
46
|
-
${n} completion fish --install --static`}}function Pt(e,t){x(T(e),{recursive:!0});let n=`${e}.tmp.${process.pid}`;re(n,t),te(n,e)}function Ft(e,t){return nn(e.rootCommand,{shell:t,programName:e.programName,mode:e.completionMode??`dispatcher`,includeDescriptions:!0,...e.programVersion!==void 0&&{programVersion:e.programVersion},...e.binPath!==void 0&&{binPath:e.binPath},...e.cacheDir!==void 0&&{cacheDir:e.cacheDir},...e.globalArgsSchema!==void 0&&{globalArgsSchema:e.globalArgsSchema},...e.bundledWorker!==void 0&&{bundledWorker:e.bundledWorker},...e.staticWorker!==void 0&&{staticWorker:e.staticWorker}}).script}function It(e,t){let n=r(e.programName,t,e.cacheDir);return Pt(n,Ft(e,t)),n}function Lt(e){try{if(!b(e))return;let t=S(e,`utf8`).split(`
|
|
47
|
-
`,10).join(`
|
|
48
|
-
`).match(/^# politty-completion-mode: (dispatcher|static)$/m);return t?t[1]:void 0}catch{return}}function Rt(e){try{if(!b(e))return null;let t=S(e,`utf8`).split(`
|
|
49
|
-
`,10).join(`
|
|
50
|
-
`).match(/^# politty-bin-path: (.*)$/m);return t?t[1]:null}catch{return null}}function zt(e,t,n){try{if(!b(e))return!1;let r=S(e,`utf8`).split(`
|
|
51
|
-
`,8).map(e=>e.trimEnd());return r.some(e=>/^# politty-completion-version: \S+$/.test(e))&&r.includes(`# program: ${t}`)&&r.includes(`# shell: ${n}`)}catch{return!1}}function Bt(e,t){try{let n=e.targetPath?b(e.targetPath)?C(e.targetPath):e.targetPath:r(e.programName,t,e.cacheDir);if(e.targetPath&&b(n)&&!zt(n,e.programName,t)||e.targetPath&&!b(n)&&!e.allowTargetCreate)return;let i=R(e.programName,e.binPath);if(!i)return;let a;try{a=Math.floor(w(i).mtimeMs/1e3).toString()}catch{return}if(o(n)===a&&Rt(n)===i)return;let s=e.completionMode??Lt(n)??(b(n)?`static`:`dispatcher`);Pt(n,Ft({...e,completionMode:s},t))}catch{}}function Vt(e,t,n){return t?p(`${t}/completion.${n}`):`"\${XDG_CACHE_HOME:-$HOME/.cache}/${e}/completion.${n}"`}function Ht(e){let t=D(e.programName),n=O(t),r=Vt(e.programName,e.cacheDir,`bash`);return`__${t}_load_completion() {
|
|
52
|
-
local _bin _cache _sig _sig_hdr _path_hdr
|
|
53
|
-
_bin="\${${n}:-$(type -P ${e.programName} 2>/dev/null)}"
|
|
54
|
-
[[ -n "$_bin" ]] || return 0
|
|
55
|
-
_cache=${r}
|
|
56
|
-
_sig=$(stat -L -c '%Y' "$_bin" 2>/dev/null || stat -L -f '%m' "$_bin" 2>/dev/null) || return 0
|
|
57
|
-
_sig_hdr="# politty-bin-sig: $_sig"
|
|
58
|
-
_path_hdr="# politty-bin-path: $_bin"
|
|
59
|
-
if [[ ! -f "$_cache" ]] || ! head -8 "$_cache" 2>/dev/null | grep -qxF "$_sig_hdr" || ! head -8 "$_cache" 2>/dev/null | grep -qxF "$_path_hdr"; then
|
|
60
|
-
# Use the hidden __refresh-completion subcommand instead of
|
|
61
|
-
# \`$_bin completion bash\`: the foreground completion command
|
|
62
|
-
# is subject to user setup/cleanup/prompt and required
|
|
63
|
-
# globalArgs validation, which can silently fail or block when
|
|
64
|
-
# invoked from rc; runMain bypasses those for __-prefixed
|
|
65
|
-
# internal subcommands.
|
|
66
|
-
"$_bin" __refresh-completion bash 2>/dev/null
|
|
67
|
-
fi
|
|
68
|
-
# If regen failed but a stale cache survived from a previous run,
|
|
69
|
-
# source it anyway — a stale completion is preferable to no
|
|
70
|
-
# completion at all.
|
|
71
|
-
[[ -f "$_cache" ]] || return 0
|
|
72
|
-
# shellcheck disable=SC1090
|
|
73
|
-
source "$_cache"
|
|
74
|
-
}
|
|
75
|
-
__${t}_load_completion
|
|
76
|
-
unset -f __${t}_load_completion
|
|
77
|
-
`}function Ut(e){let t=D(e.programName),n=O(t),r=Vt(e.programName,e.cacheDir,`zsh`);return`__${t}_load_completion() {
|
|
78
|
-
emulate -L zsh
|
|
79
|
-
setopt local_options no_aliases
|
|
80
|
-
local _bin _cache _sig _sig_hdr _path_hdr
|
|
81
|
-
_bin="\${${n}:-$(whence -p ${e.programName} 2>/dev/null)}"
|
|
82
|
-
[[ -n "$_bin" ]] || return 0
|
|
83
|
-
_cache=${r}
|
|
84
|
-
_sig=$(stat -L -c '%Y' "$_bin" 2>/dev/null || stat -L -f '%m' "$_bin" 2>/dev/null) || return 0
|
|
85
|
-
_sig_hdr="# politty-bin-sig: $_sig"
|
|
86
|
-
_path_hdr="# politty-bin-path: $_bin"
|
|
87
|
-
if [[ ! -f "$_cache" ]] || ! head -8 "$_cache" 2>/dev/null | grep -qxF "$_sig_hdr" || ! head -8 "$_cache" 2>/dev/null | grep -qxF "$_path_hdr"; then
|
|
88
|
-
# See bash loader for why we use __refresh-completion instead
|
|
89
|
-
# of \`$_bin completion zsh\`.
|
|
90
|
-
"$_bin" __refresh-completion zsh 2>/dev/null
|
|
91
|
-
fi
|
|
92
|
-
# See bash loader: keep stale completion over no completion.
|
|
93
|
-
[[ -f "$_cache" ]] || return 0
|
|
94
|
-
source "$_cache"
|
|
95
|
-
}
|
|
96
|
-
__${t}_load_completion
|
|
97
|
-
unfunction __${t}_load_completion
|
|
98
|
-
`}function Wt(e){switch(e.shell){case`bash`:return Ht(e);case`zsh`:return Ut(e);case`fish`:throw Error("fish does not use an rc loader. Run `<program> completion fish --install` to write the self-refreshing autoload file instead.")}}function Q(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`).replace(/`/g,"\\`").replace(/:/g,`\\:`)}function Gt(e){return e.replace(/\\/g,`\\\\`).replace(/:/g,`\\:`)}function Kt(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`).replace(/`/g,"\\`")}function qt(e){return e.map(e=>`"${Kt(e)}"`).join(` `)}function Jt(e,t,n){let r=[`setopt local_options null_glob`,'local _cur="${words[CURRENT]:-}" _dir _prefix _f _out',`local -a ${t===`extensions`?`_exts`:`_matchers`}=(${qt(n)})`,`if [[ -z "$_cur" || "$_cur" != */* ]]; then`,` _dir="."`,` _prefix="$_cur"`,`elif [[ "$_cur" == */ ]]; then`,' _dir="${_cur%/}"',` _prefix=""`,`else`,' _dir="${_cur%/*}"',' _prefix="${_cur##*/}"',`fi`,`for _f in "$_dir"/"$_prefix"*(N/); do`,' _out="${_f#./}"',` __${e}_add_path_candidate "$_out"`,`done`];return t===`extensions`?(r.push(`local _ext`),r.push(`for _f in "$_dir"/"$_prefix"*(N.); do`),r.push(' _out="${_f#./}"'),r.push(' for _ext in "${_exts[@]}"; do'),r.push(` [[ -n "$_ext" && "$_out" == *."$_ext" ]] && { __${e}_add_path_candidate "$_out"; break; }`),r.push(` done`),r.push(`done`)):(r.push(`local _pat`),r.push('for _pat in "${_matchers[@]}"; do'),r.push(` [[ -n "$_pat" ]] || continue`),r.push(' for _f in "$_dir"/${~_pat}(N.); do'),r.push(' _out="${_f#./}"'),r.push(` [[ "$_out" == "$_cur"* ]] && __${e}_add_path_candidate "$_out"`),r.push(` done`),r.push(`done`)),r}function Yt(e,t,n){if(!e)return[];switch(e.type){case`expand`:{if(!n)throw Error(`zshValueLines: expand variant requires a location`);let e=k(t,n.funcSuffix,n.fieldName),r=n.resolvedDeps.map(e=>e.isGlobal?`"\${_global_arg_values[${e.name}]:-}"`:`"\${_arg_values[${e.name}]:-}"`).join(`$'\\x1f'`),i=D(n.fieldName),a=n.isGlobal?`\${_global_used_field_keys[${i}]:-}`:`\${_used_field_keys[${i}]:-}`,o=n.isArrayOption?[` if [[ -n "$_ck" && " ${a} " == *" $_ck "* ]]; then continue; fi`]:[];return[`local _key=${r}`,`local _raw="\${${e}[$_key]:-}"`,`if [[ -n "$_raw" ]]; then`,' local -a _candidates=("${(@f)_raw}")',` _vals=()`,` local _c _ck _cke _vp _seen_keys=" " _desc _has_eq=0 _tmp`,' for _c in "${_candidates[@]}"; do',` _tmp="\${_c//\\\\:/$'\\x01'}"`,' _vp="${_tmp%%:*}"',` if [[ "$_vp" == *=* ]]; then`,' _cke="${_c%%=*}"',' _ck="${_cke//\\\\:/:}"',...o,' if [[ "${words[CURRENT]}" != *=* ]]; then',` [[ "$_seen_keys" == *" $_ck "* ]] && continue`,` _seen_keys+="$_ck "`,` if [[ "$_tmp" == *:* ]]; then`,` _desc="\${\${_tmp#*:}//$'\\x01'/\\\\:}"`,' _c="${_cke}=:$_desc"',` else`,' _c="${_cke}="',` fi`,` _has_eq=1`,` else`,` [[ "$_vp" == *=?* ]] || continue`,` fi`,` fi`,` _vals+=("$_c")`,` done`,` if (( _has_eq )); then`,` __${t}_cdescribe 'completions' _vals -S ''`,` else`,` __${t}_cdescribe 'completions' _vals`,` fi`,`fi`]}case`dynamic`:return[`__${t}_apply_dynamic_output "$(__${t}_invoke_complete zsh "\${(@)words[2,CURRENT]}")"`];case`choices`:return[`_vals=(${e.choices.map(e=>`"${Q(e)}"`).join(` `)})`,`__${t}_cdescribe 'completions' _vals`];case`file`:return e.matcher?.length?Jt(t,`matchers`,e.matcher):e.extensions?.length?Jt(t,`extensions`,e.extensions):[`_files`];case`directory`:return[`_files -/`];case`command`:return[`_vals=("\${(@f)$(${e.shellCommand})}")`,`__${t}_cdescribe 'completions' _vals`];case`none`:return[];case`runtime-expand`:return[]}}function Xt(e,t,n,r){let i=[];for(let a of e){if(!a.takesValue||!a.valueCompletion)continue;let o=Yt(a.valueCompletion,n,{funcSuffix:r,...d(a,e,t)});if(o.length===0)continue;let s=P(a,e);if(s.length!==0){i.push(` ${s.join(`|`)})`);for(let e of o)i.push(` ${e}`);i.push(` return 0 ;;`)}}return i}function $(e,t,n,r=[]){if(e.length===0)return[];let i=[];i.push(` case "$_pos_count" in`);for(let a of e){a.variadic?i.push(` ${a.position}|*)`):i.push(` ${a.position})`);let o=Yt(a.valueCompletion,t,{funcSuffix:n,..._(a,r,e)});for(let e of o)i.push(` ${e}`);i.push(` ;;`)}return i.push(` esac`),i}function Zt(e,t,n,r,i){let a=[`local -a _subs=(${e.map(e=>{let t=e.description?`:${Q(e.description)}`:``;return`"${e.name}${t}"`}).join(` `)})`,`__${n}_cdescribe 'subcommands' _subs`];return t.length===0?a:[`local -a _sub_names=(${e.map(e=>`"${Kt(e.name)}"`).join(` `)})`,'local _cur_word="${words[CURRENT]:-}" _sub_name _sub_match=0','for _sub_name in "${_sub_names[@]}"; do',` [[ "$_sub_name" == "$_cur_word"* ]] && _sub_match=1 && break`,`done`,`if (( _sub_match )); then`,...a.map(e=>` ${e}`),`else`,...$(t,n,r,i),`fi`]}function Qt(e,t,n,r){if(!e.some(e=>e.takesValue&&e.valueCompletion))return[];let i=Xt(e,t,n,r);return i.length===0?[]:[' case "${words[CURRENT-1]}" in',...i,` esac`]}function $t(e,t){let n=[];for(let r of e){let i=r.description?`:${Q(r.description)}`:``;if(r.valueType===`array`){n.push(` _opts+=("--${r.cliName}${i}")`);continue}let a=g(r.cliName,r.alias,r.negation,{isGlobal:r.isGlobal===!0,frameOptions:e}),o=`__${t}_not_used ${a.join(` `)}`,s=r.negationDescription?`:${Q(r.negationDescription)}`:i,c=[{name:r.cliName,desc:i}];r.negation&&c.push({name:r.negation,desc:s});for(let e of c)a.includes(`"--${e.name}"`)&&n.push(` ${o} && _opts+=("--${e.name}${e.desc}")`)}return n.push(` if (( ! _any_opt_used )); then`),n.push(` _opts+=("--help:Show help")`),n.push(` _opts+=("--help-all:Show help with all subcommand options")`),n.push(` _opts+=("--help-json:Show help as JSON")`),n.push(` fi`),n}function en(e,t,n){let r=[...n,e.name],i=r.map(D).join(`_`),a=`__${t}_complete_${i}`,o=A(e.subcommands),s=[];for(let e of o)s.push(...en(e,t,r));s.push(`${a}() {`),s.push(` local -a _vals=()`),s.push(...Qt(e.options,e.positionals,t,i));let c=r.join(`:`);if(s.push(` if __${t}_opt_takes_value "${c}" "\${words[CURRENT-1]}"; then return 0; fi`),e.positionals.length>0?(s.push(` if (( _after_dd )); then`),s.push(...$(e.positionals,t,i,e.options).map(e=>` ${e}`)),s.push(` return 0`),s.push(` fi`)):s.push(` if (( _after_dd )); then return 0; fi`),s.push(' if [[ "${words[CURRENT]}" == -* ]]; then'),s.push(` local -a _opts=()`),s.push(...$t(e.options,t)),s.push(` __${t}_cdescribe 'options' _opts`),s.push(` return 0`),s.push(` fi`),o.length>0){let n=j(e.subcommands);s.push(...Zt(n,e.positionals,t,i,e.options).map(e=>` ${e}`))}else e.positionals.length>0&&s.push(...$(e.positionals,t,i,e.options));return s.push(`}`),s.push(``),s}function tn(e,t){let{programName:n}=t,r=I(e,n,t.globalArgsSchema),i=D(n),a=t.staticWorker?`${i}_${D(t.staticWorker.functionSuffix)}`:i,o=t.staticWorker!==void 0,s=o?`_${a}_completions`:`_${n}`,c=`"\${funcstack[1]:-}" == "${Kt(s)}"`,u=r.command,d=A(u.subcommands),f=je(u),p=Ne(u,f,r.globalOptions),h=f.length>0,g=f.filter(e=>e.isArrayOption),_=g.length>0,v=[];o||(v.push(`#compdef ${n}`),v.push(``)),v.push(...z({programName:n,shell:`zsh`,binPath:t.binPath,programVersion:t.programVersion})),v.push(`# politty-completion-mode: ${o?`worker`:`static`}`),o&&v.push(`# politty-completion-worker: true`),v.push(`# Generated by politty`),v.push(``),o||v.push(...ze({programName:n,binPath:t.binPath}));for(let e of f){let t=k(a,e.funcSuffix,e.fieldName);if(e.vc.table.length===0)v.push(`typeset -gA ${t}=()`);else{v.push(`typeset -gA ${t}=(`);for(let t of e.vc.table){let e=t.key.join(``),n=t.candidates.map(e=>{let t=Gt(e.value);return e.description?`${t}:${e.description}`:t}).join(`
|
|
99
|
-
`);v.push(` ${l(e)} ${l(n)}`)}v.push(`)`)}v.push(``)}F(u)&&(v.push(...ge(a,n)),v.push(``),v.push(`__${a}_apply_dynamic_output() {`),v.push(` local _raw="$1"`),v.push(` local _directive=0`),v.push(` local -a _vals _lines`),v.push(' _lines=("${(@f)_raw}")'),v.push(` local _last=$#_lines`),v.push(' if (( _last >= 1 )) && [[ "${_lines[$_last]}" == :<-> ]]; then'),v.push(' _directive="${_lines[$_last]#:}"'),v.push(` _lines[$_last]=()`),v.push(` fi`),v.push(` local _l`),v.push(' for _l in "${_lines[@]}"; do'),v.push(` [[ -z "$_l" ]] && continue`),v.push(` _vals+=("$_l")`),v.push(` done`),v.push(" if (( ${#_vals[@]} > 0 )); then"),v.push(` if (( _directive & ${m.NoSpace} )); then`),v.push(` __${a}_cdescribe 'completions' _vals -S ''`),v.push(` else`),v.push(` __${a}_cdescribe 'completions' _vals`),v.push(` fi`),v.push(` fi`),v.push(` if (( _directive & ${m.DirectoryCompletion} )); then`),v.push(` _files -/`),v.push(` elif (( _directive & ${m.FileCompletion} )); then`),v.push(` _files`),v.push(` elif (( \${#_vals[@]} == 0 )) && ! (( _directive & ${m.NoFileCompletion} )); then`),v.push(` _files`),v.push(` fi`),v.push(`}`),v.push(``)),v.push(`__${a}_not_used() {`),v.push(` local _u _chk`),v.push(' for _u in "${_used_opts[@]}"; do'),v.push(` for _chk in "$@"; do`),v.push(` [[ "$_u" == "$_chk" ]] && return 1`),v.push(` done`),v.push(` done`),v.push(` return 0`),v.push(`}`),v.push(``),v.push(`__${a}_cdescribe() {`),v.push(` _describe "$@" 2>/dev/null && return 0`),v.push(` shift`),v.push(` local _cd_arr="$1"`),v.push(` shift`),v.push(' local -a _cd_vals=("${(@)${(P)_cd_arr}%%:*}")'),v.push(` compadd "$@" -a _cd_vals 2>/dev/null`),v.push(` return 0`),v.push(`}`),v.push(``),v.push(`__${a}_add_path_candidate() {`),v.push(` compadd -f -- "$1" 2>/dev/null && return 0`),v.push(` print -r -- "$1"`),v.push(`}`),v.push(``),v.push(`__${a}_opt_takes_value() {`),v.push(` case "$1:$2" in`),v.push(...we(u,``)),v.push(` esac`),v.push(` return 1`),v.push(`}`),v.push(``),h&&(v.push(`__${a}_track_opt() {`),v.push(` case "$1:$2" in`),v.push(...Oe(p,`zsh`)),v.push(` esac`),v.push(`}`),v.push(``),v.push(`__${a}_track_pos() {`),v.push(` case "$1:$2" in`),v.push(...ke(p,`zsh`)),v.push(` esac`),v.push(`}`),v.push(``)),_&&(v.push(`__${a}_track_array_expand() {`),v.push(` case "$1:$2" in`),v.push(...Ae(g,`zsh`)),v.push(` esac`),v.push(`}`),v.push(``));let y=N(u);y.length>0&&(v.push(`__${a}_is_subcmd() {`),v.push(` case "$1:$2" in`),v.push(...Te(y)),v.push(` esac`),v.push(` return 1`),v.push(`}`),v.push(``));for(let e of d)v.push(...en(e,a,[]));if(v.push(`__${a}_complete_root() {`),v.push(` local -a _vals=()`),v.push(...Qt(u.options,u.positionals,a,`root`)),v.push(` if __${a}_opt_takes_value "" "\${words[CURRENT-1]}"; then return 0; fi`),u.positionals.length>0?(v.push(` if (( _after_dd )); then`),v.push(...$(u.positionals,a,`root`,u.options).map(e=>` ${e}`)),v.push(` return 0`),v.push(` fi`)):v.push(` if (( _after_dd )); then return 0; fi`),v.push(' if [[ "${words[CURRENT]}" == -* ]]; then'),v.push(` local -a _opts=()`),v.push(...$t(u.options,a)),v.push(` __${a}_cdescribe 'options' _opts`),d.length>0){v.push(` else`);let e=j(u.subcommands);v.push(...Zt(e,u.positionals,a,`root`,u.options).map(e=>` ${e}`))}else u.positionals.length>0&&(v.push(` else`),v.push(...$(u.positionals,a,`root`,u.options).map(e=>` ${e}`)));v.push(` fi`),v.push(`}`),v.push(``);let ee=Ee(y,a).join(`
|
|
100
|
-
`);v.push(`${s}() {`),v.push(" (( CURRENT )) || CURRENT=${#words}"),v.push(``),v.push(` local _subcmd="" _after_dd=0 _pos_count=0 _skip_next=0`),v.push(` local -a _used_opts=()`),v.push(` local _any_opt_used=0`),h&&(v.push(` local -A _arg_values=()`),v.push(` local -A _global_arg_values=()`)),_&&(v.push(` local -A _used_field_keys=()`),v.push(` local -A _global_used_field_keys=()`),v.push(` local -A _global_arr_seen=()`)),v.push(``),v.push(` local _j=2`),v.push(` while (( _j < CURRENT )); do`),v.push(' local _w="${words[_j]}"'),v.push(` if (( _skip_next )); then _skip_next=0; (( _j++ )); continue; fi`),v.push(` if [[ "$_w" == "--" ]]; then _after_dd=1; (( _j++ )); continue; fi`);let b=h?`__${a}_track_pos "$_subcmd" "$_pos_count" "$_w"; `:``;v.push(` if (( _after_dd )); then ${b}(( _pos_count++ )); (( _j++ )); continue; fi`),v.push(` if [[ "$_w" == -*=* ]]; then`),v.push(' _used_opts+=("${_w%%=*}")'),v.push(` _any_opt_used=1`),h&&(v.push(` __${a}_track_opt "$_subcmd" "\${_w%%=*}" "\${_w#*=}"`),_&&v.push(` __${a}_track_array_expand "$_subcmd" "\${_w%%=*}" "\${_w#*=}"`)),v.push(` (( _j++ )); continue`),v.push(` fi`),v.push(` if [[ "$_w" == -* ]]; then`),v.push(` _used_opts+=("$_w")`),v.push(` _any_opt_used=1`),v.push(` if __${a}_opt_takes_value "$_subcmd" "$_w"; then`),v.push(' local _next="${words[_j+1]:-}"'),v.push(` if [[ -n "$_next" && "$_next" != -* ]]; then _skip_next=1; fi`),h&&(v.push(` if (( _skip_next )); then`),v.push(` __${a}_track_opt "$_subcmd" "$_w" "$_next"`),_&&(v.push(` if (( _j + 1 < CURRENT )); then`),v.push(` __${a}_track_array_expand "$_subcmd" "$_w" "$_next"`),v.push(` fi`)),v.push(` fi`)),v.push(` fi`),v.push(` (( _j++ )); continue`),v.push(` fi`);let x=_?`; _arg_values=(); _used_field_keys=(); _global_arr_seen=()`:h?`; _arg_values=()`:``,S=h?`__${a}_track_pos "$_subcmd" "$_pos_count" "$_w"; `:``;return y.length>0?v.push(` if __${a}_is_subcmd "$_subcmd" "$_w"; then _subcmd="\${_subcmd:+\${_subcmd}:}$_w"; _used_opts=(); _pos_count=0${x}; else ${S}(( _pos_count++ )); fi`):(h&&v.push(` __${a}_track_pos "$_subcmd" "$_pos_count" "$_w"`),v.push(` (( _pos_count++ ))`)),v.push(` (( _j++ ))`),v.push(` done`),v.push(``),v.push(` case "$_subcmd" in`),v.push(ee),v.push(` *) __${a}_complete_root ;;`),v.push(` esac`),v.push(`}`),v.push(``),v.push(`zstyle ':completion:*:*:${n}:*' file-patterns '%p:globbed-files *(-/):directories'`),v.push(``),o||(v.push(`if [[ ${c} ]]; then`),v.push(` ${s} "$@"`),v.push(`else`),v.push(` compdef ${s} ${n}`),v.push(`fi`),v.push(``)),{script:v.join(`
|
|
101
|
-
`),shell:`zsh`,installInstructions:`# To enable auto-refreshing zsh completions, add this to your ~/.zshrc after compinit:
|
|
102
|
-
eval "$(${n} completion zsh --static)"
|
|
103
|
-
|
|
104
|
-
# For faster shell startup, save the script in your fpath:
|
|
105
|
-
mkdir -p ~/.zsh/completions
|
|
106
|
-
${n} completion zsh --static > ~/.zsh/completions/_${n}
|
|
107
|
-
|
|
108
|
-
# Make sure your ~/.zshrc includes the fpath line before compinit:
|
|
109
|
-
fpath=(~/.zsh/completions $fpath)
|
|
110
|
-
autoload -Uz compinit && compinit
|
|
111
|
-
|
|
112
|
-
# If ~/.zshrc already calls compinit, add only the fpath line before
|
|
113
|
-
# the existing compinit call.
|
|
114
|
-
|
|
115
|
-
# Then reload your shell or run:
|
|
116
|
-
source ~/.zshrc`}}function nn(e,t){if(t.mode===`dispatcher`)return Ct(e,t);switch(t.shell){case`bash`:return Ye(e,t);case`zsh`:return tn(e,t);case`fish`:return Nt(e,t);default:throw Error(`Unsupported shell: ${t.shell}`)}}function rn(){return[`bash`,`zsh`,`fish`]}function an(e,t){console.error(``),console.error(`Configure zsh fpath with:`),console.error(``),console.error(` mkdir -p ~/.zsh/completions`),console.error(` ln -sf ${p(t)} ~/.zsh/completions/_${e}`),console.error(``),console.error(`Add only this block to your ~/.zshrc before compinit:`),console.error(``),console.error(` fpath=(~/.zsh/completions $fpath)`),console.error(` autoload -Uz compinit && compinit`)}function on(e,n,r,i={}){let o=n??e.name,{cacheDir:s,programVersion:l}=i,u={...s!==void 0&&{cacheDir:s},...l!==void 0&&{programVersion:l},...r!==void 0&&{globalArgsSchema:r},...i.bundledWorker!==void 0&&{bundledWorker:i.bundledWorker}},d={programName:o,...u},f={programName:o,...s!==void 0&&{cacheDir:s}};return e.subCommands?.__complete||(e.subCommands={...e.subCommands,__complete:y(e,o,r)}),e.subCommands?.[`__refresh-completion`]||(e.subCommands={...e.subCommands,"__refresh-completion":sn(e,o,u)}),e.subCommands?.[`__completion-worker-path`]||(e.subCommands={...e.subCommands,"__completion-worker-path":cn(o,u)}),t({name:`completion`,description:`Generate shell completion script`,args:a,run(t){let n=t.shell||c();if(!n){console.error(`Could not detect shell type. Please specify one of: bash, zsh, fish`),process.exitCode=1;return}if(t.static&&t.dispatcher)throw Error(`Choose only one completion mode: --dispatcher or --static.`);if(t.worker&&!t.static)throw Error("`--worker` requires `--static`.");if(t.worker&&(t.install||t.loader||t.instructions))throw Error("`--worker` can only print a worker artifact.");let a=t.static?`static`:`dispatcher`;if(t.install){let t;try{t=It({rootCommand:e,...d,completionMode:a},n)}catch(e){throw Error(`install failed: ${e instanceof Error?e.message:String(e)}`)}console.error(`installed: ${t}`),n===`bash`?(console.error(``),console.error(`Add to your ~/.${n}rc:`),console.error(``),console.error(Wt({...f,shell:n}).trim().replace(/^/gm,` `))):n===`zsh`&&an(o,t);return}if(t.loader){if(n===`fish`)throw Error("fish does not use an rc loader. Run `<program> completion fish --install` to write the self-refreshing autoload file instead.");process.stdout.write(Wt({...f,shell:n}));return}let u=nn(e,{shell:n,programName:o,mode:a,includeDescriptions:!0,...r!==void 0&&{globalArgsSchema:r},...l!==void 0&&{programVersion:l},...s!==void 0&&{cacheDir:s},...i.bundledWorker!==void 0&&{bundledWorker:i.bundledWorker},...t.worker&&{staticWorker:{functionSuffix:`worker`}}});t.instructions?console.log(u.installInstructions):console.log(u.script)}})}function sn(e,n,r={}){return t({name:`__refresh-completion`,description:`(internal) Refresh the on-disk completion cache if stale.`,args:s,run(t){Bt({rootCommand:e,programName:n,...r,completionMode:t.static||t.worker?`static`:void 0,...t.worker&&{staticWorker:{functionSuffix:`worker`}},...t.worker&&{allowTargetCreate:!0},...t.target!==void 0&&{targetPath:t.target}},t.shell)}})}function cn(e,n={}){return t({name:`__completion-worker-path`,description:`(internal) Print the bundled completion worker path when available.`,args:i,run(t){let r=ct({programName:e,shell:t.shell,...n.binPath!==void 0&&{binPath:n.binPath},...n.bundledWorker!==void 0&&{bundledWorker:n.bundledWorker}});if(!r)throw Error(`No bundled completion worker found for ${e} (${t.shell}).`);console.log(r)}})}export{rn as a,mt as c,ve as d,nn as i,U as l,cn as n,$e as o,sn as r,et as s,on as t,I as u};
|
package/dist/dynamic-BBr42fJH.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./dynamic-BK6Tq_FR.js";export{e as createDynamicCompleteCommand};
|
package/dist/dynamic-BK6Tq_FR.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{i as e,n as t}from"./field-meta-D7G8a7IG.js";import{t as n}from"./schema-extractor-QpSHJvwI.js";import{n as r}from"./command-tLHaJHe6.js";import{c as i,i as a}from"./subcommand-router-D8GTMXYL.js";import{t as o}from"./schema-ohwvrBGz.js";import{execSync as s}from"node:child_process";function c(e,t,n){return{fieldName:e.name,isArrayOption:e.valueType===`array`,isGlobal:e.isGlobal===!0,resolvedDeps:u(e.valueCompletion,e.isGlobal===!0,t,n)}}function l(e,t,n){return{fieldName:e.name,isArrayOption:!1,isGlobal:!1,resolvedDeps:u(e.valueCompletion,!1,t,n)}}function u(e,t,n,r=[]){if(e?.type!==`expand`)return[];let i=new Set,a=new Set;for(let e of n)e.isGlobal===!0?i.add(e.name):a.add(e.name);for(let e of r)a.add(e.name);return e.dependsOn.map(e=>({name:e,isGlobal:t||i.has(e)&&!a.has(e)}))}function d(e){let t=`$'`;for(let n of e){let e=n.codePointAt(0);t+=n===`\\`?`\\\\`:n===`'`?`\\'`:n===`
|
|
2
|
-
`?`\\n`:n===`\r`?`\\r`:n===` `?`\\t`:e<32||e===127?`\\x${e.toString(16).padStart(2,`0`)}`:n}return t+=`'`,t}function f(e){return`'${e.replace(/'/g,`'\\''`)}'`}function p(e,t){let n=t.withSize?`%Y:%s`:`%Y`,r=t.withSize?`%m:%z`:`%m`,i=`stat -L -c '${n}' "${e}" 2>/dev/null`,a=`stat -L -f '${r}' "${e}" 2>/dev/null`;return t.shell===`fish`?`(${i}; or ${a})`:`$(${i} || ${a})`}function m(e){return e.length===1?`-${e}`:`--${e}`}function h(t,n){g(t,m(n)),n.length===1?g(t,`--${n}`):n.includes(`-`)&&g(t,`--${e(n)}`)}function g(e,t){e.includes(t)||e.push(t)}function _(t,n){let r=[`--${t}`];t.length===1&&r.push(`-${t}`),t.includes(`-`)&&r.push(`--${e(t)}`);for(let e of n??[])h(r,e);return r}function v(e){let t=new Set;for(let n of e)if(n.isGlobal===!0){n.cliName.length===1&&t.add(`-${n.cliName}`);for(let e of n.alias??[])e.length===1&&t.add(`-${e}`)}return t}function y(t,n,r,i){let a=new Set(_(t,n));if(r&&(a.add(`--${r}`),r.includes(`-`)&&a.add(`--${e(r)}`)),i?.frameOptions){if(i.isGlobal===!0){for(let e of i.frameOptions)if(e.isGlobal!==!0)for(let t of b(e.cliName,e.alias))a.delete(t)}else{let e=v(i.frameOptions);if(e.size>0){let t=new Set((n??[]).filter(e=>e.length===1).map(e=>`-${e}`));for(let n of e)t.has(n)||a.delete(n)}}}return[...a].map(e=>`"${e}"`)}function b(t,n){let r=[`--${t}`];t.includes(`-`)&&r.push(`--${e(t)}`);for(let e of n??[])h(r,e);return r}function x(e){let t=e.completion;if(t?.custom){let n=t.custom,r=[];if(n.expand&&r.push(`expand`),n.resolve&&r.push(`resolve`),n.choices&&n.choices.length>0&&r.push(`choices`),n.shellCommand&&r.push(`shellCommand`),r.length>1)throw Error(`Field "${e.name??`<unknown>`}": completion.custom may only specify one of choices, shellCommand, resolve, expand (got ${r.join(`, `)}).`);if(n.expand)return{type:`pending-expand`,spec:n.expand};if(n.resolve)return{type:`dynamic`,resolve:n.resolve};if(n.choices&&n.choices.length>0)return{type:`choices`,choices:n.choices};if(n.shellCommand)return{type:`command`,shellCommand:n.shellCommand}}if(t?.type){if(t.type===`file`)return t.matcher?{type:`file`,matcher:t.matcher}:t.extensions?{type:`file`,extensions:t.extensions}:{type:`file`};if(t.type===`directory`)return{type:`directory`};if(t.type===`none`)return{type:`none`}}if(e.enumValues&&e.enumValues.length>0)return{type:`choices`,choices:e.enumValues}}function S(e){if(e)return e.type===`pending-expand`?{type:`runtime-expand`,dependsOn:e.spec.dependsOn,enumerate:e.spec.enumerate}:e}function C(e){return e.args?w(e.args):[]}function w(e){return n(e).fields.filter(e=>!e.positional).map(e=>{let n=t(e);return{name:e.name,cliName:e.cliName,alias:n.length>0?n:void 0,negation:e.negationDisplay,negationDescription:e.negationDescription,description:e.description,takesValue:e.type!==`boolean`,valueType:e.type,required:e.required,defaultNegationAccepted:e.type===`boolean`&&e.negation===!0,valueCompletion:S(x(e))}})}function T(e){return new Set(_(e.cliName,e.alias))}function ee(e,t){let n=T(t);for(let t of e)for(let e of T(t))if(n.has(e))return t}function te(e,t,n){let r=new Set;if(t.length===0)return r;let i=new Set,a=(e,t)=>{I(n,e,t,i),r.add(e.name)},o=0;for(;o<e.length;){let i=e[o];if(i===`--`||!i.startsWith(`-`))break;if(!i.startsWith(`--`)&&i.length>2){let e=i.indexOf(`=`);if((e>=0?i.slice(1,e):i.slice(1)).length>1)break}let s=A(i),c=z(t,s);if(!c){if(P(t,s)){o++;continue}break}if(c.takesValue){if(j(i)){let e=i.indexOf(`=`);a(c,i.slice(e+1)),o++}else if(o+1<e.length){let t=e[o+1];if(t.startsWith(`-`)){o++;continue}a(c,t),o+=2}else break}else n[c.name]=!L(c,s),r.add(c.name),o++}return r}function ne(e,t){return t.valueType===`array`?Array.isArray(e)?e:[e]:Array.isArray(e)?e.at(-1):e}function E(e,t){return t.length===0?e:[...e,...t]}function D(e,t){let n=t.length-1;if(!(n<0))return e>n?n:e}function O(e){return e.args?n(e.args).fields.filter(e=>e.positional).map((e,t)=>({name:e.name,cliName:e.cliName,position:t,description:e.description,required:e.required,variadic:e.type===`array`,valueCompletion:S(x(e))})):[]}function re(e){if(!e.subCommands)return[];let t=[];for(let[n,r]of Object.entries(e.subCommands)){if(n.startsWith(`__`))continue;t.push(n);let e=i(r);e?.aliases&&t.push(...e.aliases)}return t}function ie(e,t){if(!e.subCommands)return null;let n=Object.hasOwn(e.subCommands,t)?e.subCommands[t]:void 0;if(n)return i(n);let r=a(e,t);return r?i(e.subCommands[r]):null}function k(e){return e.startsWith(`-`)}function A(e){if(e.startsWith(`--`)){let t=e.slice(2),n=t.indexOf(`=`);return{name:n>=0?t.slice(0,n):t,isLong:!0}}return e.startsWith(`-`)?{name:e.slice(1,2),isLong:!1}:{name:e,isLong:!0}}function j(e){return e.includes(`=`)}function M(t,n,r){if(!r||t.valueType!==`boolean`)return!1;let i=[t.cliName,...t.alias??[]];for(let t of i){let r=`no-${t}`;if(n===r||n===e(r))return!0}return!1}function N(e,t,n){return e.defaultNegationAccepted===!0&&M(e,t,n)}function P(e,t){return e.some(e=>e.defaultNegationAccepted!==!0&&M(e,t.name,t.isLong))}function F(t,n){return t!==void 0&&t.includes(`-`)&&e(t)===n}function I(e,t,n,r){if(t.valueType!==`array`){e[t.name]=n;return}if(r.has(t.name)){let r=e[t.name];e[t.name]=Array.isArray(r)?[...r,n]:[n]}else e[t.name]=[n],r.add(t.name)}function L(e,t){return t.isLong?e.negation!==void 0&&(e.negation===t.name||F(e.negation,t.name))?!0:N(e,t.name,t.isLong):!1}function R(e,t,n){if(e.cliName===t&&(n||e.cliName.length===1))return!0;if(e.alias){for(let r of e.alias)if(r===t&&(n||r.length===1))return!0}return n&&e.negation===t?!0:!n||t.length<=1?!1:F(e.cliName,t)||e.alias?.some(e=>F(e,t))?!0:F(e.negation,t)}function z(e,t){if(!t.isLong){let n=e.find(e=>e.isGlobal!==!0&&e.alias?.includes(t.name)===!0);if(n)return n;let r=e.find(e=>e.isGlobal===!0&&R(e,t.name,t.isLong));if(r)return r}return e.find(e=>R(e,t.name,t.isLong))||e.find(e=>N(e,t.name,t.isLong))}function B(e,t,n){let r=t,i=[],a=n?w(n).map(e=>({...e,isGlobal:!0})):[],o=new Set,s=!1,c=0,l={},u=[],d={},f=new Set,p=0,m=new Set,h=e=>{o.add(e.cliName);for(let t of e.alias??[])o.add(t);e.negation&&o.add(e.negation),s=!0},g=(e,t)=>{I(e.isGlobal===!0?d:l,e,t,m)},_=(e,t)=>{let n=e.isGlobal===!0?d:l;n[e.name]=!L(e,t)},v=0,y=E(C(r),a),b=!1;for(;v<e.length-1;){let t=e[v];if(!b&&t===`--`){b=!0,v++;continue}if(!b&&t.startsWith(`-`)&&!t.startsWith(`--`)&&t.length>2&&!t.includes(`=`)){s=!0;let e=Array.from(t.slice(1)),n=y.filter(e=>e.isGlobal!==!0);for(let t of e){let e=z(n,{name:t,isLong:!1});e&&!e.takesValue&&(h(e),_(e,{name:t,isLong:!1}))}v++;continue}if(!b&&k(t)){s=!0;let n=A(t),r=z(y,n);if(r){if(h(r),r.takesValue){if(j(t)){let e=t.indexOf(`=`);g(r,t.slice(e+1))}else if(v+1<e.length-1){let t=e[v+1];k(t)||(g(r,t),v++)}}else _(r,n)}v++;continue}let n=b?null:ie(r,t);if(n){i.push(t);let s=C(r),h=e.slice(p,v);for(let e of te(h,a,d))f.add(e);r=n,y=E(C(r),a);for(let e of Object.keys(l)){let t=s.find(t=>t.name===e),n=a.find(t=>t.name===e)??(t?ee(a,t):void 0);n&&(f.has(n.name)||(d[n.name]=ne(l[e],n)))}o.clear(),c=0,l={},u=[],m=new Set,p=v+1,v++;continue}u.push(t),c++,v++}let x=e[e.length-1]??``,S=e[e.length-2]??``,T=O(r),M=re(r);for(let e=0;e<T.length;e++){let t=T[e];if(t.variadic){l[t.name]=u.slice(e);break}e<u.length&&(l[t.name]=u[e])}let N,P,F;if(!b&&S&&k(S)&&!j(S)){let e=z(y,A(S));e&&e.takesValue?(N=`option-value`,P=e):x.startsWith(`-`)?N=`option-name`:(N=V(x,M,T,c),N===`positional`&&(F=c))}else if(!b&&x.startsWith(`-`)&&j(x)){let e=z(y,A(x));e&&e.takesValue?(N=`option-value`,P=e):N=`option-name`}else!b&&x.startsWith(`-`)?N=`option-name`:(N=V(x,M,T,c,b),N===`positional`&&(F=c));let R=[];if(P){if(P.valueType===`array`){let e=(P.isGlobal===!0?d:l)[P.name];R=Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}}else if(N===`positional`&&F!==void 0){let e=D(F,T);e!==void 0&&T[e]?.variadic&&(R=u.slice(e))}let B={...d,...l};return{subcommandPath:i,currentCommand:r,currentWord:x,previousWord:S,completionType:N,targetOption:P,positionalIndex:F,options:y,subcommands:M,positionals:T,usedOptions:o,hasAnyOptionBeenUsed:s,providedPositionalCount:c,parsedArgs:B,previousValues:R}}function V(e,t,n,r,i){return i?`positional`:t.length>0&&(t.filter(t=>t.startsWith(e)).length>0||e===``)?`subcommand`:r<n.length||n.length>0&&n[n.length-1].variadic?`positional`:`subcommand`}const H={Default:0,NoSpace:1,NoFileCompletion:2,FilterPrefix:4,KeepOrder:8,FileCompletion:16,DirectoryCompletion:32,Error:64};function U(e){if(!e.startsWith(`-`))return;let t=e.indexOf(`=`);if(!(t<=0))return e.slice(0,t+1)}async function W(e,t){switch(e.completionType){case`subcommand`:return ue(e);case`option-name`:return Y(e);case`option-value`:{let n=e.targetOption,r=n?U(e.currentWord):void 0;return X(r?{...e,currentWord:e.currentWord.slice(r.length)}:e,t,n?.name,n?.valueCompletion,void 0,n?.valueType===`array`)}case`positional`:{let n=G(e);return n?X(e,t,n.name,n.valueCompletion,n.description,!1):{candidates:[],directive:H.NoFileCompletion}}}}function G(e){let t=e.positionalIndex??0,n=D(t,e.positionals);if(n===void 0)return;let r=e.positionals[n];if(r)return n===t||r.variadic?r:void 0}function K(e){try{return s(e,{encoding:`utf-8`,timeout:5e3}).split(`
|
|
3
|
-
`).map(e=>e.trim()).filter(e=>e.length>0).map(e=>({value:e,type:`value`}))}catch{return[]}}function q(e){return e?.type===`choices`?e.choices:void 0}function J(e,t){let n=e.options.find(e=>e.name===t&&e.isGlobal!==!0);if(n)return q(n.valueCompletion);let r=e.positionals.find(e=>e.name===t);return q(r?r.valueCompletion:e.options.find(e=>e.name===t&&e.isGlobal===!0)?.valueCompletion)}function ae(e,t){let n=!t.includes(`=`),r=n?oe(e):se(e,t);return{candidates:r,hasEqSuffix:n&&r.some(e=>e.value.endsWith(`=`))}}function oe(e){let t=new Set,n=[];for(let r of e){let e=r.value.indexOf(`=`);if(e<=0){n.push(r);continue}let i=r.value.slice(0,e+1);t.has(i)||(t.add(i),n.push({...r,value:i}))}return n}function se(e,t){let n=t.slice(0,t.indexOf(`=`)+1);return e.filter(e=>e.value!==n)}async function ce(e,t,n,r,i){let a=[],o=H.FilterPrefix,s,c;switch(e.type){case`choices`:if(e.choices)for(let t of e.choices)a.push({value:t,description:r,type:`value`});o|=H.NoFileCompletion;break;case`file`:e.matcher&&e.matcher.length>0?(c=e.matcher.filter(e=>e.trim().length>0),c.length===0&&(c=void 0,o|=H.FileCompletion)):e.extensions&&e.extensions.length>0?(s=Array.from(new Set(e.extensions.map(e=>e.trim().replace(/^\./,``)).filter(e=>e.length>0))),s.length===0&&(s=void 0,o|=H.FileCompletion)):o|=H.FileCompletion;break;case`directory`:o|=H.DirectoryCompletion;break;case`command`:e.shellCommand&&a.push(...K(e.shellCommand)),o|=H.NoFileCompletion;break;case`none`:o|=H.NoFileCompletion;break;case`dynamic`:try{let n=await e.resolve(t);for(let e of n.candidates){let t=typeof e==`string`?{value:e}:e;a.push({...t,type:`value`})}o=n.directive??H.FilterPrefix|H.NoFileCompletion}catch{o=H.NoFileCompletion|H.Error}break;case`expand`:o|=H.NoFileCompletion;break;case`runtime-expand`:{let r={},i=!1;for(let a of e.dependsOn){let e=t.parsedArgs[a],o=Array.isArray(e)?e[e.length-1]:e,s=J(n,a);if(typeof o!=`string`||s===void 0||!s.includes(o)){i=!0;break}r[a]=o}if(!i)try{let t=new Set;for(let n of e.enumerate(r)){let e=typeof n==`string`?{value:n}:n;t.has(e.value)||(t.add(e.value),a.push({...e,type:`value`}))}}catch{o=H.NoFileCompletion|H.Error;break}o|=H.NoFileCompletion;break}}if(e.type===`dynamic`||e.type===`expand`||e.type===`runtime-expand`){let n=ae(e.type===`runtime-expand`&&i===!0?le(a,t.previousValues):a,t.currentWord);return n.hasEqSuffix&&(o|=H.NoSpace),{candidates:n.candidates,directive:o,fileExtensions:s,fileMatchers:c}}return{candidates:a,directive:o,fileExtensions:s,fileMatchers:c}}function le(e,t){let n=new Set;for(let e of t){let t=e.indexOf(`=`);t>0&&n.add(e.slice(0,t))}return n.size===0?[...e]:e.filter(e=>{let t=e.value.indexOf(`=`);return t<=0||!n.has(e.value.slice(0,t))})}function ue(e){let t=[];for(let n of e.subcommands){let r=e.currentCommand.subCommands,o=r?.[n],s=o?void 0:a(e.currentCommand,n),c=o??(s?r?.[s]:void 0),l=c?i(c)?.description:void 0;t.push({value:n,description:l,type:`subcommand`})}if(t.length===0||e.currentWord.startsWith(`-`)){let n=Y(e);t.push(...n.candidates)}return{candidates:t,directive:H.FilterPrefix|H.NoFileCompletion}}function Y(e){let t=[],n=e.options.filter(t=>t.valueType===`array`||!(e.usedOptions.has(t.cliName)||t.alias&&t.alias.some(t=>e.usedOptions.has(t))||t.negation&&e.usedOptions.has(t.negation)));for(let e of n)t.push({value:`--${e.cliName}`,description:e.description,type:`option`}),e.negation&&t.push({value:`--${e.negation}`,description:e.negationDescription??e.description,type:`option`});return e.hasAnyOptionBeenUsed||t.push({value:`--help`,description:`Show help information`,type:`option`},{value:`--help-all`,description:`Show help with all subcommand options`,type:`option`},{value:`--help-json`,description:`Show help as JSON`,type:`option`}),{candidates:t,directive:H.FilterPrefix|H.NoFileCompletion}}function de(e,t,n){return{currentWord:e.currentWord,shell:t.shell,parsedArgs:fe(e.parsedArgs,n),previousValues:e.previousValues,subcommandPath:e.subcommandPath}}function fe(e,t){if(t===void 0||!(t in e))return e;let n={...e};return delete n[t],n}async function X(e,t,n,r,i,a){return r?ce(r,de(e,t,n),e,i,a):{candidates:[],directive:H.FilterPrefix}}function Z(e,t){switch(t.shell){case`bash`:return $(e,t);case`zsh`:return pe(e,t);case`fish`:return me(e,t)}}function Q(e,t){let n=`:${t.directive}`;t.fileExtensions&&t.fileExtensions.length>0&&(n+=`\t@ext:${t.fileExtensions.join(`,`)}`),t.fileMatchers&&t.fileMatchers.length>0&&(n+=`\t@matcher:${t.fileMatchers.join(`,`)}`),e.push(n)}function $(e,t){let n=((e.directive&H.FilterPrefix)!==0&&t.currentWord?e.candidates.filter(e=>e.value.startsWith(t.currentWord)):e.candidates).map(e=>t.inlinePrefix?`${t.inlinePrefix}${e.value}`:e.value);return Q(n,e),n.join(`
|
|
4
|
-
`)}function pe(e,t){let n=e.candidates.map(e=>{let t=e.value.replace(/:/g,`\\:`);return e.description?`${t}:${e.description.replace(/:/g,`\\:`)}`:t});return Q(n,e),n.join(`
|
|
5
|
-
`)}function me(e,t){let n=e.candidates.map(e=>e.description?`${e.value}\t${e.description}`:e.value);return Q(n,e),n.join(`
|
|
6
|
-
`)}function he(e,t,n){return r({name:`__complete`,args:o,async run(t){let r=B(t.args,e,n),i=r.completionType===`option-value`&&r.targetOption?U(r.currentWord):void 0,a=i?r.currentWord.slice(i.length):r.currentWord,o=Z(await W(r,{shell:t.shell}),{shell:t.shell,currentWord:a,inlinePrefix:i});console.log(o)}})}function ge(e){return!!e.subCommands?.__complete}export{W as a,d as c,b as d,c as f,p as g,f as h,H as i,_ as l,y as m,ge as n,B as o,l as p,Z as r,x as s,he as t,v as u};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
let e;function t(t){e=t}function n(){if(!e)throw Error('No validator adapter registered. Import politty through an adapter package (e.g. `import { defineCommand } from "@politty/zod"` or `from "politty"`) so the schema library integration is set up.');return e}const r=new Set([`help`,`help-all`,`help-json`,`version`]);function i(e){return e.replace(/([a-z])([A-Z])/g,`$1-$2`).replace(/([A-Z]+)([A-Z][a-z])/g,`$1-$2`).toLowerCase()}function a(e){return e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function o(e){return!e.alias&&!e.hiddenAlias?[]:[...e.alias??[],...e.hiddenAlias??[]]}function s(e,t){let n=t.argMeta,a=n?.description??t.description,o=i(e),s=/^[A-Za-z0-9][A-Za-z0-9-]*$/,c=(t,n)=>{if(t==null)return;let r=(Array.isArray(t)?t:[t]).map(t=>{if(typeof t!=`string`)throw Error(`Invalid ${n} for field "${e}": expected string or string[], received ${typeof t}.`);let r=t.trim().replace(/^-+/,``);if(r.length===0||!s.test(r))throw Error(`Invalid ${n} "${t}" for field "${e}": aliases must match ${s}.`);return r}),i=Array.from(new Set(r));return i.length>0?i:void 0},l=c(n?.alias,`alias`),u=new Set(l??[]),d=c(n?.hiddenAlias,`hiddenAlias`)?.filter(e=>!u.has(e)),f=d&&d.length>0?d:void 0,p=t.type,m=n?.negation,h;if(m!=null){if(typeof m==`boolean`){if(p!==`boolean`)throw Error(`Invalid negation for field "${e}": negation can only be used on boolean fields.`);h=m}else{if(typeof m!=`string`)throw Error(`Invalid negation for field "${e}": expected string or boolean, received ${typeof m}.`);let t=m.trim().replace(/^-+/,``);if(t.length===0||!s.test(t))throw Error(`Invalid negation "${m}" for field "${e}": negation names must match ${s}.`);if(r.has(t))throw Error(`Invalid negation "${m}" for field "${e}": negation cannot use reserved built-in flag names (${[...r].map(e=>`--${e}`).join(`, `)}).`);if(p!==`boolean`)throw Error(`Invalid negation for field "${e}": negation can only be used on boolean fields.`);h=t}}let g=n?.negationDescription,_;if(g!=null){if(typeof g!=`string`)throw Error(`Invalid negationDescription for field "${e}": expected string, received ${typeof g}.`);if(h===!1)throw Error(`Invalid negationDescription for field "${e}": negationDescription cannot be used when negation is false.`);if(h===void 0)throw Error(`Invalid negationDescription for field "${e}": negationDescription requires \`negation\` to be set (string or true).`);let t=g.trim();if(t.length===0)throw Error(`Invalid negationDescription for field "${e}": negationDescription must be a non-empty string.`);_=t}let v=typeof h==`string`?h:h===!0?`no-${o}`:void 0,y={name:e,cliName:o,alias:l,hiddenAlias:f,description:a,positional:n?.positional??!1,placeholder:n?.placeholder,env:n?.env,required:t.required,defaultValue:t.defaultValue,type:p,schema:t.schema,enumValues:t.enumValues,completion:n?.completion,prompt:n?.prompt,negation:h,negationDisplay:v,negationDescription:_,effect:n?.effect};return n&&`overrideBuiltinAlias`in n&&n.overrideBuiltinAlias===!0&&(y.overrideBuiltinAlias=!0),y}export{i as a,a as i,o as n,n as o,s as r,t as s,r as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{StringDecoder as e}from"node:string_decoder";const t={log:`stdout`,info:`stdout`,debug:`stdout`,warn:`stderr`,error:`stderr`},n=[`log`,`info`,`debug`,`warn`,`error`];function r(e){return e.map(e=>{if(e instanceof Error)return e.message;if(typeof e==`object`&&e)try{return JSON.stringify(e)}catch{return String(e)}return String(e)}).join(` `)}function i(e){return e.replace(/\r?\n$/,``)}function a(a={}){let o=[],s=a.levels??n,c=a.passthrough??!0,l=null,u=null,d=null,f=!1,p=(e,t,n)=>{o.push({message:n,timestamp:new Date,level:e,stream:t})},m=(e,n)=>(...i)=>{p(e,t[e],r(i)),f=!0;try{c&&n.apply(console,i)}finally{f=!1}},h=(t,n,r)=>{let a=new e(`utf8`);return((e,o,s)=>{if(!f){let r=typeof e==`string`?typeof o==`string`&&o!==`utf8`&&o!==`utf-8`?Buffer.from(e,o).toString(`utf8`):e:a.write(e);r!==``&&p(t,n,i(r))}if(c)return r.call(process[n],e,o,s);let l=typeof o==`function`?o:s;return typeof l==`function`&&l(),!0})};return{getLogs(){return{entries:[...o]}},start(){if(l===null){l={log:console.log,info:console.info,debug:console.debug,warn:console.warn,error:console.error};for(let e of s)console[e]=m(e,l[e]);s.includes(`log`)&&(u=process.stdout.write,process.stdout.write=h(`log`,`stdout`,u)),s.includes(`error`)&&(d=process.stderr.write,process.stderr.write=h(`error`,`stderr`,d))}},stop(){if(l!==null){for(let e of s)console[e]=l[e];l=null,u!==null&&(process.stdout.write=u,u=null),d!==null&&(process.stderr.write=d,d=null)}}}}function o(...e){return{entries:e.flatMap(e=>e.entries).sort((e,t)=>e.timestamp.getTime()-t.timestamp.getTime())}}function s(){return{entries:[]}}export{s as n,o as r,a as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e,s as t}from"./field-meta-D7G8a7IG.js";const n=new WeakMap;function r(e,t){return t&&n.set(e,t),e}function i(e){return n.get(e)}function a(e,t=new Set){if(t.has(e))return;t.add(e);let n=i(e);if(n)return n;if(typeof e.meta==`function`){let t=e.meta();if(t&&typeof t==`object`)return t}let r=e,s=r.def??r._def;if(s?.argMeta)return s.argMeta;if(s?.meta)return s.meta;let c=o(e);if(c===`optional`||c===`nullable`||c==="default"){let e=s?.innerType;if(e)return a(e,t)}if(c===`pipe`){let e=s?.in??s?.schema;if(e)return a(e,t)}}function o(e){let t=e;return t.def?.type??t._def?.type??t.type}function s(e){let t=c(e),n=(t.def??t._def)?.catchall;if(!n)return`strip`;let r=o(n);return r===`never`?`strict`:r===`unknown`||r===`any`?`passthrough`:`strip`}function c(e){let t=o(e),n=e,r=n.def??n._def;if(t===`optional`||t===`nullable`||t==="default"){let e=r?.innerType;if(e)return c(e)}if(t===`pipe`){let e=r?.in??r?.schema;if(e)return c(e)}return e}function l(e){switch(o(c(e))){case`string`:case`enum`:return`string`;case`number`:case`int`:return`number`;case`boolean`:return`boolean`;case`array`:return`array`;default:return`unknown`}}function u(e){let t=c(e),n=o(t),r=t,i=r.def??r._def;if(n===`enum`){let e=i?.entries;if(e&&typeof e==`object`)return Object.values(e);let t=i?.values;if(Array.isArray(t))return t;let n=r.options;if(Array.isArray(n))return n}if(n===`array`){let e=i?.element;if(e)return u(e)}if(n===`union`){let e=i?.options;if(Array.isArray(e)){let t=[];for(let n of e)if(o(n)===`literal`){let e=n.def??n._def,r=e?.value,i=e?.values,a=r??i?.[0];typeof a==`string`&&t.push(a)}if(t.length===e.length&&t.length>0)return t}}}function d(e){return!e.isOptional()}function f(e){let t=o(e),n=e,r=n.def??n._def;if(t==="default"){let e=r?.defaultValue;return typeof e==`function`?e():e}if(t===`optional`||t===`nullable`){let e=r?.innerType;if(e)return f(e)}if(t===`pipe`){let e=r?.in??r?.schema;if(e)return f(e)}}function p(e){if(e.description)return e.description;let t=o(e),n=e,r=n.def??n._def;if(t===`optional`||t===`nullable`||t==="default"){let e=r?.innerType;if(e)return p(e)}if(t===`pipe`){let e=r?.in??r?.schema;if(e)return p(e)}}function m(t,n){let r=a(n);return e(t,{argMeta:r,description:p(n),required:d(n),defaultValue:f(n),type:l(n),enumValues:u(n),schema:n})}function h(e){let t=e;return(t.def??t._def)?.shape??t.shape??{}}function g(e){let t=h(e);return Object.entries(t).map(([e,t])=>m(e,t))}function _(e){let t=e,n=t.def??t._def,r=n?.discriminator??``,i=n?.options??[],a=new Map,c=[];for(let e of i){let t=h(e),n=[],i=``,s=t[r];if(s){let e=o(s);if(e===`literal`){let e=s.def??s._def,t=e?.value,n=e?.values;i=String(t??n?.[0]??``)}else if(e===`enum`){let e=u(s);e&&e.length===1&&(i=e[0])}}for(let[e,r]of Object.entries(t)){let t=m(e,r);n.push(t),a.has(e)||a.set(e,t)}let l=p(e);c.push({discriminatorValue:i,fields:n,...l?{description:l}:{}})}let l=p(e);return{fields:Array.from(a.values()),schema:e,schemaType:`discriminatedUnion`,unknownKeysMode:s(e),discriminator:r,variants:c,...l?{description:l}:{}}}function v(e,t){let n=e,r=(n.def??n._def)?.options??[],i=new Map,a=[];for(let e of r){let t=x(e);a.push(t);for(let e of t.fields)i.has(e.name)||i.set(e.name,e)}let o=p(e);return{fields:Array.from(i.values()),schema:e,schemaType:t,unknownKeysMode:s(e),unionOptions:a,...o?{description:o}:{}}}function y(e){let t=e,n=t.def??t._def,r=n?.left,i=n?.right,a=new Map,o=e=>{if(!e)return;let t=x(e);for(let e of t.fields)a.has(e.name)||a.set(e.name,e)};o(r),o(i);let c=p(e);return{fields:Array.from(a.values()),schema:e,schemaType:`intersection`,unknownKeysMode:s(e),...c?{description:c}:{}}}const b=new WeakMap;function x(e){let t=b.get(e);if(t)return t;let n=e,r,i=o(n),a=n,c=a.def??a._def;switch(i){case`object`:{let t=p(n);r={fields:g(n),schema:e,schemaType:`object`,unknownKeysMode:s(n),...t?{description:t}:{}};break}case`union`:r=c?.discriminator?_(n):v(n,`union`);break;case`xor`:r=v(n,`xor`);break;case`intersection`:r=y(n);break;case`optional`:case`nullable`:case`default`:case`pipe`:{let t=c?.innerType??c?.in??c?.schema;if(t){let i=x(t),a=p(n);r={...i,schema:e,...a?{description:a}:{}};break}let i=p(n);r={fields:[],schema:e,schemaType:`object`,unknownKeysMode:s(n),...i?{description:i}:{}};break}default:{let t=p(n);r={fields:[],schema:e,schemaType:`object`,unknownKeysMode:s(n),...t?{description:t}:{}};break}}return b.set(e,r),r}function S(e){return e.issues.map(e=>({path:e.path.map(String),message:e.message,code:e.code,received:`received`in e?e.received:void 0,expected:`expected`in e?String(e.expected):void 0}))}function C(e,t){let n=t.safeParse(e);return n.success?{success:!0,data:n.data}:{success:!1,errors:S(n.error)}}t({vendor:`zod`,extractFields:x,resolveFieldMeta:(e,t)=>m(e,t),getUnknownKeysMode:e=>s(e),validate:C});export{r as t};
|
package/dist/runner-DPQ3GQA7.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./runner-DtJbfhOs.js";export{e as runCommand};
|