@hop-top/kit 0.5.0-alpha.6 → 0.5.0-alpha.8
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 +52 -0
- package/LICENSE-cobra.txt +174 -0
- package/NOTICE +15 -0
- package/README.md +3 -3
- package/dist/alias-D9_qFlyP.d.ts +174 -0
- package/dist/alias.d.ts +1 -1
- package/dist/alias.js +10 -2
- package/dist/chunk-263IZ6Z6.js +915 -0
- package/dist/{chunk-S45UHXQF.js → chunk-BLS2OBIQ.js} +106 -25
- package/dist/{chunk-7FDIN5KE.js → chunk-GHPJJV5L.js} +8 -4
- package/dist/chunk-JKMQSAJP.js +174 -0
- package/dist/chunk-JZ22ZUFA.js +1131 -0
- package/dist/{chunk-GAZPYCQD.js → chunk-NLMS7HGP.js} +93 -35
- package/dist/chunk-QQQYCWSC.js +240 -0
- package/dist/chunk-XJTRY453.js +868 -0
- package/dist/cli.js +6 -4
- package/dist/completion-csVun6SP.d.ts +112 -0
- package/dist/completion-values-By-mnjNt.d.ts +142 -0
- package/dist/completion-values.d.ts +1 -0
- package/dist/completion-values.js +29 -0
- package/dist/completion.d.ts +2 -1
- package/dist/completion.js +23 -2
- package/dist/compliance-AxFf-uMy.d.ts +60 -0
- package/dist/compliance.d.ts +1 -0
- package/dist/compliance.js +17 -0
- package/dist/config-CaK60ByQ.d.ts +241 -0
- package/dist/config.d.ts +1 -1
- package/dist/config.js +4 -2
- package/dist/index.d.ts +7 -5
- package/dist/index.js +26 -18
- package/dist/log-CkaxMX3U.d.ts +115 -0
- package/dist/log.d.ts +1 -1
- package/dist/log.js +2 -2
- package/dist/toolspec-UrWnoJ3Y.d.ts +336 -0
- package/dist/toolspec.d.ts +2 -1
- package/dist/toolspec.js +27 -2
- package/package.json +19 -3
- package/src/alias.conformance.test.ts +250 -0
- package/src/alias.test.ts +206 -2
- package/src/alias.ts +196 -21
- package/src/cli.ts +5 -0
- package/src/completion-scripts.ts +16 -0
- package/src/completion-values.test.ts +70 -10
- package/src/completion-values.ts +170 -66
- package/src/completion.conformance.test.ts +297 -0
- package/src/completion.test.ts +256 -145
- package/src/completion.ts +767 -121
- package/src/config-merge.test.ts +425 -0
- package/src/config.test.ts +41 -0
- package/src/config.ts +265 -18
- package/src/index.test.ts +2 -1
- package/src/index.ts +5 -1
- package/src/log.test.ts +270 -1
- package/src/log.ts +172 -44
- package/src/published-types.test.ts +18 -0
- package/src/toolspec-internal.ts +197 -0
- package/src/toolspec-manifest.test.ts +82 -0
- package/src/toolspec-manifest.ts +404 -0
- package/src/toolspec-spec-schemas.ts +12 -0
- package/src/toolspec-spec.test.ts +273 -0
- package/src/toolspec-spec.ts +458 -0
- package/src/toolspec.from-command.test.ts +216 -0
- package/src/toolspec.ts +159 -0
- package/test/toolspec/fixture.ts +73 -0
- package/dist/alias-BOj0-VAr.d.ts +0 -88
- package/dist/chunk-6RFRV4VP.js +0 -128
- package/dist/chunk-IQXEISMC.js +0 -142
- package/dist/chunk-W7ERKNSQ.js +0 -171
- package/dist/completion-CVnPcWMZ.d.ts +0 -32
- package/dist/config-Bm9fBXch.d.ts +0 -134
- package/dist/log-uKjHsK-c.d.ts +0 -62
- package/dist/toolspec-DPBr18Ub.d.ts +0 -106
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
+
var _chunkJZ22ZUFAjs = require('./chunk-JZ22ZUFA.js');
|
|
4
|
+
|
|
5
|
+
|
|
3
6
|
var _chunkR5U7XKVJjs = require('./chunk-R5U7XKVJ.js');
|
|
4
7
|
|
|
5
8
|
// src/alias.ts
|
|
6
9
|
var alias_exports = {};
|
|
7
10
|
_chunkR5U7XKVJjs.__export.call(void 0, alias_exports, {
|
|
11
|
+
AliasNameError: () => AliasNameError,
|
|
8
12
|
AliasStore: () => AliasStore,
|
|
9
13
|
Expander: () => Expander,
|
|
10
14
|
bridgeAliases: () => bridgeAliases,
|
|
15
|
+
detectCycles: () => detectCycles,
|
|
11
16
|
findCommand: () => findCommand,
|
|
12
17
|
findFirstNonFlag: () => findFirstNonFlag,
|
|
13
18
|
loadFrom: () => loadFrom,
|
|
14
|
-
saveTo: () => saveTo
|
|
19
|
+
saveTo: () => saveTo,
|
|
20
|
+
validateAliasName: () => validateAliasName
|
|
15
21
|
});
|
|
16
22
|
var _fs = require('fs'); var fs = _interopRequireWildcard(_fs);
|
|
17
23
|
var _path = require('path'); var path = _interopRequireWildcard(_path);
|
|
@@ -122,51 +128,123 @@ var Expander = class {
|
|
|
122
128
|
const result = [args[0], ...prefix, ...parts, ...suffix];
|
|
123
129
|
return [result, true];
|
|
124
130
|
}
|
|
125
|
-
/**
|
|
131
|
+
/**
|
|
132
|
+
* Reject names that shadow builtins or contain whitespace; see
|
|
133
|
+
* {@link validateAliasName}, which needs no config files.
|
|
134
|
+
*/
|
|
126
135
|
validateName(name) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
136
|
+
validateAliasName(name, { builtins: this.cfg.builtins });
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
var AliasNameError = class extends Error {
|
|
140
|
+
constructor(kind, alias, target) {
|
|
141
|
+
super(aliasNameMessage(kind, alias, target));
|
|
142
|
+
this.name = "AliasNameError";
|
|
143
|
+
this.kind = kind;
|
|
144
|
+
this.alias = alias;
|
|
145
|
+
this.target = target;
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
function aliasNameMessage(kind, alias, target) {
|
|
149
|
+
switch (kind) {
|
|
150
|
+
case "empty":
|
|
151
|
+
return "alias name must not be empty";
|
|
152
|
+
case "whitespace":
|
|
153
|
+
return "alias name must not contain whitespace";
|
|
154
|
+
case "builtin":
|
|
155
|
+
return `alias "${alias}" conflicts with a built-in command`;
|
|
156
|
+
case "duplicate":
|
|
157
|
+
return `alias "${alias}" is already registered for "${_nullishCoalesce(target, () => ( ""))}"`;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
var WHITE_SPACE = /\p{White_Space}/u;
|
|
161
|
+
function validateAliasName(name, rules = {}) {
|
|
162
|
+
if (name === "") throw new AliasNameError("empty", name);
|
|
163
|
+
if (WHITE_SPACE.test(name)) throw new AliasNameError("whitespace", name);
|
|
164
|
+
if (rules.builtins) {
|
|
165
|
+
for (const b of rules.builtins) {
|
|
166
|
+
if (b === name) throw new AliasNameError("builtin", name);
|
|
132
167
|
}
|
|
133
|
-
|
|
134
|
-
|
|
168
|
+
}
|
|
169
|
+
const existing = rules.existing;
|
|
170
|
+
if (existing && Object.prototype.hasOwnProperty.call(existing, name)) {
|
|
171
|
+
throw new AliasNameError("duplicate", name, existing[name]);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function detectCycles(aliases) {
|
|
175
|
+
const has = (n) => Object.prototype.hasOwnProperty.call(aliases, n);
|
|
176
|
+
const next = (n) => {
|
|
177
|
+
const first = aliases[n].trim().split(/\s+/)[0];
|
|
178
|
+
return first !== "" && has(first) ? first : void 0;
|
|
179
|
+
};
|
|
180
|
+
const cmp = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
181
|
+
const done = /* @__PURE__ */ new Set();
|
|
182
|
+
const cycles = [];
|
|
183
|
+
for (const start of Object.keys(aliases).sort(cmp)) {
|
|
184
|
+
if (done.has(start)) continue;
|
|
185
|
+
const pos = /* @__PURE__ */ new Map();
|
|
186
|
+
const walk = [];
|
|
187
|
+
let cur = start;
|
|
188
|
+
while (cur !== void 0 && !done.has(cur)) {
|
|
189
|
+
const at = pos.get(cur);
|
|
190
|
+
if (at !== void 0) {
|
|
191
|
+
const members = walk.slice(at);
|
|
192
|
+
let min = 0;
|
|
193
|
+
members.forEach((m, i) => {
|
|
194
|
+
if (m < members[min]) min = i;
|
|
195
|
+
});
|
|
196
|
+
const path2 = [...members.slice(min), ...members.slice(0, min)];
|
|
197
|
+
cycles.push([...path2, path2[0]]);
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
pos.set(cur, walk.length);
|
|
201
|
+
walk.push(cur);
|
|
202
|
+
cur = next(cur);
|
|
135
203
|
}
|
|
204
|
+
for (const n of walk) done.add(n);
|
|
136
205
|
}
|
|
137
|
-
|
|
206
|
+
return cycles.sort((a, b) => cmp(a[0], b[0]));
|
|
207
|
+
}
|
|
138
208
|
function findCommand(program, cmdPath) {
|
|
139
209
|
const parts = cmdPath.split(" ");
|
|
140
210
|
let cmd = program;
|
|
141
211
|
for (const part of parts) {
|
|
142
|
-
cmd = _optionalChain([cmd, 'optionalAccess',
|
|
212
|
+
cmd = _optionalChain([cmd, 'optionalAccess', _ => _.commands, 'access', _2 => _2.find, 'call', _3 => _3((c) => c.name() === part)]);
|
|
143
213
|
if (!cmd) return void 0;
|
|
144
214
|
}
|
|
145
215
|
return cmd;
|
|
146
216
|
}
|
|
147
|
-
function
|
|
148
|
-
|
|
217
|
+
function hasBridgeOptions(opts) {
|
|
218
|
+
return opts !== void 0 && Object.values(opts).some((v) => v !== void 0);
|
|
219
|
+
}
|
|
220
|
+
function bridgeAliases(program, source, opts) {
|
|
221
|
+
const all = typeof source.all === "function" ? source.all() : { ...source };
|
|
222
|
+
const proxyAll = hasBridgeOptions(opts);
|
|
223
|
+
const realProxy = proxyAll && (opts.hidden === false || typeof opts.dispatch === "function");
|
|
149
224
|
for (const [name, target] of Object.entries(all)) {
|
|
225
|
+
if (!realProxy) _chunkJZ22ZUFAjs.registerRootAlias.call(void 0, program, name, target);
|
|
150
226
|
const parts = target.split(/\s+/);
|
|
151
|
-
if (parts.length === 1) {
|
|
227
|
+
if (!proxyAll && parts.length === 1) {
|
|
152
228
|
const targetCmd = findCommand(program, target);
|
|
153
229
|
if (targetCmd) {
|
|
154
230
|
targetCmd.alias(name);
|
|
155
231
|
continue;
|
|
156
232
|
}
|
|
157
233
|
}
|
|
158
|
-
const
|
|
234
|
+
const dispatch = _optionalChain([opts, 'optionalAccess', _4 => _4.dispatch]);
|
|
235
|
+
const proxy = new (0, _commander.Command)(name);
|
|
236
|
+
if (proxyAll) proxy.copyInheritedSettings(program);
|
|
237
|
+
proxy.description(_nullishCoalesce(_optionalChain([opts, 'optionalAccess', _5 => _5.describe, 'optionalCall', _6 => _6(name, target)]), () => ( `Alias for ${target}`))).allowUnknownOption(true).allowExcessArguments(true).action(function() {
|
|
238
|
+
if (dispatch === false) return void 0;
|
|
239
|
+
if (dispatch) return dispatch(name, target, this);
|
|
159
240
|
const expanded = target.split(/\s+/);
|
|
160
|
-
program.
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
...this.args
|
|
165
|
-
]);
|
|
241
|
+
return program._parseCommand(
|
|
242
|
+
[],
|
|
243
|
+
[...expanded, ...this.args]
|
|
244
|
+
);
|
|
166
245
|
});
|
|
167
|
-
proxy.helpOption(false);
|
|
168
|
-
proxy.
|
|
169
|
-
program.addCommand(proxy);
|
|
246
|
+
if (_optionalChain([opts, 'optionalAccess', _7 => _7.helpOption]) !== true) proxy.helpOption(false);
|
|
247
|
+
program.addCommand(proxy, { hidden: _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _8 => _8.hidden]), () => ( true)) });
|
|
170
248
|
}
|
|
171
249
|
}
|
|
172
250
|
|
|
@@ -179,4 +257,7 @@ function bridgeAliases(program, store) {
|
|
|
179
257
|
|
|
180
258
|
|
|
181
259
|
|
|
182
|
-
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
exports.loadFrom = loadFrom; exports.saveTo = saveTo; exports.findFirstNonFlag = findFirstNonFlag; exports.AliasStore = AliasStore; exports.Expander = Expander; exports.AliasNameError = AliasNameError; exports.validateAliasName = validateAliasName; exports.detectCycles = detectCycles; exports.findCommand = findCommand; exports.bridgeAliases = bridgeAliases; exports.alias_exports = alias_exports;
|
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk72XZWQX7js = require('./chunk-72XZWQX7.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
+
var _chunkPOR5L2DGjs = require('./chunk-POR5L2DG.js');
|
|
6
7
|
|
|
7
8
|
|
|
9
|
+
var _chunkQPUCXQXTjs = require('./chunk-QPUCXQXT.js');
|
|
8
10
|
|
|
9
11
|
|
|
10
12
|
|
|
11
13
|
|
|
12
14
|
|
|
13
|
-
var _chunkKVG7YCTSjs = require('./chunk-KVG7YCTS.js');
|
|
14
15
|
|
|
15
16
|
|
|
16
|
-
var _chunk72XZWQX7js = require('./chunk-72XZWQX7.js');
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
var
|
|
19
|
+
var _chunkKVG7YCTSjs = require('./chunk-KVG7YCTS.js');
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
var _chunkJZ22ZUFAjs = require('./chunk-JZ22ZUFA.js');
|
|
20
23
|
|
|
21
24
|
|
|
22
25
|
var _chunkR5U7XKVJjs = require('./chunk-R5U7XKVJ.js');
|
|
@@ -558,6 +561,7 @@ ${cfg.help.disclaimer}` : cfg.description;
|
|
|
558
561
|
const flag = g.short ? `-${g.short}, --${g.name} <value>` : `--${g.name} <value>`;
|
|
559
562
|
program.option(flag, g.usage, _nullishCoalesce(g.default, () => ( "")));
|
|
560
563
|
}
|
|
564
|
+
_chunkJZ22ZUFAjs.installCompletionRequest.call(void 0, program);
|
|
561
565
|
applyHelpTheme(
|
|
562
566
|
program,
|
|
563
567
|
theme,
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkR5U7XKVJjs = require('./chunk-R5U7XKVJ.js');
|
|
4
|
+
|
|
5
|
+
// src/completion-values.ts
|
|
6
|
+
var completion_values_exports = {};
|
|
7
|
+
_chunkR5U7XKVJjs.__export.call(void 0, completion_values_exports, {
|
|
8
|
+
CompletionRegistry: () => CompletionRegistry,
|
|
9
|
+
ShellCompDirective: () => ShellCompDirective,
|
|
10
|
+
configKeysCompleter: () => configKeysCompleter,
|
|
11
|
+
dirCompleter: () => dirCompleter,
|
|
12
|
+
directiveName: () => directiveName,
|
|
13
|
+
fileCompleter: () => fileCompleter,
|
|
14
|
+
funcCompleter: () => funcCompleter,
|
|
15
|
+
prefixedCompleter: () => prefixedCompleter,
|
|
16
|
+
resolveCompletions: () => resolveCompletions,
|
|
17
|
+
staticCompleter: () => staticCompleter,
|
|
18
|
+
staticValues: () => staticValues,
|
|
19
|
+
withDescription: () => withDescription
|
|
20
|
+
});
|
|
21
|
+
var ShellCompDirective = {
|
|
22
|
+
Default: 0,
|
|
23
|
+
Error: 1,
|
|
24
|
+
NoSpace: 2,
|
|
25
|
+
NoFileComp: 4,
|
|
26
|
+
FilterFileExt: 8,
|
|
27
|
+
FilterDirs: 16,
|
|
28
|
+
KeepOrder: 32
|
|
29
|
+
};
|
|
30
|
+
function directiveName(d) {
|
|
31
|
+
if (d >= 64) return `ERROR: unexpected ShellCompDirective value: ${d}`;
|
|
32
|
+
const names = [
|
|
33
|
+
[ShellCompDirective.Error, "ShellCompDirectiveError"],
|
|
34
|
+
[ShellCompDirective.NoSpace, "ShellCompDirectiveNoSpace"],
|
|
35
|
+
[ShellCompDirective.NoFileComp, "ShellCompDirectiveNoFileComp"],
|
|
36
|
+
[ShellCompDirective.FilterFileExt, "ShellCompDirectiveFilterFileExt"],
|
|
37
|
+
[ShellCompDirective.FilterDirs, "ShellCompDirectiveFilterDirs"],
|
|
38
|
+
[ShellCompDirective.KeepOrder, "ShellCompDirectiveKeepOrder"]
|
|
39
|
+
];
|
|
40
|
+
const set = names.filter(([bit]) => (d & bit) === bit).map(([, n]) => n);
|
|
41
|
+
return set.length ? set.join(", ") : "ShellCompDirectiveDefault";
|
|
42
|
+
}
|
|
43
|
+
async function resolveCompletions(c, toComplete, ctx = { commandPath: "", args: [] }) {
|
|
44
|
+
const f = c.fileFilter;
|
|
45
|
+
if (_optionalChain([f, 'optionalAccess', _ => _.kind]) === "dirs") {
|
|
46
|
+
return { completions: [], directive: ShellCompDirective.FilterDirs };
|
|
47
|
+
}
|
|
48
|
+
if (_optionalChain([f, 'optionalAccess', _2 => _2.kind]) === "extensions") {
|
|
49
|
+
return f.extensions.length === 0 ? { completions: [], directive: ShellCompDirective.Default } : { completions: [...f.extensions], directive: ShellCompDirective.FilterFileExt };
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const items = await c.complete(toComplete, ctx);
|
|
53
|
+
return {
|
|
54
|
+
completions: items.map(withDescription),
|
|
55
|
+
directive: ShellCompDirective.NoFileComp
|
|
56
|
+
};
|
|
57
|
+
} catch (e2) {
|
|
58
|
+
return { completions: [], directive: ShellCompDirective.Error };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function withDescription(i) {
|
|
62
|
+
return i.description ? `${i.value} ${i.description}` : i.value;
|
|
63
|
+
}
|
|
64
|
+
var CompletionRegistry = class {
|
|
65
|
+
constructor() {
|
|
66
|
+
this.flags = /* @__PURE__ */ new Map();
|
|
67
|
+
this.args = /* @__PURE__ */ new Map();
|
|
68
|
+
}
|
|
69
|
+
register(flag, completer) {
|
|
70
|
+
this.flags.set(flag, completer);
|
|
71
|
+
}
|
|
72
|
+
registerArg(cmd, pos, completer) {
|
|
73
|
+
this.args.set(`${cmd}:${pos}`, completer);
|
|
74
|
+
}
|
|
75
|
+
forFlag(flag) {
|
|
76
|
+
return this.flags.get(flag);
|
|
77
|
+
}
|
|
78
|
+
forArg(cmd, pos) {
|
|
79
|
+
return this.args.get(`${cmd}:${pos}`);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
function filterByPrefix(items, prefix) {
|
|
83
|
+
if (!prefix) return [...items];
|
|
84
|
+
const lp = prefix.toLowerCase();
|
|
85
|
+
return items.filter((i) => i.value.toLowerCase().startsWith(lp));
|
|
86
|
+
}
|
|
87
|
+
function staticCompleter(...items) {
|
|
88
|
+
return {
|
|
89
|
+
complete(prefix) {
|
|
90
|
+
return filterByPrefix(items, prefix);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function staticValues(...values) {
|
|
95
|
+
const items = values.map((v) => ({ value: v }));
|
|
96
|
+
return staticCompleter(...items);
|
|
97
|
+
}
|
|
98
|
+
function funcCompleter(fn) {
|
|
99
|
+
return {
|
|
100
|
+
complete(prefix, ctx = { commandPath: "", args: [] }) {
|
|
101
|
+
return fn(prefix, ctx);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function prefixedCompleter(dimension, values) {
|
|
106
|
+
const lower = dimension.toLowerCase();
|
|
107
|
+
const prepend = (items) => items.map((i) => {
|
|
108
|
+
const v = `${dimension}:${i.value}`;
|
|
109
|
+
return i.description ? { value: v, description: i.description } : { value: v };
|
|
110
|
+
});
|
|
111
|
+
return {
|
|
112
|
+
complete(prefix, ctx) {
|
|
113
|
+
const colonIdx = prefix.indexOf(":");
|
|
114
|
+
if (colonIdx < 0) {
|
|
115
|
+
const dim = `${dimension}:`;
|
|
116
|
+
return dim.toLowerCase().startsWith(prefix.toLowerCase()) ? [{ value: dim, description: `${dimension} values` }] : [];
|
|
117
|
+
}
|
|
118
|
+
if (prefix.slice(0, colonIdx).toLowerCase() !== lower) return [];
|
|
119
|
+
const inner = values.complete(prefix.slice(colonIdx + 1), ctx);
|
|
120
|
+
return Array.isArray(inner) ? prepend(inner) : inner.then(prepend);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function leafKeys(obj, prefix, out) {
|
|
125
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
126
|
+
const full = prefix ? `${prefix}.${k.toLowerCase()}` : k.toLowerCase();
|
|
127
|
+
if (v != null && typeof v === "object" && !Array.isArray(v)) {
|
|
128
|
+
leafKeys(v, full, out);
|
|
129
|
+
} else {
|
|
130
|
+
out.add(full);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function configKeysCompleter(config) {
|
|
135
|
+
return {
|
|
136
|
+
complete(prefix) {
|
|
137
|
+
const keys = /* @__PURE__ */ new Set();
|
|
138
|
+
leafKeys(config, "", keys);
|
|
139
|
+
return filterByPrefix([...keys].map((k) => ({ value: k })), prefix);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function fileCompleter(...extensions) {
|
|
144
|
+
return {
|
|
145
|
+
fileFilter: { kind: "extensions", extensions: [...extensions] },
|
|
146
|
+
complete() {
|
|
147
|
+
return extensions.map((e) => ({ value: e }));
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function dirCompleter() {
|
|
152
|
+
return {
|
|
153
|
+
fileFilter: { kind: "dirs" },
|
|
154
|
+
complete() {
|
|
155
|
+
return [];
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
exports.ShellCompDirective = ShellCompDirective; exports.directiveName = directiveName; exports.resolveCompletions = resolveCompletions; exports.withDescription = withDescription; exports.CompletionRegistry = CompletionRegistry; exports.staticCompleter = staticCompleter; exports.staticValues = staticValues; exports.funcCompleter = funcCompleter; exports.prefixedCompleter = prefixedCompleter; exports.configKeysCompleter = configKeysCompleter; exports.fileCompleter = fileCompleter; exports.dirCompleter = dirCompleter; exports.completion_values_exports = completion_values_exports;
|