@kjanat/dreamcli 5.1.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{index-CuhI1Ynv.d.mts → command-Cq6YZjEH.d.mts} +1693 -1591
- package/dist/completion-DCWRvQjQ.mjs +59 -0
- package/dist/completion.d.mts +1 -1
- package/dist/completion.mjs +1 -1
- package/dist/{config-DSh3QJpX.mjs → config-CANc4lsA.mjs} +1 -1
- package/dist/config.d.mts +2 -2
- package/dist/config.mjs +1 -1
- package/dist/core-CPh0FcFg.mjs +25 -0
- package/dist/dynamic-xPNS3_vL.mjs +1 -0
- package/dist/{index-DIWRV_wp.d.mts → index-8EiEDJfX.d.mts} +33 -7
- package/dist/{index-DDhRLoTu.d.mts → index-BZ3jYjyh.d.mts} +12 -3
- package/dist/{index-Vjl2_m23.d.mts → index-Bkk86gFg.d.mts} +16 -11
- package/dist/{index-aTmg9yfl.d.mts → index-CLg6j-KJ.d.mts} +1 -1
- package/dist/{index-CLtWJqwn.d.mts → index-DBepo8jX.d.mts} +23 -4
- package/dist/index.d.mts +9 -9
- package/dist/index.mjs +1 -1
- package/dist/json-schema-DmFJR8c6.mjs +59 -0
- package/dist/json-schema.d.mts +1 -1
- package/dist/json-schema.mjs +1 -1
- package/dist/prompt.d.mts +1 -1
- package/dist/prompt.mjs +1 -1
- package/dist/runtime.d.mts +2 -2
- package/dist/runtime.mjs +1 -1
- package/dist/{session-BEKj0yLA.mjs → session-BBRg9p2u.mjs} +1 -1
- package/dist/{terminal-Dws_b5UK.mjs → terminal-mINn5p7B.mjs} +1 -1
- package/dist/{test-prompter-euLYzWWO.mjs → test-prompter-BI9sA9n7.mjs} +1 -1
- package/dist/testkit.d.mts +3 -3
- package/dist/testkit.mjs +1 -1
- package/dist/version.mjs +1 -1
- package/dreamcli.schema.json +175 -0
- package/package.json +9 -10
- package/dist/completion-B4oRc2Ae.mjs +0 -59
- package/dist/core-BZx351-p.mjs +0 -21
- package/dist/dynamic-BK2lQF2M.mjs +0 -1
- package/dist/json-schema-CYgq_hFu.mjs +0 -59
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import{t as __exportAll}from"./rolldown-runtime-DOYBPklu.mjs";import{$ as excludesOtherInputs,B as flagExpectsValue,F as resolvePlainHelpDescription,_t as CLIError,ct as getVisibleNegatedName,ft as flagValueSchema,gt as builtinEnabled,it as createFlagSchema,lt as acceptsArgv,ot as getFlagAliasNames,p as resolveRootSurface,pt as valueEnumValues,st as getFlagNegatedName,v as collectPropagatedFlags}from"./core-CPh0FcFg.mjs";import{DREAMCLI_REVISION,DREAMCLI_VERSION}from"./version.mjs";function versionTag(){let e=` (${DREAMCLI_REVISION})`;return`@kjanat/dreamcli v${DREAMCLI_VERSION}${e}`}function programTag(e){return e.version===void 0?e.name:`${e.name} v${e.version}`}function resolveRootCompletionSurface(e,t=`subcommands`){let n=resolveRootSurface(e),r=createRootFlags(builtinEnabled(e.builtins,`help`),e.version!==void 0),i=n.visibleDefaultCommand?.flags??{},a=t===`surface`?n.hasVisibleDefault:n.hasVisibleDefault&&!n.hasVisibleSubcommands,o=n.visibleDefaultCommand,s=o!==void 0&&n.visibleCommands.some(e=>e.name===o.name);return{visibleCommands:n.defaultRouted&&o!==void 0&&!s?[o,...n.visibleCommands]:n.defaultRouted?n.visibleCommands:n.visibleSubcommands,visibleDefaultCommand:n.visibleDefaultCommand,rootFlags:r,defaultFlags:i,includeDefaultFlags:a}}function createRootFlags(e,t){return{...e?{help:createSyntheticRootFlag(`Show help text`)}:{},...t?{version:createSyntheticRootFlag(`Show version`)}:{}}}function createSyntheticRootFlag(e){return createFlagSchema(`boolean`,{description:e})}function walkCommandTree(e,t=[]){let n=[];for(let r of e){if(r.hidden)continue;let e=[...t,r],i=collectPropagatedFlags(e),a={...i,...r.flags},o=r.commands.filter(e=>!e.hidden);n.push({path:e.map(e=>e.name),schema:r,propagatedFlags:i,mergedFlags:a,children:o}),o.length>0&&n.push(...walkCommandTree(o,e))}return n}function sanitizeShellIdentifier(e){let t=e.replace(/[^a-zA-Z0-9_]/g,`_`);if(t===e)return t;let n=2166136261;for(let t=0;t<e.length;t+=1)n^=e.charCodeAt(t),n=Math.imul(n,16777619);return`${t}_${(n>>>0).toString(16).padStart(8,`0`)}`}function quoteShellArg(e){return/^[a-zA-Z0-9_\-.]+$/.test(e)?e:`'${e.replace(/'/g,`'\\''`)}'`}function hasDynamicCompletion(e){let t=e=>e.constraints?.some(excludesOtherInputs)||Object.values(e.flags).some(e=>acceptsArgv(e)&&e.completion!==void 0)||e.args.some(e=>acceptsArgv(e.schema)&&e.schema.completion!==void 0)||e.commands.some(t);return e.commands.some(t)||e.defaultCommand!==void 0&&t(e.defaultCommand)}function hasCompletionConflicts(e){let t=e=>(e.constraints?.some(excludesOtherInputs)??!1)||e.commands.some(t);return e.commands.some(t)||e.defaultCommand!==void 0&&t(e.defaultCommand)}function generateBashCompletion(e,t){let n=`_${sanitizeShellIdentifier(t?.functionPrefix??e.name)}_completions`,r=resolveRootCompletionSurface(e,t?.rootMode),i=r.visibleCommands,a=walkCommandTree(i),o=a.reduce((e,t)=>Math.max(e,t.path.length),0),s=[];if(s.push(`#!/usr/bin/env bash`),s.push(`# Bash completion for ${programTag(e)}`),s.push(`# Generated by ${versionTag()}`),s.push(`#`),s.push(`# Usage: source <(${e.name} completions bash)`),s.push(`#`),s.push(`# Install permanently:`),s.push(`# ${e.name} completions bash > /etc/bash_completion.d/${e.name} # Linux`),s.push(`# ${e.name} completions bash > $(brew --prefix)/etc/bash_completion.d/${e.name} # macOS`),s.push(`#`),s.push(`# Requires: bash-completion (provides _init_completion)`),s.push(``),hasDynamicCompletion(e)&&(s.push(`${n}_unquote() {`),s.push(` local text="$1" char escaped=0 i`),s.push(` unquoted="" quote=""`),s.push(" for ((i = 0; i < ${#text}; i++)); do"),s.push(' char="${text:i:1}"'),s.push(` if ((escaped)); then`),s.push(` [[ "$quote" == '"' && "$char" != [\\\\\\"\\$\\\`] ]] && unquoted+='\\'`),s.push(` unquoted+="$char"; escaped=0`),s.push(` elif [[ "$char" == '\\' && "$quote" != "'" ]]; then`),s.push(` escaped=1`),s.push(` elif [[ -n "$quote" ]]; then`),s.push(` if [[ "$char" == "$quote" ]]; then quote=""; else unquoted+="$char"; fi`),s.push(` elif [[ "$char" == "'" || "$char" == '"' ]]; then`),s.push(` quote="$char"`),s.push(` else`),s.push(` unquoted+="$char"`),s.push(` fi`),s.push(` done`),s.push(` ((escaped)) && unquoted+='\\'`),s.push(` return 0`),s.push(`}`),s.push(``)),s.push(`${n}() {`),s.push(` local cur prev words cword`),s.push(hasDynamicCompletion(e)?` _init_completion -n =: || return`:` _init_completion || return`),s.push(` local readline_prefix=""`),s.push(` if [[ $# -ge 2 && "$cur" == *"$2" ]]; then`),s.push(' readline_prefix="${cur%"$2"}"'),s.push(` fi`),hasDynamicCompletion(e)&&(s.push(` local dynamic candidate unquoted quote readline_quote word char i quoted`),s.push(`\t${n}_unquote "$readline_prefix"`),s.push(` readline_prefix="$unquoted" readline_quote="$quote"`),s.push(` local -a dynamic_words=()`),s.push(' for word in "${words[@]:1:cword-1}" "$cur"; do'),s.push(`\t\t${n}_unquote "$word"`),s.push(` dynamic_words+=("$unquoted")`),s.push(` done`),s.push(`\tif dynamic=$(command ${quoteShellArg(e.name)} __complete -- "\${dynamic_words[@]}" 2>/dev/null); then`),s.push(` compopt -o noquote 2>/dev/null`),s.push(` COMPREPLY=()`),s.push(` while IFS= read -r candidate; do`),s.push(` [[ -n "$candidate" ]] || continue`),s.push(' candidate="${candidate#"$readline_prefix"}"'),s.push(` if [[ -z "$readline_quote" ]]; then`),s.push(` printf -v candidate %q "$candidate"`),s.push(` else`),s.push(` quoted="$readline_quote"`),s.push(" for ((i = 0; i < ${#candidate}; i++)); do"),s.push(' char="${candidate:i:1}"'),s.push(` if [[ "$readline_quote" == '"' && "$char" == [\\\\\\"\\$\\\`] ]]; then quoted+='\\'; fi`),s.push(` if [[ "$readline_quote" == "'" && "$char" == "'" ]]; then quoted+="'\\\\''"; else quoted+="$char"; fi`),s.push(` done`),s.push(` candidate="$quoted"`),s.push(` fi`),s.push(` COMPREPLY+=("$candidate")`),s.push(` done <<< "$dynamic"`),s.push(` return`),s.push(` fi`)),s.push(``),i.length>0){let e=a.filter(e=>e.children.length>0),t=collectValueFlagPattern(a,r);s.push(` # Build subcommand path by scanning COMP_WORDS`),s.push(` local subcmd_path=""`),s.push(` local i`),s.push(` for ((i = 1; i < cword; i++)); do`),s.push(' case "${words[i]}" in'),s.push(` --) break ;;`),t.length>0&&s.push(`\t\t\t${t}) ((i++)); continue ;;`),s.push(` -*) continue ;;`),s.push(` esac`),emitBashPathDetection(s,i,e,o),s.push(` done`),s.push(``),s.push(` # Complete flags and subcommands for the active path`),s.push(` case "$subcmd_path" in`);for(let e of a){let t=e.path.join(` `),n=e.mergedFlags,r=collectEnumCasesFromFlags(n),i=collectFlagWords(n),a=dedupeWords(e.children.flatMap(e=>[e.name,...e.aliases])).map(escapeForSingleQuote).join(` `),o=i.split(` `).filter(Boolean).map(escapeForSingleQuote).join(` `),c=a.length>0?`${a} ${o}`:o;if(s.push(`\t\t${quoteShellCasePattern(t)})`),r.length>0){s.push(` local enum_flag=""`),s.push(` local enum_cur="$cur"`),s.push(` local enum_prefix=""`),s.push(` if [[ "$cur" == --*=* ]]; then`),s.push(' enum_flag="${cur%%=*}"'),s.push(' enum_cur="${cur#*=}"'),s.push(' enum_prefix="${cur%%=*}="'),s.push(` fi`),s.push(' case "${enum_flag:-$prev}" in');for(let e of r)s.push(`\t\t\t\t${e.flags})`),s.push(formatBashEnumCompletion(e.values,` `,`enum_cur`,`enum_prefix`)),s.push(` return`),s.push(` ;;`);s.push(` *)`),s.push(` ;;`),s.push(` esac`)}s.push(`\t\t\tCOMPREPLY=($(compgen -W '${c.trim()}' -- "$cur"))`),s.push(` return`),s.push(` ;;`)}s.push(` *)`),s.push(` ;;`),s.push(` esac`),s.push(``);let n=collectFlagWords(r.rootFlags).split(` `).filter(Boolean),c=r.includeDefaultFlags?collectFlagWords(r.defaultFlags).split(` `).filter(Boolean):[],l=dedupeWords([...i.flatMap(e=>[e.name,...e.aliases]),...n,...c]).map(escapeForSingleQuote).join(` `);s.push(` # Root-level completions: visible root surface`),s.push(`\tCOMPREPLY=($(compgen -W '${l}' -- "$cur"))`)}else{let e=collectFlagWords({...r.rootFlags,...r.includeDefaultFlags?r.defaultFlags:{}});s.push(`\tCOMPREPLY=($(compgen -W '${e}' -- "$cur"))`)}return s.push(`}`),s.push(``),s.push(`complete -F ${n} ${quoteShellArg(e.name)}`),s.push(``),s.join(`
|
|
2
|
+
`)}function emitBashPathDetection(e,t,n,r){e.push(` case "$subcmd_path" in`),e.push(` '')`),e.push(' case "${words[i]}" in');for(let n of t){let t=[n.name,...n.aliases].map(escapeBashCasePatternValue);e.push(`\t\t\t\t\t${t.join(`|`)})`),e.push(`\t\t\t\t\t\tsubcmd_path="${escapeBashDoubleQuotedValue(n.name)}"`),e.push(` ;;`)}if(e.push(` esac`),e.push(` ;;`),r>1)for(let t of n){let n=t.path.join(` `);e.push(`\t\t\t${quoteShellCasePattern(n)})`),e.push(' case "${words[i]}" in');for(let n of t.children){let t=[n.name,...n.aliases].map(escapeBashCasePatternValue);e.push(`\t\t\t\t\t${t.join(`|`)})`),e.push(`\t\t\t\t\t\tsubcmd_path="$subcmd_path ${escapeBashDoubleQuotedValue(n.name)}"`),e.push(` ;;`)}e.push(` esac`),e.push(` ;;`)}e.push(` esac`)}function quoteShellCasePattern(e){return e.includes(` `)?`"${escapeBashDoubleQuotedValue(e)}"`:escapeBashCasePatternValue(e)}function escapeBashCasePatternValue(e){return/^[a-zA-Z0-9_\-.]+$/.test(e)?e:e.replace(/\\/g,`\\\\`).replace(/'/g,`\\'`).replace(/"/g,`\\"`).replace(/\|/g,`\\|`).replace(/\*/g,`\\*`).replace(/\?/g,`\\?`).replace(/\[/g,`\\[`).replace(/\]/g,`\\]`).replace(/\(/g,`\\(`).replace(/\)/g,`\\)`).replace(/\{/g,`\\{`).replace(/\}/g,`\\}`).replace(/\+/g,`\\+`).replace(/!/g,`\\!`).replace(/@/g,`\\@`).replace(/#/g,`\\#`).replace(/~/g,`\\~`).replace(/\s/g,e=>e===` `?`\\ `:`\\${e}`)}function escapeBashDoubleQuotedValue(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`).replace(/`/g,"\\`")}function escapeForSingleQuote(e){return/^[a-zA-Z0-9_\-.]+$/.test(e)?e:e.replace(/'/g,`'\\''`)}function formatBashEnumCompletion(e,t,n=`cur`,r){let i=[];if(e.some(e=>!/^[a-zA-Z0-9_\-.]+$/.test(e))){let r=e.map(escapeBashDollarQuote).join(`\\n`);i.push(`${t}local IFS=$'\\n'`),i.push(`${t}COMPREPLY=($(compgen -W $'${r}' -- "$${n}"))`)}else i.push(`${t}COMPREPLY=($(compgen -W '${e.join(` `)}' -- "$${n}"))`);return r!==void 0&&(i.push(`${t}if [[ -n "$${r}" && "\${#COMPREPLY[@]}" -gt 0 ]]; then`),i.push(`${t}\tlocal i`),i.push(`${t}\tfor ((i = 0; i < \${#COMPREPLY[@]}; i++)); do`),i.push(`${t}\t\tCOMPREPLY[i]="$${r}\${COMPREPLY[i]}"`),i.push(`${t}\tdone`),i.push(`${t}fi`)),i.push(`${t}local reply`),i.push(`${t}for reply in "\${!COMPREPLY[@]}"; do`),i.push(`${t}\tCOMPREPLY[reply]="\${COMPREPLY[reply]#"$readline_prefix"}"`),i.push(`${t}done`),i.join(`
|
|
3
|
+
`)}function escapeBashDollarQuote(e){return e.replace(/\\/g,`\\\\`).replace(/'/g,`\\'`).replace(/\n/g,`\\n`)}function collectFlagWords(e){let t=[];for(let[n,r]of Object.entries(e)){if(!acceptsArgv(r))continue;t.push(`--${n}`);for(let e of getFlagAliasNames(r))t.push(e.length===1?`-${e}`:`--${e}`);let e=getVisibleNegatedName(n,r);e!==void 0&&t.push(`--${e}`)}return t.join(` `)}function collectValueFlagPattern(e,t){let n=/* @__PURE__ */ new Set,r=e=>{for(let[t,r]of Object.entries(e))if(acceptsArgv(r)&&flagExpectsValue(r)){n.add(`--${t}`);for(let e of getFlagAliasNames(r,{includeHidden:!0}))n.add(e.length===1?`-${e}`:`--${e}`)}};for(let t of e)r(t.mergedFlags);return r(t.rootFlags),t.includeDefaultFlags&&r(t.defaultFlags),[...n].map(escapeBashCasePatternValue).join(`|`)}function dedupeWords(e){return[...new Set(e)]}function collectEnumCasesFromFlags(e){let t=[];for(let[n,r]of Object.entries(e)){if(!acceptsArgv(r))continue;let e=r.kind===`keyValue`?void 0:valueEnumValues(flagValueSchema(r));if(e===void 0)continue;let i=[`--${n}`,...getFlagAliasNames(r,{includeHidden:!0}).map(e=>e.length===1?`-${e}`:`--${e}`)].map(escapeBashCasePatternValue);t.push({flags:i.join(`|`),values:e})}return t}function generateFishCompletion(e,t){let n=`__${sanitizeShellIdentifier(t?.functionPrefix??e.name)}_completions`,r=`${n}_path`,i=`${n}_path_is`,a=`${n}_allows_flag`,o=resolveRootCompletionSurface(e,t?.rootMode),s=o.visibleCommands,c=walkCommandTree(s),l=quoteShellArg(e.name),u=[];u.push(`# Fish completion for ${programTag(e)}`),u.push(`# Generated by ${versionTag()}`),u.push(`#`),u.push(`# Usage: source (${e.name} completions fish | psub)`),u.push(`#`),u.push(`# Install permanently:`),u.push(`# ${e.name} completions fish > ~/.config/fish/completions/${e.name}.fish`),u.push(``),u.push(`complete -c ${l} -f`),u.push(``),hasDynamicCompletion(e)&&(u.push(`function ${n}_dynamic`),u.push(` set -l words (commandline -xpc)`),u.push(` set -l raw (commandline -ct)`),u.push(` set -l prefix (commandline --input "$raw" --tokens-expanded)`),u.push(`\tcommand ${l} __complete --value-only -- $words[2..-1] "$prefix" 2>/dev/null`),u.push(`end`),u.push(`complete -c ${l} -f -a '(${n}_dynamic)'`),u.push(``)),hasCompletionConflicts(e)&&(u.push(`function ${a}`),u.push(` set -l words (commandline -xpc)`),u.push(`\tnot contains -- "$argv[1]" (command ${l} __complete --blocked-flags -- $words[2..-1] 2>/dev/null)`),u.push(`end`),u.push(``)),emitFishPathHelpers(u,r,i,s,c,o),appendFishCommandCompletions(u,l,i,``,s),appendFishFlagCompletions(u,l,i,``,o.rootFlags,`${n}_dynamic`),o.includeDefaultFlags&&appendFishFlagCompletions(u,l,i,``,o.defaultFlags,`${n}_dynamic`,fishFlagGuard(a,o.visibleDefaultCommand));for(let e of c){let t=e.path.join(` `);appendFishCommandCompletions(u,l,i,t,e.children),appendFishFlagCompletions(u,l,i,t,e.mergedFlags,`${n}_dynamic`,fishFlagGuard(a,e.schema))}return u.join(`
|
|
4
|
+
`)}function fishFlagGuard(e,t){return{helper:e,names:new Set(t?.constraints?.filter(excludesOtherInputs).flatMap(({inputs:e})=>e.filter(({kind:e})=>e===`flag`).map(({name:e})=>e)))}}function emitFishPathHelpers(e,t,n,r,i,a){let o=collectFishValueFlagPatterns(i,a);e.push(`function ${t}`),e.push(` set -l words (commandline -xpc)`),e.push(` if test (count $words) -gt 0`),e.push(` set -e words[1]`),e.push(` end`),e.push(` set -l subcmd_path ''`),e.push(` set -l expect_value 0`),e.push(` for word in $words`),e.push(` if test $expect_value -eq 1`),e.push(` set expect_value 0`),e.push(` continue`),e.push(` end`),e.push(` switch $word`),e.push(` case '--'`),e.push(` break`),o.exact.length>0&&(e.push(`\t\t\tcase ${o.exact.map(quoteShellArg).join(` `)}`),e.push(` set expect_value 1`),e.push(` continue`)),o.prefix.length>0&&(e.push(`\t\t\tcase ${o.prefix.map(quoteShellArg).join(` `)}`),e.push(` continue`)),e.push(` case '-*'`),e.push(` continue`),e.push(` end`),e.push(` switch "$subcmd_path|$word"`);for(let t of r)for(let n of[t.name,...t.aliases])e.push(`\t\t\tcase ${quoteShellArg(`|${n}`)}`),e.push(`\t\t\t\tset subcmd_path ${quoteShellArg(t.name)}`);for(let t of i)for(let n of t.children)for(let r of[n.name,...n.aliases])e.push(`\t\t\tcase ${quoteShellArg(`${t.path.join(` `)}|${r}`)}`),e.push(`\t\t\t\tset subcmd_path ${quoteShellArg(`${t.path.join(` `)} ${n.name}`)}`);e.push(` case '*'`),e.push(` break`),e.push(` end`),e.push(` end`),e.push(` printf '%s\\n' "$subcmd_path"`),e.push(`end`),e.push(``),e.push(`function ${n}`),e.push(` set -l expected "$argv[1]"`),e.push(`\ttest (${t}) = "$expected"`),e.push(`end`),e.push(``)}function appendFishCommandCompletions(e,t,n,r,i){let a=buildFishCondition(n,r);for(let n of i){let r=quoteShellArg(n.description??n.name);for(let i of[n.name,...n.aliases])e.push(`complete -c ${t} -n "${a}" -a ${quoteShellArg(i)} -d ${r}`)}i.length>0&&e.push(``)}function appendFishFlagCompletions(e,t,n,r,i,a,o){let s=buildFishCondition(n,r);for(let[n,r]of Object.entries(i)){if(!acceptsArgv(r))continue;let i=o?.names.has(n)===!0,c=[`complete -c ${t}`,i?`-n ${quoteShellArg(`${s}; and ${o.helper} ${quoteShellArg(n)}`)}`:`-n "${s}"`];for(let e of getFlagAliasNames(r,{kind:`short`}))c.push(`-s ${quoteShellArg(e)}`);c.push(`-l ${quoteShellArg(n)}`);for(let e of getFlagAliasNames(r,{kind:`long`}))c.push(`-l ${quoteShellArg(e)}`);let l=getVisibleNegatedName(n,r);if(l!==void 0&&!i&&c.push(`-l ${quoteShellArg(l)}`),c.push(`-d ${quoteShellArg(r.description===void 0?n:resolvePlainHelpDescription(r.description))}`),l!==void 0&&i){let i=quoteShellArg(r.description===void 0?n:resolvePlainHelpDescription(r.description));e.push(`complete -c ${t} -n "${s}" -l ${quoteShellArg(l)} -d ${i}`)}flagExpectsValue(r)&&c.push(`-r`,`-f`),r.completion!==void 0&&c.push(`-a '(${a})'`);let u=r.kind===`keyValue`?void 0:valueEnumValues(flagValueSchema(r));if(u!==void 0&&r.completion===void 0)for(let t of u)e.push([...c,`-a ${quoteShellArg(t)}`].join(` `));else e.push(c.join(` `))}Object.keys(i).length>0&&e.push(``)}function collectFishValueFlagPatterns(e,t){let n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Set,i=[t.rootFlags,...t.includeDefaultFlags?[t.defaultFlags]:[],...e.map(e=>e.mergedFlags)];for(let e of i)for(let[t,i]of Object.entries(e))if(acceptsArgv(i)&&flagExpectsValue(i)){n.add(`--${t}`),r.add(`--${t}=*`);for(let e of getFlagAliasNames(i,{kind:`short`,includeHidden:!0}))n.add(`-${e}`),r.add(`-${e}*`);for(let e of getFlagAliasNames(i,{kind:`long`,includeHidden:!0}))n.add(`--${e}`),r.add(`--${e}=*`)}return{exact:[...n],prefix:[...r]}}function buildFishCondition(e,t){return`${e} ${quoteShellArg(t)}`}function generatePowerShellCompletion(e,t){let n=`__${sanitizeShellIdentifier(t?.functionPrefix??e.name)}_completions`,r=`${n}_paths`,i=resolveRootCompletionSurface(e,t?.rootMode),a=i.visibleCommands,o=walkCommandTree(a),s=hasCompletionConflicts(e),c=[];c.push(`# PowerShell completion for ${programTag(e)}`),c.push(`# Generated by ${versionTag()}`),c.push(`#`),c.push(`# Install for the current session:`),c.push(`# ${e.name} completions powershell | Out-String | Invoke-Expression`),c.push(`#`),c.push(`# Install permanently:`),c.push(`# ${e.name} completions powershell > $PROFILE.CurrentUserCurrentHost`),c.push(``),c.push(`using namespace System.Management.Automation`),c.push(`using namespace System.Management.Automation.Language`),c.push(``),emitPowerShellPathTable(c,r,i,o,s),c.push(``),emitPowerShellHelpers(c,n,r,s),c.push(``),c.push(`Register-ArgumentCompleter -Native -CommandName ${quotePowerShellString(e.name)} -ScriptBlock {`),c.push(` param($wordToComplete, $commandAst, $cursorPosition)`),hasDynamicCompletion(e)&&(c.push(` $dynamicArgs = [System.Collections.Generic.List[string]]::new()`),c.push(` $dynamicArgs.Add('__complete')`),s&&c.push(` $dynamicArgs.Add('--values')`),c.push(` $dynamicArgs.Add('--')`),c.push(` $currentText = $wordToComplete`),c.push(` foreach ($element in $commandAst.CommandElements | Select-Object -Skip 1) {`),c.push(` if ($element.Extent.StartOffset -gt $cursorPosition) { break }`),c.push(` if ($element.Extent.EndOffset -ge $cursorPosition) {`),c.push(` $currentText = $element.Extent.Text.Substring(0, $cursorPosition - $element.Extent.StartOffset)`),c.push(` break`),c.push(` }`),c.push(`\t\t$dynamicArgs.Add((${n}_UnquoteToken $element.Extent.Text))`),c.push(` }`),c.push(`\t$dynamicArgs.Add((${n}_UnquoteToken $currentText))`),c.push(`\t$dynamic = & ${quotePowerShellString(e.name)} @dynamicArgs 2>$null`),c.push(` if ($LASTEXITCODE -eq 0) {`),c.push(` foreach ($candidate in $dynamic) {`),c.push(`\t\t\t$text = ${n}_FormatCompletionValue -Value $candidate`),c.push(` [CompletionResult]::new($text, $candidate, [CompletionResultType]::ParameterValue, $candidate)`),c.push(` }`),c.push(` return`),c.push(` }`)),c.push(`\t$state = ${n}_GetState -CommandAst $commandAst -CursorPosition $cursorPosition`),c.push(` if ($null -eq $state.PathData) {`),c.push(` return`),c.push(` }`),c.push(``),c.push(` $results = [System.Collections.Generic.List[CompletionResult]]::new()`),c.push(` if ($state.AfterSeparator) {`),c.push(` return $results`),c.push(` }`),c.push(``),c.push(` $wordPrefix = if ([string]::IsNullOrEmpty($wordToComplete)) { '' } else { $wordToComplete }`),c.push(``),c.push(` if ($state.ExpectingValue) {`),c.push(`\t\t${n}_AddEnumResults -Results $results -Flag $state.ValueFlag -WordToComplete $wordPrefix`),c.push(` return $results`),c.push(` }`),c.push(``),c.push(`\t$inlineValue = ${n}_ResolveInlineValueCompletion -PathData $state.PathData -WordToComplete $wordPrefix`),c.push(` if ($null -ne $inlineValue) {`),c.push(`\t\t${n}_AddInlineEnumResults -Results $results -InlineValue $inlineValue -WordToComplete $wordPrefix`),c.push(` return $results`),c.push(` }`),c.push(``),s&&(c.push(` $dynamicArgs.RemoveAt($dynamicArgs.Count - 1)`),c.push(` $dynamicArgs[1] = '--blocked-flags'`),c.push(`\t$blockedFlags = @(& ${quotePowerShellString(e.name)} @dynamicArgs 2>$null)`));let l=s?` -BlockedFlags $blockedFlags`:``;return c.push(` if ($wordPrefix.StartsWith('-')) {`),c.push(`\t\t${n}_AddFlagResults -Results $results -PathData $state.PathData -WordToComplete $wordPrefix${l}`),c.push(` return $results`),c.push(` }`),c.push(``),c.push(`\t${n}_AddCommandResults -Results $results -PathData $state.PathData -WordToComplete $wordPrefix`),c.push(`\t${n}_AddFlagResults -Results $results -PathData $state.PathData -WordToComplete $wordPrefix${l}`),c.push(` return $results`),c.push(`}`),c.join(`
|
|
5
|
+
`)}function emitPowerShellPathTable(e,t,n,r,i){e.push(`$script:${t} = @{`),appendPowerShellPathEntry(e,``,n.visibleCommands,{...n.rootFlags,...n.includeDefaultFlags?n.defaultFlags:{}},i);for(let t of r)appendPowerShellPathEntry(e,t.path.join(` `),t.children,t.mergedFlags,i);e.push(`}`)}function appendPowerShellPathEntry(e,t,n,r,i){e.push(`\t${quotePowerShellString(t)} = @{`),e.push(` Commands = @(`);for(let t of n)e.push(` @{`),e.push(`\t\t\t\tCanonicalName = ${quotePowerShellString(t.name)}`),e.push(`\t\t\t\tNames = ${formatPowerShellArray([t.name,...t.aliases])}`),e.push(`\t\t\t\tDescription = ${quotePowerShellString(t.description??t.name)}`),e.push(` }`);e.push(` )`),e.push(` Flags = @(`);for(let[t,n]of Object.entries(r)){if(!acceptsArgv(n))continue;let r=getVisibleNegatedName(t,n),a=getFlagNegatedName(t,n),o=dedupeValues([`--${t}`,...getFlagAliasNames(n,{kind:`short`}).map(e=>`-${e}`),...getFlagAliasNames(n,{kind:`long`}).map(e=>`--${e}`),...r===void 0?[]:[`--${r}`]]),s=dedupeValues([`--${t}`,...getFlagAliasNames(n,{kind:`short`,includeHidden:!0}).map(e=>`-${e}`),...getFlagAliasNames(n,{kind:`long`,includeHidden:!0}).map(e=>`--${e}`),...a===void 0?[]:[`--${a}`]]);if(e.push(` @{`),e.push(`\t\t\t\tCanonicalName = ${quotePowerShellString(t)}`),e.push(`\t\t\t\tForms = ${formatPowerShellArray(o)}`),i){let t=r===void 0?`$null`:quotePowerShellString(`--${r}`);e.push(`\t\t\t\tNegatedForm = ${t}`)}e.push(`\t\t\t\tParseForms = ${formatPowerShellArray(s)}`),e.push(`\t\t\t\tRequiresValue = ${flagExpectsValue(n)?`$true`:`$false`}`),e.push(`\t\t\t\tDescription = ${quotePowerShellString(n.description===void 0?t:resolvePlainHelpDescription(n.description))}`),e.push(`\t\t\t\tEnumValues = ${formatPowerShellArray((n.kind===`keyValue`?void 0:valueEnumValues(flagValueSchema(n)))??[])}`),e.push(` }`)}e.push(` )`),e.push(` }`)}function emitPowerShellHelpers(e,t,n,r){e.push(`function ${t}_UnquoteToken {`),e.push(` param([string]$TokenText)`),e.push(...String.raw`
|
|
6
|
+
$result = [System.Text.StringBuilder]::new()
|
|
7
|
+
$quote = [char]0
|
|
8
|
+
for ($i = 0; $i -lt $TokenText.Length; $i++) {
|
|
9
|
+
$char = $TokenText[$i]
|
|
10
|
+
if ($quote -eq "'") {
|
|
11
|
+
if ($char -eq "'") {
|
|
12
|
+
if ($i + 1 -lt $TokenText.Length -and $TokenText[$i + 1] -eq "'") {
|
|
13
|
+
[void]$result.Append("'")
|
|
14
|
+
$i++
|
|
15
|
+
} else { $quote = [char]0 }
|
|
16
|
+
} else { [void]$result.Append($char) }
|
|
17
|
+
} elseif ($char -eq [char]96) {
|
|
18
|
+
if ($i + 1 -lt $TokenText.Length) {
|
|
19
|
+
$i++
|
|
20
|
+
$escaped = $TokenText[$i]
|
|
21
|
+
$decoded = switch -CaseSensitive ($escaped) {
|
|
22
|
+
'0' { [char]0 }
|
|
23
|
+
'a' { [char]7 }
|
|
24
|
+
'b' { [char]8 }
|
|
25
|
+
'e' { [char]27 }
|
|
26
|
+
'f' { [char]12 }
|
|
27
|
+
'n' { [char]10 }
|
|
28
|
+
'r' { [char]13 }
|
|
29
|
+
't' { [char]9 }
|
|
30
|
+
'v' { [char]11 }
|
|
31
|
+
'u' {
|
|
32
|
+
$match = [regex]::Match($TokenText.Substring($i + 1), '^\{([0-9a-fA-F]{1,6})\}')
|
|
33
|
+
if ($match.Success) {
|
|
34
|
+
$codepoint = [Convert]::ToInt32($match.Groups[1].Value, 16)
|
|
35
|
+
if ($codepoint -le 0x10ffff -and ($codepoint -lt 0xd800 -or $codepoint -gt 0xdfff)) {
|
|
36
|
+
$i += $match.Length
|
|
37
|
+
[char]::ConvertFromUtf32($codepoint)
|
|
38
|
+
} else { $escaped }
|
|
39
|
+
} else { $escaped }
|
|
40
|
+
}
|
|
41
|
+
default { $escaped }
|
|
42
|
+
}
|
|
43
|
+
[void]$result.Append($decoded)
|
|
44
|
+
} else { [void]$result.Append($char) }
|
|
45
|
+
} elseif ($quote -eq '"') {
|
|
46
|
+
if ($char -eq '"') {
|
|
47
|
+
if ($i + 1 -lt $TokenText.Length -and $TokenText[$i + 1] -eq '"') {
|
|
48
|
+
[void]$result.Append('"')
|
|
49
|
+
$i++
|
|
50
|
+
} else { $quote = [char]0 }
|
|
51
|
+
} else { [void]$result.Append($char) }
|
|
52
|
+
} elseif ($char -eq "'" -or $char -eq '"') {
|
|
53
|
+
$quote = $char
|
|
54
|
+
} else { [void]$result.Append($char) }
|
|
55
|
+
}
|
|
56
|
+
return $result.ToString()
|
|
57
|
+
`.trimEnd().split(`
|
|
58
|
+
`).slice(1)),e.push(`}`),e.push(``),e.push(`function ${t}_FindCommand {`),e.push(` param($PathData, [string]$Token)`),e.push(` foreach ($command in $PathData.Commands) {`),e.push(` foreach ($name in $command.Names) {`),e.push(` if ($name -eq $Token) {`),e.push(` return $command`),e.push(` }`),e.push(` }`),e.push(` }`),e.push(` return $null`),e.push(`}`),e.push(``),e.push(`function ${t}_ResolveFlagToken {`),e.push(` param($PathData, [string]$Token)`),e.push(` foreach ($flag in $PathData.Flags) {`),e.push(` foreach ($form in $flag.ParseForms) {`),e.push(` if ($Token -eq $form) {`),e.push(` return @{ Flag = $flag; InlinePrefix = $null }`),e.push(` }`),e.push(``),e.push(` if (-not $flag.RequiresValue) {`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` if ($form.StartsWith('--') -and $Token.StartsWith("$form=")) {`),e.push(` return @{ Flag = $flag; InlinePrefix = "$form=" }`),e.push(` }`),e.push(``),e.push(` if ($form.StartsWith('-') -and -not $form.StartsWith('--') -and $Token.StartsWith($form) -and $Token.Length -gt $form.Length) {`),e.push(` return @{ Flag = $flag; InlinePrefix = $form }`),e.push(` }`),e.push(` }`),e.push(` }`),e.push(` return $null`),e.push(`}`),e.push(``),e.push(`function ${t}_GetState {`),e.push(` param([CommandAst]$CommandAst, [int]$CursorPosition)`),e.push(`\t$pathData = $script:${n}[${quotePowerShellString(``)}]`),e.push(` $path = ""`),e.push(` $afterSeparator = $false`),e.push(` $expectingValue = $false`),e.push(` $valueFlag = $null`),e.push(` $tokens = [System.Collections.Generic.List[string]]::new()`),e.push(``),e.push(` foreach ($element in $CommandAst.CommandElements | Select-Object -Skip 1) {`),e.push(` if ($element.Extent.EndOffset -ge $CursorPosition) {`),e.push(` break`),e.push(` }`),e.push(`\t\t$tokenText = ${t}_UnquoteToken $element.Extent.Text`),e.push(` [void]$tokens.Add($tokenText)`),e.push(` }`),e.push(``),e.push(` foreach ($token in $tokens) {`),e.push(` if ($expectingValue) {`),e.push(` $expectingValue = $false`),e.push(` $valueFlag = $null`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` if ($token -eq '--') {`),e.push(` $afterSeparator = $true`),e.push(` break`),e.push(` }`),e.push(``),e.push(`\t\t$flagMatch = ${t}_ResolveFlagToken -PathData $pathData -Token $token`),e.push(` if ($null -ne $flagMatch) {`),e.push(` if ($flagMatch.InlinePrefix -eq $null -and $flagMatch.Flag.RequiresValue) {`),e.push(` $expectingValue = $true`),e.push(` $valueFlag = $flagMatch.Flag`),e.push(` }`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` if ($token.StartsWith('-')) {`),e.push(` continue`),e.push(` }`),e.push(``),e.push(`\t\t$command = ${t}_FindCommand -PathData $pathData -Token $token`),e.push(` if ($null -eq $command) {`),e.push(` break`),e.push(` }`),e.push(``),e.push(` $path = if ([string]::IsNullOrEmpty($path)) {`),e.push(` $command.CanonicalName`),e.push(` } else {`),e.push(` "$path $($command.CanonicalName)"`),e.push(` }`),e.push(`\t\t$nextPathData = $script:${n}[$path]`),e.push(` if ($null -eq $nextPathData) {`),e.push(` break`),e.push(` }`),e.push(` $pathData = $nextPathData`),e.push(` }`),e.push(``),e.push(` return @{`),e.push(` Path = $path`),e.push(` PathData = $pathData`),e.push(` AfterSeparator = $afterSeparator`),e.push(` ExpectingValue = $expectingValue`),e.push(` ValueFlag = $valueFlag`),e.push(` }`),e.push(`}`),e.push(``),e.push(`function ${t}_ResolveInlineValueCompletion {`),e.push(` param($PathData, [string]$WordToComplete)`),e.push(`\t$flagMatch = ${t}_ResolveFlagToken -PathData $PathData -Token $WordToComplete`),e.push(` if ($null -eq $flagMatch -or $flagMatch.InlinePrefix -eq $null) {`),e.push(` return $null`),e.push(` }`),e.push(` return $flagMatch`),e.push(`}`),e.push(``),e.push(`function ${t}_FormatCompletionValue {`),e.push(` param([string]$Value)`),e.push(` if ($Value.Length -eq 0) {`),e.push(` return "''"`),e.push(` }`),e.push(``),e.push(` if ($Value -match '^[a-zA-Z0-9_./:\\\\-]+$') {`),e.push(` return $Value`),e.push(` }`),e.push(``),e.push(` return "'$([CodeGeneration]::EscapeSingleQuotedStringContent($Value))'"`),e.push(`}`),e.push(``),e.push(`function ${t}_MatchesCompletionPrefix {`),e.push(` param([string]$WordToComplete, [string]$RawText, [string]$CompletionText)`),e.push(` if ([string]::IsNullOrEmpty($WordToComplete)) {`),e.push(` return $true`),e.push(` }`),e.push(``),e.push(` return $RawText.StartsWith($WordToComplete, [System.StringComparison]::OrdinalIgnoreCase) -or $CompletionText.StartsWith($WordToComplete, [System.StringComparison]::OrdinalIgnoreCase)`),e.push(`}`),e.push(``),e.push(`function ${t}_AddCommandResults {`),e.push(` param($Results, $PathData, [string]$WordToComplete)`),e.push(` foreach ($command in $PathData.Commands) {`),e.push(` foreach ($name in $command.Names) {`),e.push(` if (-not [string]::IsNullOrEmpty($WordToComplete) -and -not $name.StartsWith($WordToComplete, [System.StringComparison]::OrdinalIgnoreCase)) {`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` $Results.Add([CompletionResult]::new(`),e.push(` $name,`),e.push(` $name,`),e.push(` [CompletionResultType]::Command,`),e.push(` $command.Description`),e.push(` ))`),e.push(` }`),e.push(` }`),e.push(`}`),e.push(``),e.push(`function ${t}_AddFlagResults {`),e.push(r?` param($Results, $PathData, [string]$WordToComplete, [string[]]$BlockedFlags)`:` param($Results, $PathData, [string]$WordToComplete)`),e.push(` foreach ($flag in $PathData.Flags) {`),e.push(` foreach ($form in $flag.Forms) {`),r&&e.push(` if ($BlockedFlags -ccontains $flag.CanonicalName -and $form -cne $flag.NegatedForm) { continue }`),e.push(` if (-not [string]::IsNullOrEmpty($WordToComplete) -and -not $form.StartsWith($WordToComplete, [System.StringComparison]::OrdinalIgnoreCase)) {`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` $Results.Add([CompletionResult]::new(`),e.push(` $form,`),e.push(` $form,`),e.push(` [CompletionResultType]::ParameterName,`),e.push(` $flag.Description`),e.push(` ))`),e.push(` }`),e.push(` }`),e.push(`}`),e.push(``),e.push(`function ${t}_AddEnumResults {`),e.push(` param($Results, $Flag, [string]$WordToComplete)`),e.push(` foreach ($value in $Flag.EnumValues) {`),e.push(`\t\t$completionText = ${t}_FormatCompletionValue -Value $value`),e.push(`\t\tif (-not (${t}_MatchesCompletionPrefix -WordToComplete $WordToComplete -RawText $value -CompletionText $completionText)) {`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` $Results.Add([CompletionResult]::new(`),e.push(` $completionText,`),e.push(` $value,`),e.push(` [CompletionResultType]::ParameterValue,`),e.push(` $Flag.Description`),e.push(` ))`),e.push(` }`),e.push(`}`),e.push(``),e.push(`function ${t}_AddInlineEnumResults {`),e.push(` param($Results, $InlineValue, [string]$WordToComplete)`),e.push(` foreach ($value in $InlineValue.Flag.EnumValues) {`),e.push(` $rawCompletion = "$($InlineValue.InlinePrefix)$value"`),e.push(`\t\t$formattedValue = ${t}_FormatCompletionValue -Value $value`),e.push(` $completionText = "$($InlineValue.InlinePrefix)$formattedValue"`),e.push(`\t\tif (-not (${t}_MatchesCompletionPrefix -WordToComplete $WordToComplete -RawText $rawCompletion -CompletionText $completionText)) {`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` $Results.Add([CompletionResult]::new(`),e.push(` $completionText,`),e.push(` $value,`),e.push(` [CompletionResultType]::ParameterValue,`),e.push(` $InlineValue.Flag.Description`),e.push(` ))`),e.push(` }`),e.push(`}`)}function quotePowerShellString(e){return`'${e.replace(/'/g,`''`)}'`}function formatPowerShellArray(e){return e.length===0?`@()`:`@(${e.map(quotePowerShellString).join(`, `)})`}function dedupeValues(e){return[...new Set(e)]}function generateZshCompletion(e,t){let n=`_${sanitizeShellIdentifier(t?.functionPrefix??e.name)}`,r=resolveRootCompletionSurface(e,t?.rootMode),i=r.visibleCommands,a=walkCommandTree(i),o=[];o.push(`#compdef ${quoteShellArg(e.name)}`),o.push(`# Zsh completion for ${programTag(e)}`),o.push(`# Generated by ${versionTag()}`),o.push(`#`),o.push(`# Usage: source <(${e.name} completions zsh)`),o.push(`#`),o.push(`# Install permanently:`),o.push(`# ${e.name} completions zsh > "\${fpath[1]}/_${e.name}"`),o.push(`# # Then restart your shell`),o.push(``);let s=a.filter(e=>e.children.length>0),c=a.filter(e=>e.children.length===0);for(let e of c)e.path.length<2||emitZshLeafFunction(o,`${n}_${e.path.map(sanitizeShellIdentifier).join(`_`)}`,e);let l=[...s].sort((e,t)=>t.path.length-e.path.length);for(let e of l)emitZshGroupFunction(o,`${n}_${e.path.map(sanitizeShellIdentifier).join(`_`)}`,n,e);if(o.push(`${n}() {`),hasDynamicCompletion(e)&&(o.push(` local dynamic word current_prefix=$PREFIX`),o.push(` local -a dynamic_words=()`),o.push(' for word in "${words[@]:1:$((CURRENT-2))}"; do'),o.push(' dynamic_words+=("${(Q)word}")'),o.push(` done`),o.push(` if [[ $compstate[quoting] = (single|double) ]]; then`),o.push(` current_prefix="$compstate[quote]$PREFIX$compstate[quote]"`),o.push(` fi`),o.push(' dynamic_words+=("${(Q)current_prefix}")'),o.push(`\tif dynamic=$(command ${quoteShellArg(e.name)} __complete -- "\${dynamic_words[@]}" 2>/dev/null); then`),o.push(` local -a candidates`),o.push(` if [[ -n "$dynamic" ]]; then`),o.push(' candidates=("${(@f)dynamic}")'),o.push(` compadd -a candidates`),o.push(` fi`),o.push(` return`),o.push(` fi`)),i.length>0){o.push(` local -a subcmds`),o.push(` local line state`),o.push(``);let e=buildZshFlagSpecsFromFlags({...r.rootFlags,...r.includeDefaultFlags?r.defaultFlags:{}});o.push(` _arguments -C \\`);for(let t of e)o.push(`\t\t${t} \\`);o.push(` '1: :->subcmd' \\`),o.push(` '*::arg:->args'`),o.push(``),o.push(` case "$state" in`),o.push(` subcmd)`),o.push(` subcmds=(`),appendZshCommandCandidates(o,i,` `),o.push(` )`),o.push(` _describe 'command' subcmds`),o.push(` ;;`),o.push(` args)`),o.push(` case "$line[1]" in`);for(let e of i){let t=[e.name,...e.aliases].map(escapeZshCasePatternValue),r=e.commands.filter(e=>!e.hidden);if(o.push(`\t\t\t\t${t.join(`|`)})`),r.length>0){let t=`${n}_${sanitizeShellIdentifier(e.name)}`;o.push(`\t\t\t\t\t${t}`)}else{let t=a.find(t=>t.path.length===1&&t.schema.name===e.name);if(t===void 0)throw new CLIError(`Missing completion node for command '${e.name}'`,{code:`UNEXPECTED_ERROR`});let n=buildZshFlagSpecsFromFlags(t.mergedFlags);if(n.length>0){o.push(` _arguments \\`);for(let e=0;e<n.length;e++){let t=e<n.length-1?` \\`:``;o.push(`\t\t\t\t\t\t${n[e]}${t}`)}}}o.push(` ;;`)}o.push(` esac`),o.push(` ;;`),o.push(` esac`)}else{let e=buildZshFlagSpecsFromFlags({...r.rootFlags,...r.includeDefaultFlags?r.defaultFlags:{}});o.push(` _arguments \\`);for(let t=0;t<e.length;t++){let n=t<e.length-1?` \\`:``;o.push(`\t\t${e[t]}${n}`)}}return o.push(`}`),o.push(``),o.push(`compdef ${n} ${quoteShellArg(e.name)}`),o.push(``),o.join(`
|
|
59
|
+
`)}function emitZshGroupFunction(e,t,n,r){e.push(`${t}() {`),e.push(` local -a subcmds`),e.push(` local line state`),e.push(``);let i=buildZshFlagSpecsFromFlags(r.mergedFlags);e.push(` _arguments -C \\`);for(let t of i)e.push(`\t\t${t} \\`);e.push(` '1: :->subcmd' \\`),e.push(` '*::arg:->args'`),e.push(``),e.push(` case "$state" in`),e.push(` subcmd)`),e.push(` subcmds=(`),appendZshCommandCandidates(e,r.children,` `),e.push(` )`),e.push(` _describe 'command' subcmds`),e.push(` ;;`),e.push(` args)`),e.push(` case "$line[1]" in`);for(let t of r.children){let i=[t.name,...t.aliases].map(escapeZshCasePatternValue),a=`${n}_${[...r.path,t.name].map(sanitizeShellIdentifier).join(`_`)}`;e.push(`\t\t\t\t${i.join(`|`)})`),e.push(`\t\t\t\t\t${a}`),e.push(` ;;`)}e.push(` esac`),e.push(` ;;`),e.push(` esac`),e.push(`}`),e.push(``)}function emitZshLeafFunction(e,t,n){let r=buildZshFlagSpecsFromFlags(n.mergedFlags);if(e.push(`${t}() {`),r.length>0){e.push(` _arguments \\`);for(let t=0;t<r.length;t++){let n=t<r.length-1?` \\`:``;e.push(`\t\t${r[t]}${n}`)}}e.push(`}`),e.push(``)}function appendZshCommandCandidates(e,t,n){for(let r of t){let t=r.description??r.name;for(let i of[r.name,...r.aliases])e.push(`${n}${quoteShellArg(`${i}:${t}`)}`)}}function escapeZshCasePatternValue(e){return/^[a-zA-Z0-9_\-.]+$/.test(e)?e:e.replace(/\\/g,`\\\\`).replace(/'/g,`\\'`).replace(/"/g,`\\"`).replace(/`/g,"\\`").replace(/\|/g,`\\|`).replace(/\*/g,`\\*`).replace(/\?/g,`\\?`).replace(/\[/g,`\\[`).replace(/\]/g,`\\]`).replace(/\(/g,`\\(`).replace(/\)/g,`\\)`).replace(/\{/g,`\\{`).replace(/\}/g,`\\}`).replace(/\+/g,`\\+`).replace(/!/g,`\\!`).replace(/@/g,`\\@`).replace(/#/g,`\\#`).replace(/~/g,`\\~`).replace(/\s/g,e=>e===` `?`\\ `:`\\${e}`)}function escapeZshDescription(e){return e.replace(/\\/g,`\\\\`).replace(/\]/g,`\\]`)}function buildZshFlagSpecsFromFlags(e){let t=[];for(let[n,r]of Object.entries(e)){if(!acceptsArgv(r))continue;let e=escapeZshDescription(r.description===void 0?n:resolvePlainHelpDescription(r.description)),i=`--${n}`,a=getFlagAliasNames(r,{kind:`short`}).map(e=>`-${e}`),o=getFlagAliasNames(r,{kind:`long`}).map(e=>`--${e}`),s=getVisibleNegatedName(n,r),c=s===void 0?[]:[`--${s}`],l=[...a,i,...o,...c],u=r.kind===`keyValue`?void 0:valueEnumValues(flagValueSchema(r)),d=``;if(flagExpectsValue(r)&&(d=u===void 0?`:value:`:`:value:(${u.map(escapeZshEnumValue).join(` `)})`),l.length>1){let n=l.map(escapeZshCasePatternValue).join(`,`);t.push(`${quoteShellArg(`(${l.join(` `)})`)}{${n}}${quoteShellArg(`[${e}]${d}`)}`)}else t.push(quoteShellArg(`${i}[${e}]${d}`))}return t}function escapeZshEnumValue(e){return/^[a-zA-Z0-9_\-.]+$/.test(e)?e:e.replace(/\\/g,`\\\\`).replace(/ /g,`\\ `).replace(/\(/g,`\\(`).replace(/\)/g,`\\)`)}var completion_exports=/* @__PURE__ */ __exportAll({generateCompletion:()=>generateCompletion});function generateCompletion(e,t,n){switch(t){case`bash`:return generateBashCompletion(e,n);case`zsh`:return generateZshCompletion(e,n);case`fish`:return generateFishCompletion(e,n);case`powershell`:return generatePowerShellCompletion(e,n)}}export{generateFishCompletion as a,generatePowerShellCompletion as i,generateCompletion as n,generateBashCompletion as o,generateZshCompletion as r,completion_exports as t};
|
package/dist/completion.d.mts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @module @kjanat/dreamcli/completion
|
|
10
10
|
*/
|
|
11
|
-
import { C as SHELLS, T as CompletionOptions, o as CLISchema, w as Shell } from "./index-
|
|
11
|
+
import { C as SHELLS, T as CompletionOptions, o as CLISchema, w as Shell } from "./index-Bkk86gFg.mjs";
|
|
12
12
|
/**
|
|
13
13
|
* Generate a bash completion script for the CLI.
|
|
14
14
|
*
|
package/dist/completion.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as generateFishCompletion,i as generatePowerShellCompletion,n as generateCompletion,o as generateBashCompletion,r as generateZshCompletion}from"./completion-
|
|
1
|
+
import{a as generateFishCompletion,i as generatePowerShellCompletion,n as generateCompletion,o as generateBashCompletion,r as generateZshCompletion}from"./completion-DCWRvQjQ.mjs";import{Ct as SHELLS}from"./core-CPh0FcFg.mjs";export{SHELLS,generateBashCompletion,generateCompletion,generateFishCompletion,generatePowerShellCompletion,generateZshCompletion};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as __exportAll}from"./rolldown-runtime-DOYBPklu.mjs";import{
|
|
1
|
+
import{t as __exportAll}from"./rolldown-runtime-DOYBPklu.mjs";import{_t as CLIError}from"./core-CPh0FcFg.mjs";var config_exports=/* @__PURE__ */ __exportAll({discoverConfig:()=>discoverConfig});function isPlainObject(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}const jsonLoader={extensions:[`json`],parse:e=>{let t=JSON.parse(e);if(typeof t!=`object`||!t||Array.isArray(t))throw Error(`Config must be a JSON object`);return t}};function joinPath(e,...t){let n=e.includes(`\\`)?`\\`:`/`;return[e.endsWith(n)?e.slice(0,-1):e,...t].join(n)}function ancestorDirs(e){let t=e.includes(`\\`)?`\\`:`/`,n=e;for(;n.length>1&&n.endsWith(t)&&!n.endsWith(`:${t}`);)n=n.slice(0,-1);let r=[n];for(;;){let e=n.lastIndexOf(t);if(e<0)break;let i=n.slice(0,e);if(i===``?i=t:/^[A-Za-z]:$/.test(i)&&(i=`${i}${t}`),i===n)break;r.push(i),n=i}return r}function getExtension(e){let t=e.lastIndexOf(`.`);return t<=Math.max(e.lastIndexOf(`/`),e.lastIndexOf(`\\`))?``:e.slice(t+1).toLowerCase()}function buildConfigSearchPaths(e,t){let n=buildExtensionList(t.loaders),r=[];for(let i of ancestorDirs(t.baseDir)){for(let t of n)r.push(joinPath(i,`.${e}.${t}`));for(let t of n)r.push(joinPath(i,`${e}.config.${t}`));for(let t of n)r.push(joinPath(i,`.config`,`${e}.${t}`))}for(let i of t.userConfigDirs)for(let t of n)r.push(joinPath(i,e,`config.${t}`));for(let i of t.systemConfigDirs??[])for(let t of n)r.push(joinPath(i,e,`config.${t}`));return r}function buildExtensionList(e){let t=/* @__PURE__ */ new Set,n=[];for(let e of jsonLoader.extensions){let r=e.toLowerCase();t.has(r)||(t.add(r),n.push(r))}if(e!==void 0)for(let r of e)for(let e of r.extensions){let r=e.toLowerCase();t.has(r)||(t.add(r),n.push(r))}return n}function buildLoaderMap(e){let t=/* @__PURE__ */ new Map;for(let e of jsonLoader.extensions)t.set(e.toLowerCase(),jsonLoader);if(e!==void 0)for(let n of e)for(let e of n.extensions)t.set(e.toLowerCase(),n);return t}async function discoverConfig(e,t,n){let r=buildLoaderMap(n?.loaders),i=n?.configPath===void 0?n?.searchPaths??buildConfigSearchPaths(e,{baseDir:n?.baseDir??t.cwd,userConfigDirs:t.userConfigDirs??[t.configDir],systemConfigDirs:t.systemConfigDirs??[],...n?.loaders===void 0?{}:{loaders:n.loaders}}):[n.configPath];for(let e of i){let i=await t.readFile(e);if(i===null){if(n?.configPath!==void 0)throw new CLIError(`Config file not found: ${e}`,{code:`CONFIG_NOT_FOUND`,details:{path:e},suggest:`Create the config file or remove the --config flag`});continue}let a=getExtension(e),o=r.get(a);if(o===void 0)throw new CLIError(`No loader registered for config format: .${a}`,{code:`CONFIG_UNKNOWN_FORMAT`,details:{path:e,extension:a},suggest:`Supported formats: ${[...r.keys()].join(`, `)}`});try{let n=`parse`in o?o.parse(i):await o.load(e,t);if(!isPlainObject(n))throw Error(`Config loader must return a plain object`);return{found:!0,path:e,data:n,format:a}}catch(t){throw new CLIError(`Failed to parse config file: ${e}`,{code:`CONFIG_PARSE_ERROR`,cause:t,details:{path:e,format:a,message:t instanceof Error?t.message:String(t)},suggest:`parse`in o?`Check the config file for syntax errors`:`Check that the config loader can load this file and returns a plain object`})}}return{found:!1}}function configFormat(e,t){return{extensions:e,parse:t}}function configModule(e){return{extensions:e?.typescript?[`mjs`,`cjs`,`js`,`ts`,`mts`,`cts`]:[`mjs`,`cjs`,`js`],load(e,t){if(t.importConfigModule===void 0)throw Error(`The runtime adapter does not support executable config files`);return t.importConfigModule(e)}}}export{discoverConfig as a,config_exports as i,configFormat as n,configModule as r,buildConfigSearchPaths as t};
|
package/dist/config.d.mts
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @module @kjanat/dreamcli/config
|
|
10
10
|
*/
|
|
11
|
-
import { _ as
|
|
12
|
-
export { type ConfigAdapter, type ConfigDiscoveryOptions, type ConfigDiscoveryResult, type ConfigFound, type ConfigNotFound, type ConfigSearchPathOptions, type FormatLoader, type ManifestDiscoveryOptions, type PackageJsonAdapter, type PackageJsonData, type PackageRepository, type PackageRepositoryUrlOptions, buildConfigSearchPaths, configFormat, discoverConfig, discoverManifest, inferCliName, packageRepositoryUrl };
|
|
11
|
+
import { S as inferCliName, _ as ManifestDiscoveryOptions, a as ConfigLoader, b as PackageRepository, c as ConfigSearchPathOptions, d as buildConfigSearchPaths, f as configFormat, g as packageRepositoryUrl, h as PackageRepositoryUrlOptions, i as ConfigFound, l as FormatLoader, m as discoverConfig, n as ConfigDiscoveryOptions, o as ConfigModuleOptions, p as configModule, r as ConfigDiscoveryResult, s as ConfigNotFound, t as ConfigAdapter, u as PathConfigLoader, v as PackageJsonAdapter, x as discoverManifest, y as PackageJsonData } from "./index-8EiEDJfX.mjs";
|
|
12
|
+
export { type ConfigAdapter, type ConfigDiscoveryOptions, type ConfigDiscoveryResult, type ConfigFound, type ConfigLoader, type ConfigModuleOptions, type ConfigNotFound, type ConfigSearchPathOptions, type FormatLoader, type ManifestDiscoveryOptions, type PackageJsonAdapter, type PackageJsonData, type PackageRepository, type PackageRepositoryUrlOptions, type PathConfigLoader, buildConfigSearchPaths, configFormat, configModule, discoverConfig, discoverManifest, inferCliName, packageRepositoryUrl };
|
package/dist/config.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{x as packageRepositoryUrl}from"./core-
|
|
1
|
+
import{x as packageRepositoryUrl}from"./core-CPh0FcFg.mjs";import{n as inferCliName,t as discoverManifest}from"./package-json-hqUWeazy.mjs";import{a as discoverConfig,n as configFormat,r as configModule,t as buildConfigSearchPaths}from"./config-CANc4lsA.mjs";export{buildConfigSearchPaths,configFormat,configModule,discoverConfig,discoverManifest,inferCliName,packageRepositoryUrl};
|