@kjanat/dreamcli 4.0.0-rc.3 → 4.1.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/README.md +5 -7
- package/dist/{runtime/adapter.d.mts → adapter-YM5QGi3M.d.mts} +4 -4
- package/dist/completion-CUMeOnAz.mjs +6 -0
- package/dist/completion.d.mts +90 -0
- package/dist/completion.mjs +1 -0
- package/dist/config-CrlScpYX.mjs +1 -0
- package/dist/config.d.mts +2 -0
- package/dist/config.mjs +1 -0
- package/dist/core-DvXUolc_.mjs +17 -0
- package/dist/{core/json-schema/index.d.mts → index-3l8uj16E.d.mts} +43 -34
- package/dist/{core/cli/index.d.mts → index-BAj2y70U.d.mts} +116 -57
- package/dist/index-BziI2aKc.d.mts +5440 -0
- package/dist/index-Cap0MA2V.d.mts +277 -0
- package/dist/index-Cp9kt2t-.d.mts +370 -0
- package/dist/index-DWsnGZlx.d.mts +831 -0
- package/dist/index.d.mts +190 -41
- package/dist/index.mjs +1 -26
- package/dist/json-schema-DRlrz_IV.mjs +52 -0
- package/dist/json-schema.d.mts +2 -0
- package/dist/json-schema.mjs +1 -0
- package/dist/package-json-BgE9YjjQ.mjs +3 -0
- package/dist/prompt.d.mts +48 -0
- package/dist/prompt.mjs +1 -0
- package/dist/rolldown-runtime-G4Kt5YOX.mjs +1 -0
- package/dist/runtime.d.mts +2 -6
- package/dist/runtime.mjs +1 -6
- package/dist/terminal-C8KTXjv5.mjs +6 -0
- package/dist/test-prompter-v__jT2yG.mjs +1 -0
- package/dist/testkit.d.mts +54 -6
- package/dist/testkit.mjs +1 -5
- package/dist/version.mjs +1 -7
- package/dreamcli.schema.json +697 -538
- package/package.json +29 -7
- package/skills/cli-creation/SKILL.md +16 -11
- package/CHANGELOG.md +0 -1116
- package/dist/core/cli/builtins.d.mts +0 -117
- package/dist/core/cli/builtins.mjs +0 -135
- package/dist/core/cli/compiled.d.mts +0 -66
- package/dist/core/cli/compiled.mjs +0 -76
- package/dist/core/cli/dispatch.d.mts +0 -115
- package/dist/core/cli/dispatch.mjs +0 -205
- package/dist/core/cli/help-links.d.mts +0 -27
- package/dist/core/cli/help-links.mjs +0 -41
- package/dist/core/cli/index.mjs +0 -1271
- package/dist/core/cli/planner.d.mts +0 -174
- package/dist/core/cli/planner.mjs +0 -323
- package/dist/core/cli/plugin.d.mts +0 -94
- package/dist/core/cli/plugin.mjs +0 -41
- package/dist/core/cli/propagate.d.mts +0 -39
- package/dist/core/cli/propagate.mjs +0 -57
- package/dist/core/cli/reserved-flags.d.mts +0 -19
- package/dist/core/cli/reserved-flags.mjs +0 -158
- package/dist/core/cli/root-help.d.mts +0 -53
- package/dist/core/cli/root-help.mjs +0 -221
- package/dist/core/cli/root-output-flags.d.mts +0 -74
- package/dist/core/cli/root-output-flags.mjs +0 -169
- package/dist/core/cli/root-surface.d.mts +0 -64
- package/dist/core/cli/root-surface.mjs +0 -28
- package/dist/core/cli/runtime-preflight.d.mts +0 -213
- package/dist/core/cli/runtime-preflight.mjs +0 -221
- package/dist/core/completion/index.d.mts +0 -76
- package/dist/core/completion/index.mjs +0 -90
- package/dist/core/completion/shells/bash.d.mts +0 -23
- package/dist/core/completion/shells/bash.mjs +0 -312
- package/dist/core/completion/shells/fish.d.mts +0 -19
- package/dist/core/completion/shells/fish.mjs +0 -164
- package/dist/core/completion/shells/powershell.d.mts +0 -13
- package/dist/core/completion/shells/powershell.mjs +0 -360
- package/dist/core/completion/shells/shared.d.mts +0 -164
- package/dist/core/completion/shells/shared.mjs +0 -147
- package/dist/core/completion/shells/zsh.d.mts +0 -23
- package/dist/core/completion/shells/zsh.mjs +0 -256
- package/dist/core/config/index.d.mts +0 -191
- package/dist/core/config/index.mjs +0 -285
- package/dist/core/config/package-json.d.mts +0 -179
- package/dist/core/config/package-json.mjs +0 -353
- package/dist/core/errors/index.d.mts +0 -125
- package/dist/core/errors/index.mjs +0 -87
- package/dist/core/execution/index.d.mts +0 -61
- package/dist/core/execution/index.mjs +0 -220
- package/dist/core/help/ansi.d.mts +0 -84
- package/dist/core/help/ansi.mjs +0 -121
- package/dist/core/help/index.d.mts +0 -149
- package/dist/core/help/index.mjs +0 -418
- package/dist/core/help/theme.d.mts +0 -86
- package/dist/core/help/theme.mjs +0 -69
- package/dist/core/json-schema/index.mjs +0 -1008
- package/dist/core/json-schema/meta-descriptions.generated.d.mts +0 -274
- package/dist/core/json-schema/meta-descriptions.generated.mjs +0 -136
- package/dist/core/output/activity.d.mts +0 -193
- package/dist/core/output/activity.mjs +0 -452
- package/dist/core/output/bind.d.mts +0 -37
- package/dist/core/output/bind.mjs +0 -56
- package/dist/core/output/contracts.d.mts +0 -82
- package/dist/core/output/contracts.mjs +0 -57
- package/dist/core/output/display-value.d.mts +0 -19
- package/dist/core/output/display-value.mjs +0 -32
- package/dist/core/output/index.d.mts +0 -344
- package/dist/core/output/index.mjs +0 -514
- package/dist/core/output/renderers.d.mts +0 -45
- package/dist/core/output/renderers.mjs +0 -46
- package/dist/core/output/writer.d.mts +0 -39
- package/dist/core/output/writer.mjs +0 -12
- package/dist/core/parse/index.d.mts +0 -178
- package/dist/core/parse/index.mjs +0 -850
- package/dist/core/parse/occurrences.d.mts +0 -90
- package/dist/core/parse/occurrences.mjs +0 -114
- package/dist/core/prompt/index.d.mts +0 -213
- package/dist/core/prompt/index.mjs +0 -348
- package/dist/core/read-flags/index.d.mts +0 -150
- package/dist/core/read-flags/index.mjs +0 -217
- package/dist/core/resolve/args.d.mts +0 -39
- package/dist/core/resolve/args.mjs +0 -182
- package/dist/core/resolve/coerce.d.mts +0 -79
- package/dist/core/resolve/coerce.mjs +0 -900
- package/dist/core/resolve/config.d.mts +0 -10
- package/dist/core/resolve/config.mjs +0 -19
- package/dist/core/resolve/contracts.d.mts +0 -146
- package/dist/core/resolve/errors.d.mts +0 -10
- package/dist/core/resolve/errors.mjs +0 -148
- package/dist/core/resolve/flags.d.mts +0 -74
- package/dist/core/resolve/flags.mjs +0 -246
- package/dist/core/resolve/index.d.mts +0 -44
- package/dist/core/resolve/index.mjs +0 -123
- package/dist/core/resolve/path-checks.d.mts +0 -48
- package/dist/core/resolve/path-checks.mjs +0 -102
- package/dist/core/resolve/redaction.d.mts +0 -13
- package/dist/core/resolve/redaction.mjs +0 -14
- package/dist/core/resolve/stages.d.mts +0 -86
- package/dist/core/resolve/stages.mjs +0 -170
- package/dist/core/resolve/standard.d.mts +0 -26
- package/dist/core/resolve/standard.mjs +0 -212
- package/dist/core/schema/activity.d.mts +0 -189
- package/dist/core/schema/arg.d.mts +0 -1461
- package/dist/core/schema/arg.mjs +0 -1139
- package/dist/core/schema/brand.d.mts +0 -17
- package/dist/core/schema/cardinality.d.mts +0 -302
- package/dist/core/schema/cardinality.mjs +0 -514
- package/dist/core/schema/command.d.mts +0 -1132
- package/dist/core/schema/command.mjs +0 -999
- package/dist/core/schema/flag.d.mts +0 -1495
- package/dist/core/schema/flag.mjs +0 -1207
- package/dist/core/schema/index.d.mts +0 -15
- package/dist/core/schema/index.mjs +0 -10
- package/dist/core/schema/middleware.d.mts +0 -129
- package/dist/core/schema/middleware.mjs +0 -41
- package/dist/core/schema/number-constraints.d.mts +0 -96
- package/dist/core/schema/number-constraints.mjs +0 -60
- package/dist/core/schema/prompt.d.mts +0 -135
- package/dist/core/schema/provenance.d.mts +0 -99
- package/dist/core/schema/provenance.mjs +0 -28
- package/dist/core/schema/run.d.mts +0 -211
- package/dist/core/schema/source.d.mts +0 -180
- package/dist/core/schema/source.mjs +0 -206
- package/dist/core/schema/standard.d.mts +0 -100
- package/dist/core/schema/standard.mjs +0 -15
- package/dist/core/schema/stdin.d.mts +0 -97
- package/dist/core/schema/stdin.mjs +0 -91
- package/dist/core/schema/string-constraints.d.mts +0 -108
- package/dist/core/schema/string-constraints.mjs +0 -86
- package/dist/core/schema/value-parsers.d.mts +0 -150
- package/dist/core/schema/value-parsers.mjs +0 -160
- package/dist/core/schema/value.d.mts +0 -243
- package/dist/core/schema/value.mjs +0 -573
- package/dist/core/testkit/index.d.mts +0 -63
- package/dist/core/testkit/index.mjs +0 -102
- package/dist/runtime/adapter.mjs +0 -92
- package/dist/runtime/auto.d.mts +0 -25
- package/dist/runtime/auto.mjs +0 -45
- package/dist/runtime/deno.d.mts +0 -99
- package/dist/runtime/deno.mjs +0 -265
- package/dist/runtime/detect.d.mts +0 -86
- package/dist/runtime/detect.mjs +0 -45
- package/dist/runtime/index.d.mts +0 -6
- package/dist/runtime/node.d.mts +0 -71
- package/dist/runtime/node.mjs +0 -228
- package/dist/runtime/paths.d.mts +0 -31
- package/dist/runtime/paths.mjs +0 -48
- package/dist/strings.d.mts +0 -27
- package/dist/strings.mjs +0 -22
- package/examples/basic.ts +0 -37
- package/examples/flag-types.ts +0 -79
- package/examples/gh/package.json +0 -45
- package/examples/gh/src/commands/auth.ts +0 -66
- package/examples/gh/src/commands/issue.ts +0 -120
- package/examples/gh/src/commands/pr.ts +0 -125
- package/examples/gh/src/data/issues.yaml +0 -5
- package/examples/gh/src/data/issues.yaml.d.ts +0 -17
- package/examples/gh/src/data/pull-requests.yaml +0 -7
- package/examples/gh/src/data/pull-requests.yaml.d.ts +0 -18
- package/examples/gh/src/docs.ts +0 -11
- package/examples/gh/src/lib/auth.ts +0 -37
- package/examples/gh/src/lib/utils.ts +0 -17
- package/examples/gh/src/main.test.ts +0 -307
- package/examples/gh/src/main.ts +0 -46
- package/examples/help-config.ts +0 -43
- package/examples/interactive.ts +0 -67
- package/examples/json-mode.ts +0 -95
- package/examples/middleware.ts +0 -71
- package/examples/multi-command.ts +0 -66
- package/examples/output-extras.ts +0 -46
- package/examples/parser-control.ts +0 -40
- package/examples/pwsh-demo/README.md +0 -40
- package/examples/pwsh-demo/package.json +0 -41
- package/examples/pwsh-demo/pwsh-demo.cmd +0 -3
- package/examples/pwsh-demo/smoke-powershell.ps1 +0 -218
- package/examples/pwsh-demo/src/main.test.ts +0 -45
- package/examples/pwsh-demo/src/main.ts +0 -140
- package/examples/spinner-progress.ts +0 -49
- package/examples/standard-schema.ts +0 -45
- package/examples/testing.ts +0 -147
- package/examples/transport-launcher.ts +0 -85
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[][jsr]
|
|
5
5
|
[][socket]
|
|
6
6
|
|
|
7
|
-
Schema-first, fully typed TypeScript CLI framework.
|
|
7
|
+
Schema-first, fully typed TypeScript CLI framework. One runtime dependency, `ansispeck`, for terminal colors.
|
|
8
8
|
|
|
9
9
|
One flag declaration configures the entire resolution pipeline:
|
|
10
10
|
|
|
@@ -404,11 +404,8 @@ cli('mycli').command(command('deploy')).completions({ as: 'flag' }).run();
|
|
|
404
404
|
For programmatic integrations, call the generator directly:
|
|
405
405
|
|
|
406
406
|
```ts
|
|
407
|
-
import {
|
|
408
|
-
|
|
409
|
-
command,
|
|
410
|
-
generateCompletion,
|
|
411
|
-
} from '@kjanat/dreamcli';
|
|
407
|
+
import { cli, command } from '@kjanat/dreamcli';
|
|
408
|
+
import { generateCompletion } from '@kjanat/dreamcli/completion';
|
|
412
409
|
|
|
413
410
|
const myCli = cli('mycli').command(command('deploy'));
|
|
414
411
|
|
|
@@ -430,7 +427,8 @@ command('deploy').flag(
|
|
|
430
427
|
Searches XDG-standard paths automatically. JSON built-in, plugin hook for YAML/TOML:
|
|
431
428
|
|
|
432
429
|
```ts
|
|
433
|
-
import { cli
|
|
430
|
+
import { cli } from '@kjanat/dreamcli';
|
|
431
|
+
import { configFormat } from '@kjanat/dreamcli/config';
|
|
434
432
|
import { parse as parseYAML } from 'yaml';
|
|
435
433
|
|
|
436
434
|
cli('mycli')
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { WriteFn } from "
|
|
2
|
-
import "../core/output/index.mjs";
|
|
3
|
-
import { ReadFn } from "../core/prompt/index.mjs";
|
|
1
|
+
import { a as WriteFn, s as ReadFn } from "./index-BziI2aKc.mjs";
|
|
4
2
|
//#region src/runtime/adapter.d.ts
|
|
5
3
|
/**
|
|
6
4
|
* Runtime adapter interface.
|
|
@@ -38,6 +36,8 @@ interface RuntimeAdapter {
|
|
|
38
36
|
readonly stdout: WriteFn;
|
|
39
37
|
/** Writer for stderr. Framework routes `out.warn`/`out.error` through this. */
|
|
40
38
|
readonly stderr: WriteFn;
|
|
39
|
+
/** Wait for pending output writes to settle, rejecting with a recorded output failure. */
|
|
40
|
+
readonly flush?: () => Promise<void>;
|
|
41
41
|
/**
|
|
42
42
|
* Line reader for stdin. Used by the prompt engine for interactive input.
|
|
43
43
|
*
|
|
@@ -278,4 +278,4 @@ declare class ExitError extends Error {
|
|
|
278
278
|
*/
|
|
279
279
|
declare function createTestAdapter(options?: TestAdapterOptions): RuntimeAdapter;
|
|
280
280
|
//#endregion
|
|
281
|
-
export {
|
|
281
|
+
export { createTestAdapter as a, TestAdapterOptions as i, RuntimeAdapter as n, TerminalSize as r, ExitError as t };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{t as __exportAll}from"./rolldown-runtime-G4Kt5YOX.mjs";import{C as flagExpectsValue,G as getFlagNegatedName,H as createFlagSchema,N as resolvePlainHelpDescription,Q as CLIError,W as getFlagAliasNames,Z as builtinEnabled,f as collectPropagatedFlags,u as resolveRootSurface}from"./core-DvXUolc_.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 getVisibleNegatedName(e,t){if(!(t.negation===void 0||t.negation.hidden))return getFlagNegatedName(e,t)}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 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(``),s.push(`${n}() {`),s.push(` local cur prev words cword`),s.push(` _init_completion || return`),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.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)){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=new Set,r=e=>{for(let[t,r]of Object.entries(e))if(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(r.kind!==`enum`||r.enumValues===void 0)continue;let e=[`--${n}`,...getFlagAliasNames(r,{includeHidden:!0}).map(e=>e.length===1?`-${e}`:`--${e}`)].map(escapeBashCasePatternValue);t.push({flags:e.join(`|`),values:r.enumValues})}return t}function generateFishCompletion(e,t){let n=`__${sanitizeShellIdentifier(t?.functionPrefix??e.name)}_completions`,r=`${n}_path`,i=`${n}_path_is`,a=resolveRootCompletionSurface(e,t?.rootMode),o=a.visibleCommands,s=walkCommandTree(o),c=quoteShellArg(e.name),l=[];l.push(`# Fish completion for ${programTag(e)}`),l.push(`# Generated by ${versionTag()}`),l.push(`#`),l.push(`# Usage: source (${e.name} completions fish | psub)`),l.push(`#`),l.push(`# Install permanently:`),l.push(`# ${e.name} completions fish > ~/.config/fish/completions/${e.name}.fish`),l.push(``),l.push(`complete -c ${c} -f`),l.push(``),emitFishPathHelpers(l,r,i,o,s,a),appendFishCommandCompletions(l,c,i,``,o),appendFishFlagCompletions(l,c,i,``,a.rootFlags),a.includeDefaultFlags&&appendFishFlagCompletions(l,c,i,``,a.defaultFlags);for(let e of s){let t=e.path.join(` `);appendFishCommandCompletions(l,c,i,t,e.children),appendFishFlagCompletions(l,c,i,t,e.mergedFlags)}return l.join(`
|
|
4
|
+
`)}function emitFishPathHelpers(e,t,n,r,i,a){let o=collectFishValueFlagPatterns(i,a);e.push(`function ${t}`),e.push(` set -l words (commandline -opc)`),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){let a=buildFishCondition(n,r);for(let[n,r]of Object.entries(i)){let i=[`complete -c ${t}`,`-n "${a}"`];for(let e of getFlagAliasNames(r,{kind:`short`}))i.push(`-s ${quoteShellArg(e)}`);i.push(`-l ${quoteShellArg(n)}`);for(let e of getFlagAliasNames(r,{kind:`long`}))i.push(`-l ${quoteShellArg(e)}`);let o=getVisibleNegatedName(n,r);if(o!==void 0&&i.push(`-l ${quoteShellArg(o)}`),i.push(`-d ${quoteShellArg(r.description===void 0?n:resolvePlainHelpDescription(r.description))}`),flagExpectsValue(r)&&i.push(`-r`,`-f`),r.kind===`enum`&&r.enumValues!==void 0){for(let t of r.enumValues)e.push([...i,`-a ${quoteShellArg(t)}`].join(` `));continue}e.push(i.join(` `))}Object.keys(i).length>0&&e.push(``)}function collectFishValueFlagPatterns(e,t){let n=new Set,r=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(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=[];return s.push(`# PowerShell completion for ${programTag(e)}`),s.push(`# Generated by ${versionTag()}`),s.push(`#`),s.push(`# Install for the current session:`),s.push(`# ${e.name} completions powershell | Out-String | Invoke-Expression`),s.push(`#`),s.push(`# Install permanently:`),s.push(`# ${e.name} completions powershell > $PROFILE.CurrentUserCurrentHost`),s.push(``),s.push(`using namespace System.Management.Automation`),s.push(`using namespace System.Management.Automation.Language`),s.push(``),emitPowerShellPathTable(s,r,i,o),s.push(``),emitPowerShellHelpers(s,n,r),s.push(``),s.push(`Register-ArgumentCompleter -Native -CommandName ${quotePowerShellString(e.name)} -ScriptBlock {`),s.push(` param($wordToComplete, $commandAst, $cursorPosition)`),s.push(`\t$state = ${n}_GetState -CommandAst $commandAst -CursorPosition $cursorPosition`),s.push(` if ($null -eq $state.PathData) {`),s.push(` return`),s.push(` }`),s.push(``),s.push(` $results = [System.Collections.Generic.List[CompletionResult]]::new()`),s.push(` if ($state.AfterSeparator) {`),s.push(` return $results`),s.push(` }`),s.push(``),s.push(` $wordPrefix = if ([string]::IsNullOrEmpty($wordToComplete)) { '' } else { $wordToComplete }`),s.push(``),s.push(` if ($state.ExpectingValue) {`),s.push(`\t\t${n}_AddEnumResults -Results $results -Flag $state.ValueFlag -WordToComplete $wordPrefix`),s.push(` return $results`),s.push(` }`),s.push(``),s.push(`\t$inlineValue = ${n}_ResolveInlineValueCompletion -PathData $state.PathData -WordToComplete $wordPrefix`),s.push(` if ($null -ne $inlineValue) {`),s.push(`\t\t${n}_AddInlineEnumResults -Results $results -InlineValue $inlineValue -WordToComplete $wordPrefix`),s.push(` return $results`),s.push(` }`),s.push(``),s.push(` if ($wordPrefix.StartsWith('-')) {`),s.push(`\t\t${n}_AddFlagResults -Results $results -PathData $state.PathData -WordToComplete $wordPrefix`),s.push(` return $results`),s.push(` }`),s.push(``),s.push(`\t${n}_AddCommandResults -Results $results -PathData $state.PathData -WordToComplete $wordPrefix`),s.push(`\t${n}_AddFlagResults -Results $results -PathData $state.PathData -WordToComplete $wordPrefix`),s.push(` return $results`),s.push(`}`),s.join(`
|
|
5
|
+
`)}function emitPowerShellPathTable(e,t,n,r){e.push(`$script:${t} = @{`),appendPowerShellPathEntry(e,``,n.visibleCommands,{...n.rootFlags,...n.includeDefaultFlags?n.defaultFlags:{}});for(let t of r)appendPowerShellPathEntry(e,t.path.join(` `),t.children,t.mergedFlags);e.push(`}`)}function appendPowerShellPathEntry(e,t,n,r){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)){let r=getVisibleNegatedName(t,n),i=getFlagNegatedName(t,n),a=dedupeValues([`--${t}`,...getFlagAliasNames(n,{kind:`short`}).map(e=>`-${e}`),...getFlagAliasNames(n,{kind:`long`}).map(e=>`--${e}`),...r===void 0?[]:[`--${r}`]]),o=dedupeValues([`--${t}`,...getFlagAliasNames(n,{kind:`short`,includeHidden:!0}).map(e=>`-${e}`),...getFlagAliasNames(n,{kind:`long`,includeHidden:!0}).map(e=>`--${e}`),...i===void 0?[]:[`--${i}`]]);e.push(` @{`),e.push(`\t\t\t\tCanonicalName = ${quotePowerShellString(t)}`),e.push(`\t\t\t\tForms = ${formatPowerShellArray(a)}`),e.push(`\t\t\t\tParseForms = ${formatPowerShellArray(o)}`),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.enumValues??[])}`),e.push(` }`)}e.push(` )`),e.push(` }`)}function emitPowerShellHelpers(e,t,n){e.push(`function ${t}_UnquoteToken {`),e.push(` param([string]$TokenText)`),e.push(` if ($TokenText.Length -lt 2) {`),e.push(` return $TokenText`),e.push(` }`),e.push(``),e.push(` if (($TokenText.StartsWith("'") -and $TokenText.EndsWith("'")) -or`),e.push(` ($TokenText.StartsWith('"') -and $TokenText.EndsWith('"'))) {`),e.push(` return $TokenText.Substring(1, $TokenText.Length - 2)`),e.push(` }`),e.push(``),e.push(` return $TokenText`),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(` param($Results, $PathData, [string]$WordToComplete)`),e.push(` foreach ($flag in $PathData.Flags) {`),e.push(` foreach ($form in $flag.Forms) {`),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}() {`),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(`
|
|
6
|
+
`)}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)){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=``;if(flagExpectsValue(r)&&(u=r.kind===`enum`&&r.enumValues!==void 0?`:value:(${r.enumValues.map(escapeZshEnumValue).join(` `)})`:`:value:`),l.length>1){let n=l.map(escapeZshCasePatternValue).join(`,`);t.push(`${quoteShellArg(`(${l.join(` `)})`)}{${n}}${quoteShellArg(`[${e}]${u}`)}`)}else t.push(quoteShellArg(`${i}[${e}]${u}`))}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=__exportAll({generateBashCompletion:()=>generateBashCompletion,generateCompletion:()=>generateCompletion,generateFishCompletion:()=>generateFishCompletion,generatePowerShellCompletion:()=>generatePowerShellCompletion,generateZshCompletion:()=>generateZshCompletion});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};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { C as SHELLS, T as CompletionOptions, o as CLISchema, w as Shell } from "./index-BAj2y70U.mjs";
|
|
2
|
+
//#region src/core/completion/shells/bash.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Generate a bash completion script for the CLI.
|
|
5
|
+
*
|
|
6
|
+
* Use this when you want a bash-specific script directly rather than routing
|
|
7
|
+
* through {@link generateCompletion}. The generated script expects the
|
|
8
|
+
* `bash-completion` package because it relies on `_init_completion`.
|
|
9
|
+
*
|
|
10
|
+
* @param schema - The CLI schema.
|
|
11
|
+
* @param options - Optional generator configuration.
|
|
12
|
+
* @returns A complete bash completion script.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const script = generateBashCompletion(app.schema);
|
|
17
|
+
* // install with: mycli completions bash > /etc/bash_completion.d/mycli
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
declare function generateBashCompletion(schema: CLISchema, options?: CompletionOptions): string;
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/core/completion/shells/fish.d.ts
|
|
23
|
+
/**
|
|
24
|
+
* Generate a fish completion script for the CLI.
|
|
25
|
+
*
|
|
26
|
+
* @param schema - The CLI schema.
|
|
27
|
+
* @param options - Optional generator configuration.
|
|
28
|
+
* @returns A complete fish completion script.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const script = generateFishCompletion(app.schema);
|
|
33
|
+
* // install with: mycli completions fish > ~/.config/fish/completions/mycli.fish
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
declare function generateFishCompletion(schema: CLISchema, options?: CompletionOptions): string;
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/core/completion/shells/powershell.d.ts
|
|
39
|
+
/**
|
|
40
|
+
* Generate a PowerShell completion script for the CLI.
|
|
41
|
+
*
|
|
42
|
+
* @param schema - The CLI schema.
|
|
43
|
+
* @param options - Optional generator configuration.
|
|
44
|
+
* @returns A complete PowerShell completion script.
|
|
45
|
+
*/
|
|
46
|
+
declare function generatePowerShellCompletion(schema: CLISchema, options?: CompletionOptions): string;
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/core/completion/shells/zsh.d.ts
|
|
49
|
+
/**
|
|
50
|
+
* Generate a zsh completion script for the CLI.
|
|
51
|
+
*
|
|
52
|
+
* Use this when you want a zsh-specific script directly rather than routing
|
|
53
|
+
* through {@link generateCompletion}. The generated script is compatible with
|
|
54
|
+
* zsh's normal `#compdef` / `fpath` loading flow.
|
|
55
|
+
*
|
|
56
|
+
* @param schema - The CLI schema.
|
|
57
|
+
* @param options - Optional generator configuration.
|
|
58
|
+
* @returns A complete zsh completion script.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* const script = generateZshCompletion(app.schema);
|
|
63
|
+
* // install with: mycli completions zsh > "${fpath[1]}/_mycli"
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare function generateZshCompletion(schema: CLISchema, options?: CompletionOptions): string;
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/core/completion/index.d.ts
|
|
69
|
+
/**
|
|
70
|
+
* Generate a completion script for the given shell.
|
|
71
|
+
*
|
|
72
|
+
* This is the primary completion entrypoint for most consumers. Pass a CLI
|
|
73
|
+
* schema and target shell, then write the returned script to a file or source
|
|
74
|
+
* it directly from the command line.
|
|
75
|
+
*
|
|
76
|
+
* @param schema - The CLI schema describing commands, flags, and args.
|
|
77
|
+
* @param shell - Target shell.
|
|
78
|
+
* @param options - Optional generator configuration such as function naming
|
|
79
|
+
* and root default-command completion behavior.
|
|
80
|
+
* @returns A complete shell completion script as a string.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* const script = generateCompletion(app.schema, 'bash');
|
|
85
|
+
* // e.g. source <(mycli completions bash)
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
declare function generateCompletion(schema: CLISchema, shell: Shell, options?: CompletionOptions): string;
|
|
89
|
+
//#endregion
|
|
90
|
+
export { type CompletionOptions, SHELLS, type Shell, generateBashCompletion, generateCompletion, generateFishCompletion, generatePowerShellCompletion, generateZshCompletion };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{it as SHELLS}from"./core-DvXUolc_.mjs";import{a as generateFishCompletion,i as generatePowerShellCompletion,n as generateCompletion,o as generateBashCompletion,r as generateZshCompletion}from"./completion-CUMeOnAz.mjs";export{SHELLS,generateBashCompletion,generateCompletion,generateFishCompletion,generatePowerShellCompletion,generateZshCompletion};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as __exportAll}from"./rolldown-runtime-G4Kt5YOX.mjs";import{Q as CLIError}from"./core-DvXUolc_.mjs";var config_exports=__exportAll({buildConfigSearchPaths:()=>buildConfigSearchPaths,configFormat:()=>configFormat,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=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=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 t=o.parse(i);if(!isPlainObject(t))throw Error(`Config loader must return a plain object`);return{found:!0,path:e,data:t,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:`Check the config file for syntax errors`})}}return{found:!1}}function configFormat(e,t){return{extensions:e,parse:t}}export{discoverConfig as i,configFormat as n,config_exports as r,buildConfigSearchPaths as t};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { _ as discoverManifest, a as ConfigNotFound, c as buildConfigSearchPaths, d as PackageRepositoryUrlOptions, f as packageRepositoryUrl, g as PackageRepository, h as PackageJsonData, i as ConfigFound, l as configFormat, m as PackageJsonAdapter, n as ConfigDiscoveryOptions, o as ConfigSearchPathOptions, p as ManifestDiscoveryOptions, r as ConfigDiscoveryResult, s as FormatLoader, t as ConfigAdapter, u as discoverConfig, v as inferCliName } from "./index-Cp9kt2t-.mjs";
|
|
2
|
+
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 };
|
package/dist/config.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{p as packageRepositoryUrl}from"./core-DvXUolc_.mjs";import{n as inferCliName,t as discoverManifest}from"./package-json-BgE9YjjQ.mjs";import{i as discoverConfig,n as configFormat,t as buildConfigSearchPaths}from"./config-CrlScpYX.mjs";export{buildConfigSearchPaths,configFormat,discoverConfig,discoverManifest,inferCliName,packageRepositoryUrl};
|