@kjanat/dreamcli 2.5.0 → 3.0.0-rc.10
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/CHANGELOG.md +344 -1
- package/README.md +9 -2
- package/dist/core/cli/dispatch.d.mts +6 -5
- package/dist/core/cli/dispatch.mjs +205 -1
- package/dist/core/cli/help-links.d.mts +0 -1
- package/dist/core/cli/help-links.mjs +41 -1
- package/dist/core/cli/index.d.mts +185 -19
- package/dist/core/cli/index.mjs +945 -1
- package/dist/core/cli/planner.d.mts +32 -6
- package/dist/core/cli/planner.mjs +300 -1
- package/dist/core/cli/plugin.d.mts +1 -1
- package/dist/core/cli/plugin.mjs +41 -1
- package/dist/core/cli/propagate.d.mts +1 -1
- package/dist/core/cli/propagate.mjs +57 -1
- package/dist/core/cli/root-help.d.mts +18 -3
- package/dist/core/cli/root-help.mjs +226 -6
- package/dist/core/cli/root-surface.d.mts +30 -4
- package/dist/core/cli/root-surface.mjs +28 -1
- package/dist/core/cli/runtime-preflight.d.mts +30 -3
- package/dist/core/cli/runtime-preflight.mjs +169 -1
- package/dist/core/completion/index.d.mts +32 -2
- package/dist/core/completion/index.mjs +90 -1
- package/dist/core/completion/shells/bash.d.mts +0 -1
- package/dist/core/completion/shells/bash.mjs +308 -3
- package/dist/core/completion/shells/fish.d.mts +0 -1
- package/dist/core/completion/shells/fish.mjs +162 -2
- package/dist/core/completion/shells/powershell.d.mts +0 -1
- package/dist/core/completion/shells/powershell.mjs +358 -2
- package/dist/core/completion/shells/shared.d.mts +23 -2
- package/dist/core/completion/shells/shared.mjs +176 -1
- package/dist/core/completion/shells/zsh.d.mts +0 -1
- package/dist/core/completion/shells/zsh.mjs +251 -2
- package/dist/core/config/index.d.mts +2 -3
- package/dist/core/config/index.mjs +246 -1
- package/dist/core/config/package-json.d.mts +27 -4
- package/dist/core/config/package-json.mjs +386 -3
- package/dist/core/errors/index.d.mts +3 -3
- package/dist/core/errors/index.mjs +87 -1
- package/dist/core/execution/index.d.mts +0 -1
- package/dist/core/execution/index.mjs +201 -1
- package/dist/core/help/ansi.d.mts +11 -5
- package/dist/core/help/ansi.mjs +121 -2
- package/dist/core/help/index.d.mts +65 -2
- package/dist/core/help/index.mjs +341 -7
- package/dist/core/help/theme.d.mts +68 -0
- package/dist/core/help/theme.mjs +46 -0
- package/dist/core/json-schema/index.d.mts +15 -2
- package/dist/core/json-schema/index.mjs +536 -12
- package/dist/core/json-schema/meta-descriptions.generated.d.mts +22 -5
- package/dist/core/json-schema/meta-descriptions.generated.mjs +102 -28
- package/dist/core/output/activity.d.mts +0 -1
- package/dist/core/output/activity.mjs +452 -1
- package/dist/core/output/bind.mjs +56 -1
- package/dist/core/output/contracts.d.mts +4 -5
- package/dist/core/output/contracts.mjs +57 -1
- package/dist/core/output/display-value.mjs +32 -1
- package/dist/core/output/index.d.mts +21 -1
- package/dist/core/output/index.mjs +442 -2
- package/dist/core/output/renderers.d.mts +0 -1
- package/dist/core/output/renderers.mjs +46 -1
- package/dist/core/output/writer.mjs +12 -1
- package/dist/core/parse/index.d.mts +54 -7
- package/dist/core/parse/index.mjs +727 -1
- package/dist/core/prompt/index.d.mts +12 -4
- package/dist/core/prompt/index.mjs +348 -6
- package/dist/core/resolve/args.d.mts +1 -1
- package/dist/core/resolve/args.mjs +105 -1
- package/dist/core/resolve/coerce.d.mts +1 -1
- package/dist/core/resolve/coerce.mjs +336 -1
- package/dist/core/resolve/config.mjs +19 -1
- package/dist/core/resolve/contracts.d.mts +9 -4
- package/dist/core/resolve/errors.d.mts +0 -1
- package/dist/core/resolve/errors.mjs +140 -2
- package/dist/core/resolve/flags.d.mts +7 -2
- package/dist/core/resolve/flags.mjs +251 -1
- package/dist/core/resolve/index.d.mts +2 -2
- package/dist/core/resolve/index.mjs +85 -1
- package/dist/core/resolve/property.d.mts +6 -2
- package/dist/core/resolve/property.mjs +53 -1
- package/dist/core/schema/activity.d.mts +31 -11
- package/dist/core/schema/arg.d.mts +92 -13
- package/dist/core/schema/arg.mjs +463 -1
- package/dist/core/schema/command.d.mts +29 -7
- package/dist/core/schema/command.mjs +726 -1
- package/dist/core/schema/flag.d.mts +577 -21
- package/dist/core/schema/flag.mjs +705 -1
- package/dist/core/schema/index.d.mts +5 -2
- package/dist/core/schema/middleware.d.mts +4 -3
- package/dist/core/schema/middleware.mjs +41 -1
- package/dist/core/schema/number-constraints.d.mts +96 -0
- package/dist/core/schema/number-constraints.mjs +60 -0
- package/dist/core/schema/prompt.d.mts +21 -3
- package/dist/core/schema/run.d.mts +24 -5
- package/dist/core/schema/string-constraints.d.mts +97 -0
- package/dist/core/schema/string-constraints.mjs +69 -0
- package/dist/core/schema/value-parsers.d.mts +78 -0
- package/dist/core/schema/value-parsers.mjs +142 -0
- package/dist/core/schema-dsl/runtime.mjs +271 -2
- package/dist/core/schema-dsl/to-json-schema.d.mts +0 -1
- package/dist/core/schema-dsl/to-json-schema.mjs +74 -1
- package/dist/core/testkit/index.d.mts +9 -36
- package/dist/core/testkit/index.mjs +83 -1
- package/dist/index.d.mts +12 -6
- package/dist/index.mjs +22 -1
- package/dist/runtime/adapter.d.mts +38 -2
- package/dist/runtime/adapter.mjs +87 -1
- package/dist/runtime/auto.d.mts +2 -3
- package/dist/runtime/auto.mjs +45 -1
- package/dist/runtime/deno.d.mts +24 -5
- package/dist/runtime/deno.mjs +262 -2
- package/dist/runtime/detect.mjs +45 -1
- package/dist/runtime/index.d.mts +3 -4
- package/dist/runtime/node.d.mts +8 -2
- package/dist/runtime/node.mjs +220 -2
- package/dist/runtime/paths.mjs +48 -1
- package/dist/runtime.d.mts +4 -4
- package/dist/runtime.mjs +6 -1
- package/dist/strings.mjs +22 -1
- package/dist/testkit.d.mts +1 -0
- package/dist/testkit.mjs +5 -1
- package/dist/version.d.mts +7 -3
- package/dist/version.mjs +7 -1
- package/dreamcli.schema.json +36 -7
- package/examples/basic.ts +5 -1
- package/examples/gh/package.json +2 -7
- package/examples/pwsh-demo/package.json +1 -7
- package/examples/pwsh-demo/src/main.test.ts +1 -4
- package/examples/pwsh-demo/src/main.ts +14 -4
- package/examples/transport-launcher.ts +85 -0
- package/package.json +43 -49
- package/dist/runtime/bun.d.mts +0 -28
- package/dist/runtime/bun.mjs +0 -1
- package/dist/runtime/support.d.mts +0 -42
- package/dist/runtime/support.mjs +0 -1
- package/src/core/cli/dispatch.ts +0 -349
- package/src/core/cli/help-links.ts +0 -82
- package/src/core/cli/index.ts +0 -1413
- package/src/core/cli/planner.ts +0 -487
- package/src/core/cli/plugin.ts +0 -117
- package/src/core/cli/propagate.ts +0 -97
- package/src/core/cli/root-help.ts +0 -252
- package/src/core/cli/root-surface.ts +0 -74
- package/src/core/cli/runtime-preflight.ts +0 -438
- package/src/core/completion/index.ts +0 -88
- package/src/core/completion/shells/bash.ts +0 -459
- package/src/core/completion/shells/fish.ts +0 -259
- package/src/core/completion/shells/powershell.ts +0 -439
- package/src/core/completion/shells/shared.ts +0 -283
- package/src/core/completion/shells/zsh.ts +0 -381
- package/src/core/config/index.ts +0 -417
- package/src/core/config/package-json.ts +0 -560
- package/src/core/errors/index.ts +0 -193
- package/src/core/execution/index.ts +0 -268
- package/src/core/help/ansi.ts +0 -144
- package/src/core/help/index.ts +0 -516
- package/src/core/json-schema/index.ts +0 -891
- package/src/core/json-schema/meta-descriptions.generated.ts +0 -185
- package/src/core/output/activity.ts +0 -575
- package/src/core/output/bind.ts +0 -59
- package/src/core/output/contracts.ts +0 -194
- package/src/core/output/display-value.ts +0 -48
- package/src/core/output/index.ts +0 -704
- package/src/core/output/renderers.ts +0 -125
- package/src/core/output/writer.ts +0 -46
- package/src/core/parse/index.ts +0 -681
- package/src/core/prompt/index.ts +0 -583
- package/src/core/resolve/args.ts +0 -144
- package/src/core/resolve/coerce.ts +0 -432
- package/src/core/resolve/config.ts +0 -26
- package/src/core/resolve/contracts.ts +0 -135
- package/src/core/resolve/errors.ts +0 -227
- package/src/core/resolve/flags.ts +0 -255
- package/src/core/resolve/index.ts +0 -108
- package/src/core/resolve/property.ts +0 -99
- package/src/core/schema/activity.ts +0 -240
- package/src/core/schema/arg.ts +0 -719
- package/src/core/schema/command.ts +0 -1498
- package/src/core/schema/flag.ts +0 -801
- package/src/core/schema/index.ts +0 -91
- package/src/core/schema/middleware.ts +0 -171
- package/src/core/schema/prompt.ts +0 -156
- package/src/core/schema/run.ts +0 -198
- package/src/core/schema-dsl/index.ts +0 -109
- package/src/core/schema-dsl/parse.ts +0 -262
- package/src/core/schema-dsl/runtime.ts +0 -609
- package/src/core/schema-dsl/to-json-schema.ts +0 -102
- package/src/core/testkit/index.ts +0 -123
- package/src/index.ts +0 -179
- package/src/runtime/adapter.ts +0 -303
- package/src/runtime/auto.ts +0 -110
- package/src/runtime/bun.ts +0 -55
- package/src/runtime/deno.ts +0 -369
- package/src/runtime/detect.ts +0 -105
- package/src/runtime/index.ts +0 -21
- package/src/runtime/node-builtins.d.ts +0 -27
- package/src/runtime/node.ts +0 -300
- package/src/runtime/paths.ts +0 -64
- package/src/runtime/support.ts +0 -135
- package/src/runtime.ts +0 -31
- package/src/strings.ts +0 -34
- package/src/testkit.ts +0 -25
- package/src/version.ts +0 -20
|
@@ -1,2 +1,358 @@
|
|
|
1
|
-
import{getFlagAliasNames
|
|
2
|
-
|
|
1
|
+
import { getFlagAliasNames, getFlagNegatedName } from "../../schema/flag.mjs";
|
|
2
|
+
import { flagExpectsValue } from "../../parse/index.mjs";
|
|
3
|
+
import { getVisibleNegatedName, resolveRootCompletionSurface, sanitizeShellIdentifier, versionTag, walkCommandTree } from "./shared.mjs";
|
|
4
|
+
//#region src/core/completion/shells/powershell.ts
|
|
5
|
+
/**
|
|
6
|
+
* Generate a PowerShell completion script for the CLI.
|
|
7
|
+
*
|
|
8
|
+
* @param schema - The CLI schema.
|
|
9
|
+
* @param options - Optional generator configuration.
|
|
10
|
+
* @returns A complete PowerShell completion script.
|
|
11
|
+
*/
|
|
12
|
+
function generatePowerShellCompletion(schema, options) {
|
|
13
|
+
const helperPrefix = `__${sanitizeShellIdentifier(options?.functionPrefix ?? schema.name)}_completions`;
|
|
14
|
+
const dataVarName = `${helperPrefix}_paths`;
|
|
15
|
+
const rootSurface = resolveRootCompletionSurface(schema, options?.rootMode);
|
|
16
|
+
const visibleCommands = rootSurface.visibleCommands;
|
|
17
|
+
const nodes = walkCommandTree(visibleCommands);
|
|
18
|
+
const lines = [];
|
|
19
|
+
lines.push(`# PowerShell completion for ${schema.name}`);
|
|
20
|
+
lines.push(`# Generated by ${versionTag()}`);
|
|
21
|
+
lines.push("#");
|
|
22
|
+
lines.push("# Install for the current session:");
|
|
23
|
+
lines.push(`# ${schema.name} completions powershell | Out-String | Invoke-Expression`);
|
|
24
|
+
lines.push("#");
|
|
25
|
+
lines.push("# Install permanently:");
|
|
26
|
+
lines.push(`# ${schema.name} completions powershell > $PROFILE.CurrentUserCurrentHost`);
|
|
27
|
+
lines.push("");
|
|
28
|
+
lines.push("using namespace System.Management.Automation");
|
|
29
|
+
lines.push("using namespace System.Management.Automation.Language");
|
|
30
|
+
lines.push("");
|
|
31
|
+
emitPowerShellPathTable(lines, dataVarName, rootSurface, nodes);
|
|
32
|
+
lines.push("");
|
|
33
|
+
emitPowerShellHelpers(lines, helperPrefix, dataVarName);
|
|
34
|
+
lines.push("");
|
|
35
|
+
lines.push(`Register-ArgumentCompleter -Native -CommandName ${quotePowerShellString(schema.name)} -ScriptBlock {`);
|
|
36
|
+
lines.push(" param($wordToComplete, $commandAst, $cursorPosition)");
|
|
37
|
+
lines.push(`\t$state = ${helperPrefix}_GetState -CommandAst $commandAst -CursorPosition $cursorPosition`);
|
|
38
|
+
lines.push(" if ($null -eq $state.PathData) {");
|
|
39
|
+
lines.push(" return");
|
|
40
|
+
lines.push(" }");
|
|
41
|
+
lines.push("");
|
|
42
|
+
lines.push(" $results = [System.Collections.Generic.List[CompletionResult]]::new()");
|
|
43
|
+
lines.push(" if ($state.AfterSeparator) {");
|
|
44
|
+
lines.push(" return $results");
|
|
45
|
+
lines.push(" }");
|
|
46
|
+
lines.push("");
|
|
47
|
+
lines.push(`\t$wordPrefix = if ([string]::IsNullOrEmpty($wordToComplete)) { '' } else { $wordToComplete }`);
|
|
48
|
+
lines.push("");
|
|
49
|
+
lines.push(" if ($state.ExpectingValue) {");
|
|
50
|
+
lines.push(`\t\t${helperPrefix}_AddEnumResults -Results $results -Flag $state.ValueFlag -WordToComplete $wordPrefix`);
|
|
51
|
+
lines.push(" return $results");
|
|
52
|
+
lines.push(" }");
|
|
53
|
+
lines.push("");
|
|
54
|
+
lines.push(`\t$inlineValue = ${helperPrefix}_ResolveInlineValueCompletion -PathData $state.PathData -WordToComplete $wordPrefix`);
|
|
55
|
+
lines.push(" if ($null -ne $inlineValue) {");
|
|
56
|
+
lines.push(`\t\t${helperPrefix}_AddInlineEnumResults -Results $results -InlineValue $inlineValue -WordToComplete $wordPrefix`);
|
|
57
|
+
lines.push(" return $results");
|
|
58
|
+
lines.push(" }");
|
|
59
|
+
lines.push("");
|
|
60
|
+
lines.push(" if ($wordPrefix.StartsWith('-')) {");
|
|
61
|
+
lines.push(`\t\t${helperPrefix}_AddFlagResults -Results $results -PathData $state.PathData -WordToComplete $wordPrefix`);
|
|
62
|
+
lines.push(" return $results");
|
|
63
|
+
lines.push(" }");
|
|
64
|
+
lines.push("");
|
|
65
|
+
lines.push(`\t${helperPrefix}_AddCommandResults -Results $results -PathData $state.PathData -WordToComplete $wordPrefix`);
|
|
66
|
+
lines.push(`\t${helperPrefix}_AddFlagResults -Results $results -PathData $state.PathData -WordToComplete $wordPrefix`);
|
|
67
|
+
lines.push(" return $results");
|
|
68
|
+
lines.push("}");
|
|
69
|
+
return lines.join("\n");
|
|
70
|
+
}
|
|
71
|
+
function emitPowerShellPathTable(lines, dataVarName, rootSurface, nodes) {
|
|
72
|
+
lines.push(`$script:${dataVarName} = @{`);
|
|
73
|
+
appendPowerShellPathEntry(lines, "", rootSurface.visibleCommands, {
|
|
74
|
+
...rootSurface.rootFlags,
|
|
75
|
+
...rootSurface.includeDefaultFlags ? rootSurface.defaultFlags : {}
|
|
76
|
+
});
|
|
77
|
+
for (const node of nodes) appendPowerShellPathEntry(lines, node.path.join(" "), node.children, node.mergedFlags);
|
|
78
|
+
lines.push("}");
|
|
79
|
+
}
|
|
80
|
+
function appendPowerShellPathEntry(lines, path, commands, flags) {
|
|
81
|
+
lines.push(`\t${quotePowerShellString(path)} = @{`);
|
|
82
|
+
lines.push(" Commands = @(");
|
|
83
|
+
for (const command of commands) {
|
|
84
|
+
lines.push(" @{");
|
|
85
|
+
lines.push(`\t\t\t\tCanonicalName = ${quotePowerShellString(command.name)}`);
|
|
86
|
+
lines.push(`\t\t\t\tNames = ${formatPowerShellArray([command.name, ...command.aliases])}`);
|
|
87
|
+
lines.push(`\t\t\t\tDescription = ${quotePowerShellString(command.description ?? command.name)}`);
|
|
88
|
+
lines.push(" }");
|
|
89
|
+
}
|
|
90
|
+
lines.push(" )");
|
|
91
|
+
lines.push(" Flags = @(");
|
|
92
|
+
for (const [name, schema] of Object.entries(flags)) {
|
|
93
|
+
const visibleNegated = getVisibleNegatedName(name, schema);
|
|
94
|
+
const parseNegated = getFlagNegatedName(name, schema);
|
|
95
|
+
const forms = dedupeValues([
|
|
96
|
+
`--${name}`,
|
|
97
|
+
...getFlagAliasNames(schema, { kind: "short" }).map((alias) => `-${alias}`),
|
|
98
|
+
...getFlagAliasNames(schema, { kind: "long" }).map((alias) => `--${alias}`),
|
|
99
|
+
...visibleNegated !== void 0 ? [`--${visibleNegated}`] : []
|
|
100
|
+
]);
|
|
101
|
+
const parseForms = dedupeValues([
|
|
102
|
+
`--${name}`,
|
|
103
|
+
...getFlagAliasNames(schema, {
|
|
104
|
+
kind: "short",
|
|
105
|
+
includeHidden: true
|
|
106
|
+
}).map((alias) => `-${alias}`),
|
|
107
|
+
...getFlagAliasNames(schema, {
|
|
108
|
+
kind: "long",
|
|
109
|
+
includeHidden: true
|
|
110
|
+
}).map((alias) => `--${alias}`),
|
|
111
|
+
...parseNegated !== void 0 ? [`--${parseNegated}`] : []
|
|
112
|
+
]);
|
|
113
|
+
lines.push(" @{");
|
|
114
|
+
lines.push(`\t\t\t\tCanonicalName = ${quotePowerShellString(name)}`);
|
|
115
|
+
lines.push(`\t\t\t\tForms = ${formatPowerShellArray(forms)}`);
|
|
116
|
+
lines.push(`\t\t\t\tParseForms = ${formatPowerShellArray(parseForms)}`);
|
|
117
|
+
lines.push(`\t\t\t\tRequiresValue = ${flagExpectsValue(schema) ? "$true" : "$false"}`);
|
|
118
|
+
lines.push(`\t\t\t\tDescription = ${quotePowerShellString(schema.description ?? name)}`);
|
|
119
|
+
lines.push(`\t\t\t\tEnumValues = ${formatPowerShellArray(schema.enumValues ?? [])}`);
|
|
120
|
+
lines.push(" }");
|
|
121
|
+
}
|
|
122
|
+
lines.push(" )");
|
|
123
|
+
lines.push(" }");
|
|
124
|
+
}
|
|
125
|
+
function emitPowerShellHelpers(lines, helperPrefix, dataVarName) {
|
|
126
|
+
lines.push(`function ${helperPrefix}_UnquoteToken {`);
|
|
127
|
+
lines.push(" param([string]$TokenText)");
|
|
128
|
+
lines.push(" if ($TokenText.Length -lt 2) {");
|
|
129
|
+
lines.push(" return $TokenText");
|
|
130
|
+
lines.push(" }");
|
|
131
|
+
lines.push("");
|
|
132
|
+
lines.push(" if (($TokenText.StartsWith(\"'\") -and $TokenText.EndsWith(\"'\")) -or");
|
|
133
|
+
lines.push(" ($TokenText.StartsWith('\"') -and $TokenText.EndsWith('\"'))) {");
|
|
134
|
+
lines.push(" return $TokenText.Substring(1, $TokenText.Length - 2)");
|
|
135
|
+
lines.push(" }");
|
|
136
|
+
lines.push("");
|
|
137
|
+
lines.push(" return $TokenText");
|
|
138
|
+
lines.push("}");
|
|
139
|
+
lines.push("");
|
|
140
|
+
lines.push(`function ${helperPrefix}_FindCommand {`);
|
|
141
|
+
lines.push(" param($PathData, [string]$Token)");
|
|
142
|
+
lines.push(" foreach ($command in $PathData.Commands) {");
|
|
143
|
+
lines.push(" foreach ($name in $command.Names) {");
|
|
144
|
+
lines.push(" if ($name -eq $Token) {");
|
|
145
|
+
lines.push(" return $command");
|
|
146
|
+
lines.push(" }");
|
|
147
|
+
lines.push(" }");
|
|
148
|
+
lines.push(" }");
|
|
149
|
+
lines.push(" return $null");
|
|
150
|
+
lines.push("}");
|
|
151
|
+
lines.push("");
|
|
152
|
+
lines.push(`function ${helperPrefix}_ResolveFlagToken {`);
|
|
153
|
+
lines.push(" param($PathData, [string]$Token)");
|
|
154
|
+
lines.push(" foreach ($flag in $PathData.Flags) {");
|
|
155
|
+
lines.push(" foreach ($form in $flag.ParseForms) {");
|
|
156
|
+
lines.push(" if ($Token -eq $form) {");
|
|
157
|
+
lines.push(" return @{ Flag = $flag; InlinePrefix = $null }");
|
|
158
|
+
lines.push(" }");
|
|
159
|
+
lines.push("");
|
|
160
|
+
lines.push(" if (-not $flag.RequiresValue) {");
|
|
161
|
+
lines.push(" continue");
|
|
162
|
+
lines.push(" }");
|
|
163
|
+
lines.push("");
|
|
164
|
+
lines.push(" if ($form.StartsWith('--') -and $Token.StartsWith(\"$form=\")) {");
|
|
165
|
+
lines.push(" return @{ Flag = $flag; InlinePrefix = \"$form=\" }");
|
|
166
|
+
lines.push(" }");
|
|
167
|
+
lines.push("");
|
|
168
|
+
lines.push(" if ($form.StartsWith('-') -and -not $form.StartsWith('--') -and $Token.StartsWith($form) -and $Token.Length -gt $form.Length) {");
|
|
169
|
+
lines.push(" return @{ Flag = $flag; InlinePrefix = $form }");
|
|
170
|
+
lines.push(" }");
|
|
171
|
+
lines.push(" }");
|
|
172
|
+
lines.push(" }");
|
|
173
|
+
lines.push(" return $null");
|
|
174
|
+
lines.push("}");
|
|
175
|
+
lines.push("");
|
|
176
|
+
lines.push(`function ${helperPrefix}_GetState {`);
|
|
177
|
+
lines.push(" param([CommandAst]$CommandAst, [int]$CursorPosition)");
|
|
178
|
+
lines.push(`\t$pathData = $script:${dataVarName}[${quotePowerShellString("")}]`);
|
|
179
|
+
lines.push(" $path = \"\"");
|
|
180
|
+
lines.push(" $afterSeparator = $false");
|
|
181
|
+
lines.push(" $expectingValue = $false");
|
|
182
|
+
lines.push(" $valueFlag = $null");
|
|
183
|
+
lines.push(" $tokens = [System.Collections.Generic.List[string]]::new()");
|
|
184
|
+
lines.push("");
|
|
185
|
+
lines.push(" foreach ($element in $CommandAst.CommandElements | Select-Object -Skip 1) {");
|
|
186
|
+
lines.push(" if ($element.Extent.EndOffset -ge $CursorPosition) {");
|
|
187
|
+
lines.push(" break");
|
|
188
|
+
lines.push(" }");
|
|
189
|
+
lines.push(`\t\t$tokenText = ${helperPrefix}_UnquoteToken $element.Extent.Text`);
|
|
190
|
+
lines.push(" [void]$tokens.Add($tokenText)");
|
|
191
|
+
lines.push(" }");
|
|
192
|
+
lines.push("");
|
|
193
|
+
lines.push(" foreach ($token in $tokens) {");
|
|
194
|
+
lines.push(" if ($expectingValue) {");
|
|
195
|
+
lines.push(" $expectingValue = $false");
|
|
196
|
+
lines.push(" $valueFlag = $null");
|
|
197
|
+
lines.push(" continue");
|
|
198
|
+
lines.push(" }");
|
|
199
|
+
lines.push("");
|
|
200
|
+
lines.push(" if ($token -eq '--') {");
|
|
201
|
+
lines.push(" $afterSeparator = $true");
|
|
202
|
+
lines.push(" break");
|
|
203
|
+
lines.push(" }");
|
|
204
|
+
lines.push("");
|
|
205
|
+
lines.push(`\t\t$flagMatch = ${helperPrefix}_ResolveFlagToken -PathData $pathData -Token $token`);
|
|
206
|
+
lines.push(" if ($null -ne $flagMatch) {");
|
|
207
|
+
lines.push(" if ($flagMatch.InlinePrefix -eq $null -and $flagMatch.Flag.RequiresValue) {");
|
|
208
|
+
lines.push(" $expectingValue = $true");
|
|
209
|
+
lines.push(" $valueFlag = $flagMatch.Flag");
|
|
210
|
+
lines.push(" }");
|
|
211
|
+
lines.push(" continue");
|
|
212
|
+
lines.push(" }");
|
|
213
|
+
lines.push("");
|
|
214
|
+
lines.push(" if ($token.StartsWith('-')) {");
|
|
215
|
+
lines.push(" continue");
|
|
216
|
+
lines.push(" }");
|
|
217
|
+
lines.push("");
|
|
218
|
+
lines.push(`\t\t$command = ${helperPrefix}_FindCommand -PathData $pathData -Token $token`);
|
|
219
|
+
lines.push(" if ($null -eq $command) {");
|
|
220
|
+
lines.push(" break");
|
|
221
|
+
lines.push(" }");
|
|
222
|
+
lines.push("");
|
|
223
|
+
lines.push(" $path = if ([string]::IsNullOrEmpty($path)) {");
|
|
224
|
+
lines.push(" $command.CanonicalName");
|
|
225
|
+
lines.push(" } else {");
|
|
226
|
+
lines.push(" \"$path $($command.CanonicalName)\"");
|
|
227
|
+
lines.push(" }");
|
|
228
|
+
lines.push(`\t\t$nextPathData = $script:${dataVarName}[$path]`);
|
|
229
|
+
lines.push(" if ($null -eq $nextPathData) {");
|
|
230
|
+
lines.push(" break");
|
|
231
|
+
lines.push(" }");
|
|
232
|
+
lines.push(" $pathData = $nextPathData");
|
|
233
|
+
lines.push(" }");
|
|
234
|
+
lines.push("");
|
|
235
|
+
lines.push(" return @{");
|
|
236
|
+
lines.push(" Path = $path");
|
|
237
|
+
lines.push(" PathData = $pathData");
|
|
238
|
+
lines.push(" AfterSeparator = $afterSeparator");
|
|
239
|
+
lines.push(" ExpectingValue = $expectingValue");
|
|
240
|
+
lines.push(" ValueFlag = $valueFlag");
|
|
241
|
+
lines.push(" }");
|
|
242
|
+
lines.push("}");
|
|
243
|
+
lines.push("");
|
|
244
|
+
lines.push(`function ${helperPrefix}_ResolveInlineValueCompletion {`);
|
|
245
|
+
lines.push(" param($PathData, [string]$WordToComplete)");
|
|
246
|
+
lines.push(`\t$flagMatch = ${helperPrefix}_ResolveFlagToken -PathData $PathData -Token $WordToComplete`);
|
|
247
|
+
lines.push(" if ($null -eq $flagMatch -or $flagMatch.InlinePrefix -eq $null) {");
|
|
248
|
+
lines.push(" return $null");
|
|
249
|
+
lines.push(" }");
|
|
250
|
+
lines.push(" return $flagMatch");
|
|
251
|
+
lines.push("}");
|
|
252
|
+
lines.push("");
|
|
253
|
+
lines.push(`function ${helperPrefix}_FormatCompletionValue {`);
|
|
254
|
+
lines.push(" param([string]$Value)");
|
|
255
|
+
lines.push(" if ($Value.Length -eq 0) {");
|
|
256
|
+
lines.push(" return \"''\"");
|
|
257
|
+
lines.push(" }");
|
|
258
|
+
lines.push("");
|
|
259
|
+
lines.push(" if ($Value -match '^[a-zA-Z0-9_./:\\\\-]+$') {");
|
|
260
|
+
lines.push(" return $Value");
|
|
261
|
+
lines.push(" }");
|
|
262
|
+
lines.push("");
|
|
263
|
+
lines.push(" return \"'$([CodeGeneration]::EscapeSingleQuotedStringContent($Value))'\"");
|
|
264
|
+
lines.push("}");
|
|
265
|
+
lines.push("");
|
|
266
|
+
lines.push(`function ${helperPrefix}_MatchesCompletionPrefix {`);
|
|
267
|
+
lines.push(" param([string]$WordToComplete, [string]$RawText, [string]$CompletionText)");
|
|
268
|
+
lines.push(" if ([string]::IsNullOrEmpty($WordToComplete)) {");
|
|
269
|
+
lines.push(" return $true");
|
|
270
|
+
lines.push(" }");
|
|
271
|
+
lines.push("");
|
|
272
|
+
lines.push(" return $RawText.StartsWith($WordToComplete, [System.StringComparison]::OrdinalIgnoreCase) -or $CompletionText.StartsWith($WordToComplete, [System.StringComparison]::OrdinalIgnoreCase)");
|
|
273
|
+
lines.push("}");
|
|
274
|
+
lines.push("");
|
|
275
|
+
lines.push(`function ${helperPrefix}_AddCommandResults {`);
|
|
276
|
+
lines.push(" param($Results, $PathData, [string]$WordToComplete)");
|
|
277
|
+
lines.push(" foreach ($command in $PathData.Commands) {");
|
|
278
|
+
lines.push(" foreach ($name in $command.Names) {");
|
|
279
|
+
lines.push(" if (-not [string]::IsNullOrEmpty($WordToComplete) -and -not $name.StartsWith($WordToComplete, [System.StringComparison]::OrdinalIgnoreCase)) {");
|
|
280
|
+
lines.push(" continue");
|
|
281
|
+
lines.push(" }");
|
|
282
|
+
lines.push("");
|
|
283
|
+
lines.push(" $Results.Add([CompletionResult]::new(");
|
|
284
|
+
lines.push(" $name,");
|
|
285
|
+
lines.push(" $name,");
|
|
286
|
+
lines.push(" [CompletionResultType]::Command,");
|
|
287
|
+
lines.push(" $command.Description");
|
|
288
|
+
lines.push(" ))");
|
|
289
|
+
lines.push(" }");
|
|
290
|
+
lines.push(" }");
|
|
291
|
+
lines.push("}");
|
|
292
|
+
lines.push("");
|
|
293
|
+
lines.push(`function ${helperPrefix}_AddFlagResults {`);
|
|
294
|
+
lines.push(" param($Results, $PathData, [string]$WordToComplete)");
|
|
295
|
+
lines.push(" foreach ($flag in $PathData.Flags) {");
|
|
296
|
+
lines.push(" foreach ($form in $flag.Forms) {");
|
|
297
|
+
lines.push(" if (-not [string]::IsNullOrEmpty($WordToComplete) -and -not $form.StartsWith($WordToComplete, [System.StringComparison]::OrdinalIgnoreCase)) {");
|
|
298
|
+
lines.push(" continue");
|
|
299
|
+
lines.push(" }");
|
|
300
|
+
lines.push("");
|
|
301
|
+
lines.push(" $Results.Add([CompletionResult]::new(");
|
|
302
|
+
lines.push(" $form,");
|
|
303
|
+
lines.push(" $form,");
|
|
304
|
+
lines.push(" [CompletionResultType]::ParameterName,");
|
|
305
|
+
lines.push(" $flag.Description");
|
|
306
|
+
lines.push(" ))");
|
|
307
|
+
lines.push(" }");
|
|
308
|
+
lines.push(" }");
|
|
309
|
+
lines.push("}");
|
|
310
|
+
lines.push("");
|
|
311
|
+
lines.push(`function ${helperPrefix}_AddEnumResults {`);
|
|
312
|
+
lines.push(" param($Results, $Flag, [string]$WordToComplete)");
|
|
313
|
+
lines.push(" foreach ($value in $Flag.EnumValues) {");
|
|
314
|
+
lines.push(`\t\t$completionText = ${helperPrefix}_FormatCompletionValue -Value $value`);
|
|
315
|
+
lines.push(`\t\tif (-not (${helperPrefix}_MatchesCompletionPrefix -WordToComplete $WordToComplete -RawText $value -CompletionText $completionText)) {`);
|
|
316
|
+
lines.push(" continue");
|
|
317
|
+
lines.push(" }");
|
|
318
|
+
lines.push("");
|
|
319
|
+
lines.push(" $Results.Add([CompletionResult]::new(");
|
|
320
|
+
lines.push(" $completionText,");
|
|
321
|
+
lines.push(" $value,");
|
|
322
|
+
lines.push(" [CompletionResultType]::ParameterValue,");
|
|
323
|
+
lines.push(" $Flag.Description");
|
|
324
|
+
lines.push(" ))");
|
|
325
|
+
lines.push(" }");
|
|
326
|
+
lines.push("}");
|
|
327
|
+
lines.push("");
|
|
328
|
+
lines.push(`function ${helperPrefix}_AddInlineEnumResults {`);
|
|
329
|
+
lines.push(" param($Results, $InlineValue, [string]$WordToComplete)");
|
|
330
|
+
lines.push(" foreach ($value in $InlineValue.Flag.EnumValues) {");
|
|
331
|
+
lines.push(" $rawCompletion = \"$($InlineValue.InlinePrefix)$value\"");
|
|
332
|
+
lines.push(`\t\t$formattedValue = ${helperPrefix}_FormatCompletionValue -Value $value`);
|
|
333
|
+
lines.push(" $completionText = \"$($InlineValue.InlinePrefix)$formattedValue\"");
|
|
334
|
+
lines.push(`\t\tif (-not (${helperPrefix}_MatchesCompletionPrefix -WordToComplete $WordToComplete -RawText $rawCompletion -CompletionText $completionText)) {`);
|
|
335
|
+
lines.push(" continue");
|
|
336
|
+
lines.push(" }");
|
|
337
|
+
lines.push("");
|
|
338
|
+
lines.push(" $Results.Add([CompletionResult]::new(");
|
|
339
|
+
lines.push(" $completionText,");
|
|
340
|
+
lines.push(" $value,");
|
|
341
|
+
lines.push(" [CompletionResultType]::ParameterValue,");
|
|
342
|
+
lines.push(" $InlineValue.Flag.Description");
|
|
343
|
+
lines.push(" ))");
|
|
344
|
+
lines.push(" }");
|
|
345
|
+
lines.push("}");
|
|
346
|
+
}
|
|
347
|
+
function quotePowerShellString(value) {
|
|
348
|
+
return `'${value.replace(/'/g, "''")}'`;
|
|
349
|
+
}
|
|
350
|
+
function formatPowerShellArray(values) {
|
|
351
|
+
if (values.length === 0) return "@()";
|
|
352
|
+
return `@(${values.map(quotePowerShellString).join(", ")})`;
|
|
353
|
+
}
|
|
354
|
+
function dedupeValues(values) {
|
|
355
|
+
return [...new Set(values)];
|
|
356
|
+
}
|
|
357
|
+
//#endregion
|
|
358
|
+
export { generatePowerShellCompletion };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FlagSchema } from "../../schema/flag.mjs";
|
|
2
2
|
import { CommandSchema } from "../../schema/command.mjs";
|
|
3
|
-
|
|
3
|
+
import "../../schema/index.mjs";
|
|
4
4
|
//#region src/core/completion/shells/shared.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* Format a version tag for generated completion script headers.
|
|
@@ -33,6 +33,16 @@ interface CompletionOptions {
|
|
|
33
33
|
* ```
|
|
34
34
|
*/
|
|
35
35
|
readonly functionPrefix?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Where the built-in shell completion is exposed.
|
|
38
|
+
*
|
|
39
|
+
* - `'command'` registers a `completions` subcommand (the default).
|
|
40
|
+
* - `'flag'` exposes an eager `--completions <shell>` flag on the CLI root
|
|
41
|
+
* instead, keeping the root free of a `completions` subcommand.
|
|
42
|
+
*
|
|
43
|
+
* @defaultValue `'command'`
|
|
44
|
+
*/
|
|
45
|
+
readonly as?: 'command' | 'flag';
|
|
36
46
|
/**
|
|
37
47
|
* Controls which root-level surface shell completion exposes when a
|
|
38
48
|
* default command exists.
|
|
@@ -110,6 +120,17 @@ interface CommandNode {
|
|
|
110
120
|
* @internal
|
|
111
121
|
*/
|
|
112
122
|
declare function walkCommandTree(topLevel: readonly CommandSchema[], ancestorSchemas?: readonly CommandSchema[]): readonly CommandNode[];
|
|
123
|
+
/**
|
|
124
|
+
* Effective negated long-form spelling for user-facing suggestion lists.
|
|
125
|
+
*
|
|
126
|
+
* Returns the negated spelling without the `--` prefix (e.g. `no-verbose`)
|
|
127
|
+
* when the flag is negatable and the negation is not hidden; `undefined`
|
|
128
|
+
* otherwise. Negated spellings are long-only and take no value, so they only
|
|
129
|
+
* belong in suggestion lists — never in value-flag (operand-skip) patterns.
|
|
130
|
+
*
|
|
131
|
+
* @internal
|
|
132
|
+
*/
|
|
133
|
+
declare function getVisibleNegatedName(name: string, schema: FlagSchema): string | undefined;
|
|
113
134
|
/**
|
|
114
135
|
* Sanitize a string for use as a shell function identifier.
|
|
115
136
|
* Replaces non-alphanumeric/underscore characters with underscores.
|
|
@@ -136,4 +157,4 @@ declare function sanitizeShellIdentifier(name: string): string;
|
|
|
136
157
|
*/
|
|
137
158
|
declare function quoteShellArg(value: string): string;
|
|
138
159
|
//#endregion
|
|
139
|
-
export { type CommandNode, type CompletionOptions, type RootCompletionSurface, quoteShellArg, resolveRootCompletionSurface, sanitizeShellIdentifier, versionTag, walkCommandTree };
|
|
160
|
+
export { type CommandNode, type CompletionOptions, type RootCompletionSurface, getVisibleNegatedName, quoteShellArg, resolveRootCompletionSurface, sanitizeShellIdentifier, versionTag, walkCommandTree };
|
|
@@ -1 +1,176 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { getFlagNegatedName } from "../../schema/flag.mjs";
|
|
2
|
+
import { collectPropagatedFlags } from "../../cli/propagate.mjs";
|
|
3
|
+
import { resolveRootSurface } from "../../cli/root-surface.mjs";
|
|
4
|
+
import { DREAMCLI_REVISION, DREAMCLI_VERSION } from "../../../version.mjs";
|
|
5
|
+
//#region src/core/completion/shells/shared.ts
|
|
6
|
+
/**
|
|
7
|
+
* Shared infrastructure for shell completion generators.
|
|
8
|
+
*
|
|
9
|
+
* Provides the command tree walker, shell escaping utilities, and
|
|
10
|
+
* the version tag used in generated script headers. Consumed by
|
|
11
|
+
* the per-shell generators in sibling files.
|
|
12
|
+
*
|
|
13
|
+
* @module dreamcli/core/completion/shells/shared
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Format a version tag for generated completion script headers.
|
|
18
|
+
*
|
|
19
|
+
* Produces e.g. `"@kjanat/dreamcli v0.9.1 (f9b5f1a)"` when built, or
|
|
20
|
+
* `"@kjanat/dreamcli"` when running unbundled in development.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
function versionTag() {
|
|
25
|
+
return `@kjanat/dreamcli v${DREAMCLI_VERSION}${` (${DREAMCLI_REVISION})`}`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Resolve the root-level completion surface from the CLI schema and policy.
|
|
29
|
+
*
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
function resolveRootCompletionSurface(schema, rootMode = "subcommands") {
|
|
33
|
+
const rootSurface = resolveRootSurface(schema);
|
|
34
|
+
const rootFlags = createRootFlags(schema.version !== void 0);
|
|
35
|
+
const defaultFlags = rootSurface.visibleDefaultCommand?.flags ?? {};
|
|
36
|
+
const includeDefaultFlags = rootMode === "surface" ? rootSurface.hasVisibleDefault : rootSurface.hasVisibleDefault && !rootSurface.hasVisibleSubcommands;
|
|
37
|
+
const defaultCommand = rootSurface.visibleDefaultCommand;
|
|
38
|
+
const alreadyListed = defaultCommand !== void 0 && rootSurface.visibleCommands.some((c) => c.name === defaultCommand.name);
|
|
39
|
+
return {
|
|
40
|
+
visibleCommands: defaultCommand !== void 0 && !alreadyListed ? [defaultCommand, ...rootSurface.visibleCommands] : rootSurface.visibleCommands,
|
|
41
|
+
visibleDefaultCommand: rootSurface.visibleDefaultCommand,
|
|
42
|
+
rootFlags,
|
|
43
|
+
defaultFlags,
|
|
44
|
+
includeDefaultFlags
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Build the synthetic root-level flags (`--help`, optionally `--version`).
|
|
49
|
+
*
|
|
50
|
+
* @param hasVersion - Whether to include a `--version` flag.
|
|
51
|
+
* @returns A record of root flag schemas.
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
function createRootFlags(hasVersion) {
|
|
55
|
+
return {
|
|
56
|
+
help: createSyntheticRootFlag("Show help text"),
|
|
57
|
+
...hasVersion ? { version: createSyntheticRootFlag("Show version") } : {}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Create a minimal boolean {@link FlagSchema} for a synthetic root flag.
|
|
62
|
+
*
|
|
63
|
+
* @param description - Help text for the flag.
|
|
64
|
+
* @returns A complete flag schema with all optional fields defaulted.
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
function createSyntheticRootFlag(description) {
|
|
68
|
+
return {
|
|
69
|
+
kind: "boolean",
|
|
70
|
+
presence: "optional",
|
|
71
|
+
defaultValue: void 0,
|
|
72
|
+
aliases: [],
|
|
73
|
+
envVar: void 0,
|
|
74
|
+
configPath: void 0,
|
|
75
|
+
description,
|
|
76
|
+
enumValues: void 0,
|
|
77
|
+
numberConstraints: void 0,
|
|
78
|
+
stringConstraints: void 0,
|
|
79
|
+
elementSchema: void 0,
|
|
80
|
+
separator: void 0,
|
|
81
|
+
unique: false,
|
|
82
|
+
pathChecks: void 0,
|
|
83
|
+
valueHint: void 0,
|
|
84
|
+
prompt: void 0,
|
|
85
|
+
parseFn: void 0,
|
|
86
|
+
deprecated: void 0,
|
|
87
|
+
propagate: false,
|
|
88
|
+
negation: void 0,
|
|
89
|
+
duplicates: "last"
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Walk the command tree depth-first, producing a flat list of
|
|
94
|
+
* {@link CommandNode}s with propagated flag context.
|
|
95
|
+
*
|
|
96
|
+
* @param topLevel - Top-level visible command schemas.
|
|
97
|
+
* @param ancestorSchemas - Schema path from root (for propagation calculation).
|
|
98
|
+
* @returns Flat list of all visible nodes in the tree.
|
|
99
|
+
*
|
|
100
|
+
* @internal
|
|
101
|
+
*/
|
|
102
|
+
function walkCommandTree(topLevel, ancestorSchemas = []) {
|
|
103
|
+
const nodes = [];
|
|
104
|
+
for (const schema of topLevel) {
|
|
105
|
+
if (schema.hidden) continue;
|
|
106
|
+
const fullPath = [...ancestorSchemas, schema];
|
|
107
|
+
const propagatedFlags = collectPropagatedFlags(fullPath);
|
|
108
|
+
const mergedFlags = {
|
|
109
|
+
...propagatedFlags,
|
|
110
|
+
...schema.flags
|
|
111
|
+
};
|
|
112
|
+
const children = schema.commands.filter((c) => !c.hidden);
|
|
113
|
+
nodes.push({
|
|
114
|
+
path: fullPath.map((s) => s.name),
|
|
115
|
+
schema,
|
|
116
|
+
propagatedFlags,
|
|
117
|
+
mergedFlags,
|
|
118
|
+
children
|
|
119
|
+
});
|
|
120
|
+
if (children.length > 0) nodes.push(...walkCommandTree(children, fullPath));
|
|
121
|
+
}
|
|
122
|
+
return nodes;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Effective negated long-form spelling for user-facing suggestion lists.
|
|
126
|
+
*
|
|
127
|
+
* Returns the negated spelling without the `--` prefix (e.g. `no-verbose`)
|
|
128
|
+
* when the flag is negatable and the negation is not hidden; `undefined`
|
|
129
|
+
* otherwise. Negated spellings are long-only and take no value, so they only
|
|
130
|
+
* belong in suggestion lists — never in value-flag (operand-skip) patterns.
|
|
131
|
+
*
|
|
132
|
+
* @internal
|
|
133
|
+
*/
|
|
134
|
+
function getVisibleNegatedName(name, schema) {
|
|
135
|
+
if (schema.negation === void 0 || schema.negation.hidden) return void 0;
|
|
136
|
+
return getFlagNegatedName(name, schema);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Sanitize a string for use as a shell function identifier.
|
|
140
|
+
* Replaces non-alphanumeric/underscore characters with underscores.
|
|
141
|
+
* When sanitization changes the name, appends a short stable hash suffix so
|
|
142
|
+
* distinct originals cannot collide on the same helper identifier.
|
|
143
|
+
* Used by both bash and zsh generators.
|
|
144
|
+
*
|
|
145
|
+
* @internal
|
|
146
|
+
*/
|
|
147
|
+
function sanitizeShellIdentifier(name) {
|
|
148
|
+
const sanitized = name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
149
|
+
if (sanitized === name) return sanitized;
|
|
150
|
+
let hash = 2166136261;
|
|
151
|
+
for (let i = 0; i < name.length; i += 1) {
|
|
152
|
+
hash ^= name.charCodeAt(i);
|
|
153
|
+
hash = Math.imul(hash, 16777619);
|
|
154
|
+
}
|
|
155
|
+
return `${sanitized}_${(hash >>> 0).toString(16).padStart(8, "0")}`;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Quote a string for safe interpolation into a shell script.
|
|
159
|
+
*
|
|
160
|
+
* Uses single-quote wrapping with the standard `'\''` idiom for
|
|
161
|
+
* embedded single quotes. This prevents shell injection from CLI
|
|
162
|
+
* names containing spaces, semicolons, backticks, or other
|
|
163
|
+
* special characters.
|
|
164
|
+
*
|
|
165
|
+
* Returns the input unquoted if it consists only of shell-safe
|
|
166
|
+
* characters (`[a-zA-Z0-9_\-.]`), avoiding unnecessary noise
|
|
167
|
+
* in generated scripts for common CLI names like `my-cli` or `app.v2`.
|
|
168
|
+
*
|
|
169
|
+
* @internal
|
|
170
|
+
*/
|
|
171
|
+
function quoteShellArg(value) {
|
|
172
|
+
if (/^[a-zA-Z0-9_\-.]+$/.test(value)) return value;
|
|
173
|
+
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
174
|
+
}
|
|
175
|
+
//#endregion
|
|
176
|
+
export { getVisibleNegatedName, quoteShellArg, resolveRootCompletionSurface, sanitizeShellIdentifier, versionTag, walkCommandTree };
|