burgee 0.2.0 → 0.4.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/LICENSE +21 -0
- package/README.md +61 -9
- package/dist/brand.d.ts +62 -1
- package/dist/brand.js +73 -7
- package/dist/cli.d.ts +11 -0
- package/dist/cli.js +17 -1
- package/dist/{commander-argument.js → commander/argument.js} +4 -1
- package/dist/{commander-command.d.ts → commander/command.d.ts} +15 -5
- package/dist/{commander-command.js → commander/command.js} +175 -22
- package/dist/{commander-error.js → commander/error.js} +2 -0
- package/dist/{commander-help.d.ts → commander/help.d.ts} +3 -3
- package/dist/{commander-help.js → commander/help.js} +18 -1
- package/dist/{commander-option.d.ts → commander/option.d.ts} +1 -1
- package/dist/{commander-option.js → commander/option.js} +15 -1
- package/dist/commander.d.ts +8 -8
- package/dist/commander.js +8 -8
- package/dist/completions.js +15 -4
- package/dist/dev.d.ts +47 -0
- package/dist/dev.js +132 -0
- package/dist/execute.d.ts +22 -1
- package/dist/execute.js +75 -24
- package/dist/help.d.ts +19 -7
- package/dist/help.js +50 -21
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/manifest.d.ts +15 -0
- package/dist/manifest.js +12 -1
- package/dist/mcp.d.ts +14 -2
- package/dist/mcp.js +15 -2
- package/dist/runtime.d.ts +12 -0
- package/dist/runtime.js +7 -0
- package/dist/schema.d.ts +10 -0
- package/dist/schema.js +11 -0
- package/dist/testing-helpers.d.ts +18 -1
- package/dist/testing-helpers.js +35 -0
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +1 -1
- package/dist/unknown-option.d.ts +9 -0
- package/dist/unknown-option.js +27 -0
- package/dist/{yargs-burgee.d.ts → yargs/burgee.d.ts} +2 -2
- package/dist/{yargs-burgee.js → yargs/burgee.js} +15 -1
- package/dist/{yargs-cliui.js → yargs/cliui.js} +8 -0
- package/dist/{yargs-command.d.ts → yargs/command.d.ts} +5 -5
- package/dist/{yargs-command.js → yargs/command.js} +9 -2
- package/dist/{yargs-completion.d.ts → yargs/completion.d.ts} +3 -3
- package/dist/{yargs-completion.js → yargs/completion.js} +7 -2
- package/dist/{yargs-factory.d.ts → yargs/factory.d.ts} +8 -8
- package/dist/{yargs-factory.js → yargs/factory.js} +63 -13
- package/dist/{yargs-middleware.js → yargs/middleware.js} +6 -1
- package/dist/{yargs-shim.d.ts → yargs/shim.d.ts} +3 -3
- package/dist/{yargs-shim.js → yargs/shim.js} +24 -5
- package/dist/{yargs-usage.d.ts → yargs/usage.d.ts} +1 -1
- package/dist/{yargs-usage.js → yargs/usage.js} +9 -1
- package/dist/{yargs-utils.js → yargs/utils.js} +11 -0
- package/dist/{yargs-validation.d.ts → yargs/validation.d.ts} +1 -1
- package/dist/{yargs-validation.js → yargs/validation.js} +7 -1
- package/dist/{yargs-y18n.js → yargs/y18n.js} +6 -0
- package/dist/yargs-helpers.d.ts +1 -1
- package/dist/yargs-helpers.js +1 -1
- package/dist/yargs.d.ts +4 -4
- package/dist/yargs.js +5 -5
- package/package.json +3 -2
- /package/dist/{commander-argument.d.ts → commander/argument.d.ts} +0 -0
- /package/dist/{commander-error.d.ts → commander/error.d.ts} +0 -0
- /package/dist/{commander-suggest.d.ts → suggest.d.ts} +0 -0
- /package/dist/{commander-suggest.js → suggest.js} +0 -0
- /package/dist/{yargs-cliui.d.ts → yargs/cliui.d.ts} +0 -0
- /package/dist/{yargs-middleware.d.ts → yargs/middleware.d.ts} +0 -0
- /package/dist/{yargs-utils.d.ts → yargs/utils.d.ts} +0 -0
- /package/dist/{yargs-y18n.d.ts → yargs/y18n.d.ts} +0 -0
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { Readable } from 'node:stream';
|
|
9
9
|
import { ExitCode } from './exit-code.js';
|
|
10
10
|
import { type Manifest } from './manifest.js';
|
|
11
|
-
import { type Runtime } from './runtime.js';
|
|
11
|
+
import { type Clock, type Runtime } from './runtime.js';
|
|
12
12
|
export interface RunOptions {
|
|
13
13
|
argv: string[];
|
|
14
14
|
env?: Record<string, string>;
|
|
@@ -16,6 +16,8 @@ export interface RunOptions {
|
|
|
16
16
|
cwd?: string;
|
|
17
17
|
/** `true` = every stream is a TTY; an object sets each; default: none is. */
|
|
18
18
|
tty?: boolean | Partial<Runtime['isTTY']>;
|
|
19
|
+
/** The clock the runtime reports; a fresh `fakeClock()` at 0 when not given. */
|
|
20
|
+
clock?: FakeClock;
|
|
19
21
|
}
|
|
20
22
|
export interface RunResult {
|
|
21
23
|
code: ExitCode;
|
|
@@ -33,7 +35,22 @@ export declare class RuntimeExit extends Error {
|
|
|
33
35
|
export interface FakeRuntime extends Runtime {
|
|
34
36
|
out: string[];
|
|
35
37
|
err: string[];
|
|
38
|
+
clock: FakeClock;
|
|
36
39
|
}
|
|
40
|
+
/** A `Clock` that moves only when the test says so (R14): `tick` is the only source of time. */
|
|
41
|
+
export interface FakeClock extends Clock {
|
|
42
|
+
/**
|
|
43
|
+
* Advance by `ms`, running every callback that falls due, earliest first, then by order
|
|
44
|
+
* scheduled. A callback that schedules inside the window runs in the same tick, so one that
|
|
45
|
+
* reschedules itself at `0` would never leave the loop (real Node yields between turns);
|
|
46
|
+
* a tick runs at most `TICK_CAP` callbacks and throws, naming the cap, when exceeded.
|
|
47
|
+
*/
|
|
48
|
+
tick(ms: number): void;
|
|
49
|
+
/** Callbacks scheduled and neither run nor cancelled. */
|
|
50
|
+
pending(): number;
|
|
51
|
+
}
|
|
52
|
+
/** Deterministic time for the harness. Starts at `start` (0 by default) and never moves on its own. */
|
|
53
|
+
export declare function fakeClock(start?: number): FakeClock;
|
|
37
54
|
/** A `Runtime` whose every part is under the test's control. */
|
|
38
55
|
export declare function fakeRuntime(opts: RunOptions): FakeRuntime;
|
|
39
56
|
export declare function swapEnv(env: Record<string, string> | undefined): () => void;
|
package/dist/testing-helpers.js
CHANGED
|
@@ -9,6 +9,40 @@ export class RuntimeExit extends Error {
|
|
|
9
9
|
this.name = 'RuntimeExit';
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
+
const TICK_CAP = 1000;
|
|
13
|
+
export function fakeClock(start = 0) {
|
|
14
|
+
let now = start;
|
|
15
|
+
let nextId = 0;
|
|
16
|
+
const timers = [];
|
|
17
|
+
const remove = (id) => {
|
|
18
|
+
const at = timers.findIndex((t) => t.id === id);
|
|
19
|
+
if (at !== -1)
|
|
20
|
+
timers.splice(at, 1);
|
|
21
|
+
};
|
|
22
|
+
return {
|
|
23
|
+
now: () => now,
|
|
24
|
+
schedule(fn, ms) {
|
|
25
|
+
const id = nextId++;
|
|
26
|
+
timers.push({ id, at: now + Math.max(0, ms), fn });
|
|
27
|
+
return () => remove(id);
|
|
28
|
+
},
|
|
29
|
+
tick(ms) {
|
|
30
|
+
const until = now + ms;
|
|
31
|
+
const nextDue = () => timers.filter((t) => t.at <= until).sort((a, b) => a.at - b.at || a.id - b.id)[0];
|
|
32
|
+
let ran = 0;
|
|
33
|
+
for (let due = nextDue(); due !== undefined; due = nextDue()) {
|
|
34
|
+
if (ran === TICK_CAP)
|
|
35
|
+
throw new Error(`fakeClock.tick(${ms}) ran ${TICK_CAP} callbacks (TICK_CAP): a callback keeps rescheduling inside the window`);
|
|
36
|
+
ran += 1;
|
|
37
|
+
remove(due.id);
|
|
38
|
+
now = Math.max(now, due.at);
|
|
39
|
+
due.fn();
|
|
40
|
+
}
|
|
41
|
+
now = until;
|
|
42
|
+
},
|
|
43
|
+
pending: () => timers.length,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
12
46
|
function ttyOf(tty) {
|
|
13
47
|
if (tty === true)
|
|
14
48
|
return { stdin: true, stdout: true, stderr: true };
|
|
@@ -31,6 +65,7 @@ export function fakeRuntime(opts) {
|
|
|
31
65
|
exit(code) {
|
|
32
66
|
throw new RuntimeExit(code);
|
|
33
67
|
},
|
|
68
|
+
clock: opts.clock ?? fakeClock(),
|
|
34
69
|
out,
|
|
35
70
|
err,
|
|
36
71
|
};
|
package/dist/testing.d.ts
CHANGED
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* A separate entry point so it is paid for per import (K6): a user's shipped CLI
|
|
6
6
|
* imports `burgee` and never pulls a byte of this.
|
|
7
7
|
*/
|
|
8
|
-
export { processRuntime, type Runtime, type Writer } from './runtime.js';
|
|
9
|
-
export { captureConsole, codeOf, fakeRuntime, finish, runBurgee, RuntimeExit, stripAnsi, swapEnv, type FakeRuntime, type RunOptions, type RunResult, } from './testing-helpers.js';
|
|
8
|
+
export { processRuntime, type Clock, type Runtime, type Writer } from './runtime.js';
|
|
9
|
+
export { captureConsole, codeOf, fakeClock, fakeRuntime, finish, runBurgee, RuntimeExit, stripAnsi, swapEnv, type FakeClock, type FakeRuntime, type RunOptions, type RunResult, } from './testing-helpers.js';
|
|
10
10
|
export { ExitCode, isExitCode, type ExitCode as ExitCodeValue } from './exit-code.js';
|
package/dist/testing.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { processRuntime } from './runtime.js';
|
|
2
|
-
export { captureConsole, codeOf, fakeRuntime, finish, runBurgee, RuntimeExit, stripAnsi, swapEnv, } from './testing-helpers.js';
|
|
2
|
+
export { captureConsole, codeOf, fakeClock, fakeRuntime, finish, runBurgee, RuntimeExit, stripAnsi, swapEnv, } from './testing-helpers.js';
|
|
3
3
|
export { ExitCode, isExitCode } from './exit-code.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `-foo=bar` means three short flags to a parser and one long flag to a person
|
|
3
|
+
* (citty #237). The more specific reading of the same argv, so it is offered first.
|
|
4
|
+
*/
|
|
5
|
+
export declare function singleDashHint(argv: readonly string[]): string | undefined;
|
|
6
|
+
export declare function unknownOption(cause: unknown, declared: readonly string[]): {
|
|
7
|
+
message: string;
|
|
8
|
+
hint: string;
|
|
9
|
+
} | undefined;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { suggestSimilar } from './suggest.js';
|
|
2
|
+
const UNKNOWN_OPTION = /^Unknown option '(?<flag>[^']+)'/u;
|
|
3
|
+
const NEAREST = /--[\w-]+/u;
|
|
4
|
+
const SINGLE_DASH_WORD = /^-(?<word>[a-zA-Z][\w-]+)(?:=.*)?$/u;
|
|
5
|
+
export function singleDashHint(argv) {
|
|
6
|
+
for (const token of argv) {
|
|
7
|
+
if (token === '--')
|
|
8
|
+
return undefined;
|
|
9
|
+
const word = SINGLE_DASH_WORD.exec(token)?.groups?.['word'];
|
|
10
|
+
if (word !== undefined)
|
|
11
|
+
return `did you mean --${word}? a single dash introduces one-letter options`;
|
|
12
|
+
}
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
export function unknownOption(cause, declared) {
|
|
16
|
+
if (!(cause instanceof Error))
|
|
17
|
+
return undefined;
|
|
18
|
+
const flag = UNKNOWN_OPTION.exec(cause.message)?.groups?.['flag'];
|
|
19
|
+
if (flag === undefined)
|
|
20
|
+
return undefined;
|
|
21
|
+
const dashed = declared.map((option) => `--${option}`);
|
|
22
|
+
const near = NEAREST.exec(suggestSimilar(flag, dashed))?.[0];
|
|
23
|
+
return {
|
|
24
|
+
message: `unknown option ${flag}`,
|
|
25
|
+
hint: near === undefined ? 'run --help to see the available options' : `did you mean ${near}?`,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* this module projects that snapshot into the manifest every surface reads (J7, J8).
|
|
5
5
|
* Nothing here runs at parse time unless a burgee surface was asked for.
|
|
6
6
|
*/
|
|
7
|
-
import { type Effects, type Manifest, type OptionSpec } from '
|
|
8
|
-
import type { Positional } from './
|
|
7
|
+
import { type Effects, type Manifest, type OptionSpec } from '../manifest.js';
|
|
8
|
+
import type { Positional } from './utils.js';
|
|
9
9
|
/** What one yargs instance (the root, or a command's builder run on a scratch) registered. */
|
|
10
10
|
export interface Snapshot {
|
|
11
11
|
name: string;
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* burgee's additions on yargs syntax — the pure half. `yargs-factory.ts` snapshots what
|
|
3
|
+
* a program registered (options, descriptions, commands and their builders' results) and
|
|
4
|
+
* this module projects that snapshot into the manifest every surface reads (J7, J8).
|
|
5
|
+
* Nothing here runs at parse time unless a burgee surface was asked for.
|
|
6
|
+
*/
|
|
7
|
+
import {} from '../manifest.js';
|
|
8
|
+
import { camelCase } from '../yargs-parser.js';
|
|
2
9
|
const DEFER_PREFIX = '__yargsString__:';
|
|
3
10
|
function describe(descriptions, key) {
|
|
4
11
|
const raw = descriptions[key];
|
|
@@ -14,6 +21,7 @@ function typeOf(s, key) {
|
|
|
14
21
|
return 'number';
|
|
15
22
|
return 'string';
|
|
16
23
|
}
|
|
24
|
+
/** Options as the manifest describes them, on a null-prototype record keyed by the canonical camelCase name. */
|
|
17
25
|
export function optionSpecs(s) {
|
|
18
26
|
const specs = Object.create(null);
|
|
19
27
|
const aliasOf = new Set();
|
|
@@ -68,6 +76,10 @@ function argumentsOf(s) {
|
|
|
68
76
|
push(p, false);
|
|
69
77
|
return out;
|
|
70
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Project a snapshot into the manifest: the root, then every command as a child path.
|
|
81
|
+
* Plugin-contributed nodes survive re-projection, exactly as on the commander façade.
|
|
82
|
+
*/
|
|
71
83
|
export function projectManifest(manifest, root) {
|
|
72
84
|
const contributed = manifest.commands.filter((c) => c.plugin !== undefined);
|
|
73
85
|
manifest.commands.splice(0, manifest.commands.length, ...contributed);
|
|
@@ -90,6 +102,7 @@ export function projectManifest(manifest, root) {
|
|
|
90
102
|
};
|
|
91
103
|
visit(root, [root.name], root.description, undefined);
|
|
92
104
|
}
|
|
105
|
+
/** What a run prints for a handler's return value when the streams are injected. */
|
|
93
106
|
export function render(value) {
|
|
94
107
|
if (value === undefined || value === null)
|
|
95
108
|
return '';
|
|
@@ -102,3 +115,4 @@ export function render(value) {
|
|
|
102
115
|
}
|
|
103
116
|
return `${JSON.stringify(value)}\n`;
|
|
104
117
|
}
|
|
118
|
+
//# sourceMappingURL=burgee.js.map
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cliui 9 — the column layout yargs' usage renders through — with the string-width,
|
|
3
|
+
* strip-ansi and wrap-ansi it depends on, ported for `burgee/yargs`. The wrapping
|
|
4
|
+
* arithmetic is byte-for-byte the upstream's: yargs' usage tests compare whole help
|
|
5
|
+
* screens.
|
|
6
|
+
*/
|
|
1
7
|
const ANSI_PATTERN = '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))';
|
|
2
8
|
export function stripAnsi(str) {
|
|
3
9
|
return typeof str === 'string' ? str.replace(new RegExp(ANSI_PATTERN, 'g'), '') : str;
|
|
@@ -47,6 +53,7 @@ export function stringWidth(input) {
|
|
|
47
53
|
}
|
|
48
54
|
return width;
|
|
49
55
|
}
|
|
56
|
+
/** ansi-styles' open→close map, the part wrap-ansi reads. */
|
|
50
57
|
function closeCode(code) {
|
|
51
58
|
if (code === 1 || code === 2)
|
|
52
59
|
return 22;
|
|
@@ -419,3 +426,4 @@ function alignCenter(str, width) {
|
|
|
419
426
|
export function cliui(opts) {
|
|
420
427
|
return new UI({ width: opts?.width || getWindowWidth(), wrap: opts?.wrap });
|
|
421
428
|
}
|
|
429
|
+
//# sourceMappingURL=cliui.js.map
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
* builder/handler pipeline, positionals and the default command — ported for
|
|
4
4
|
* `burgee/yargs`.
|
|
5
5
|
*/
|
|
6
|
-
import { type Middleware } from './
|
|
7
|
-
import type { PlatformShim } from './
|
|
8
|
-
import type { UsageInstance } from './
|
|
9
|
-
import { type Positional } from './
|
|
10
|
-
import type { ValidationInstance } from './
|
|
6
|
+
import { type Middleware } from './middleware.js';
|
|
7
|
+
import type { PlatformShim } from './shim.js';
|
|
8
|
+
import type { UsageInstance } from './usage.js';
|
|
9
|
+
import { type Positional } from './utils.js';
|
|
10
|
+
import type { ValidationInstance } from './validation.js';
|
|
11
11
|
export interface CommandHandler {
|
|
12
12
|
original: string;
|
|
13
13
|
description?: string | false | undefined;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* yargs' command instance — `.command()` in its five shapes, `.commandDir()`, the
|
|
3
|
+
* builder/handler pipeline, positionals and the default command — ported for
|
|
4
|
+
* `burgee/yargs`.
|
|
5
|
+
*/
|
|
6
|
+
import { applyMiddleware, commandMiddlewareFactory } from './middleware.js';
|
|
7
|
+
import { isPromise, maybeAsyncResult, parseCommand } from './utils.js';
|
|
3
8
|
const DEFAULT_MARKER = /(^\*)|(^\$0)/;
|
|
4
9
|
export function isYargsInstance(y) {
|
|
5
10
|
return !!y && typeof y.getInternalMethods === 'function';
|
|
@@ -222,6 +227,7 @@ export class CommandInstance {
|
|
|
222
227
|
yargs.getInternalMethods().getUsageInstance().fail(null, error);
|
|
223
228
|
}
|
|
224
229
|
catch {
|
|
230
|
+
// the failure was reported; yargs swallows the rethrow here
|
|
225
231
|
}
|
|
226
232
|
});
|
|
227
233
|
}
|
|
@@ -412,3 +418,4 @@ function isCommandBuilderOptionDefinitions(builder) {
|
|
|
412
418
|
export function isCommandHandlerDefinition(cmd) {
|
|
413
419
|
return typeof cmd === 'object' && !Array.isArray(cmd);
|
|
414
420
|
}
|
|
421
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* yargs' completion — `--get-yargs-completions`, the custom completion function in its
|
|
3
3
|
* three arities, and the bash/zsh script templates — ported for `burgee/yargs`.
|
|
4
4
|
*/
|
|
5
|
-
import { type CommandInstance } from './
|
|
6
|
-
import type { PlatformShim } from './
|
|
7
|
-
import type { UsageInstance } from './
|
|
5
|
+
import { type CommandInstance } from './command.js';
|
|
6
|
+
import type { PlatformShim } from './shim.js';
|
|
7
|
+
import type { UsageInstance } from './usage.js';
|
|
8
8
|
export declare const completionShTemplate = "###-begin-{{app_name}}-completions-###\n#\n# yargs command completion script\n#\n# Installation: {{app_path}} {{completion_command}} >> ~/.bashrc\n# or {{app_path}} {{completion_command}} >> ~/.bash_profile on OSX.\n#\n_{{app_name}}_yargs_completions()\n{\n local cur_word args type_list\n\n cur_word=\"${COMP_WORDS[COMP_CWORD]}\"\n args=(\"${COMP_WORDS[@]}\")\n\n # ask yargs to generate completions.\n # see https://stackoverflow.com/a/40944195/7080036 for the spaces-handling awk\n mapfile -t type_list < <({{app_path}} --get-yargs-completions \"${args[@]}\")\n mapfile -t COMPREPLY < <(compgen -W \"$( printf '%q ' \"${type_list[@]}\" )\" -- \"${cur_word}\" |\n awk '/ / { print \"\\\"\"$0\"\\\"\" } /^[^ ]+$/ { print $0 }')\n\n # if no match was found, fall back to filename completion\n if [ ${#COMPREPLY[@]} -eq 0 ]; then\n COMPREPLY=()\n fi\n\n return 0\n}\ncomplete -o bashdefault -o default -F _{{app_name}}_yargs_completions {{app_name}}\n###-end-{{app_name}}-completions-###\n";
|
|
9
9
|
export declare const completionZshTemplate = "#compdef {{app_name}}\n###-begin-{{app_name}}-completions-###\n#\n# yargs command completion script\n#\n# Installation: {{app_path}} {{completion_command}} >> ~/.zshrc\n# or {{app_path}} {{completion_command}} >> ~/.zprofile on OSX.\n#\n_{{app_name}}_yargs_completions()\n{\n local reply\n local si=$IFS\n IFS=$'\n' reply=($(COMP_CWORD=\"$((CURRENT-1))\" COMP_LINE=\"$BUFFER\" COMP_POINT=\"$CURSOR\" {{app_path}} --get-yargs-completions \"${words[@]}\"))\n IFS=$si\n if [[ ${#reply} -gt 0 ]]; then\n _describe 'values' reply\n else\n _default\n fi\n}\nif [[ \"'${zsh_eval_context[-1]}\" == \"loadautofunc\" ]]; then\n _{{app_name}}_yargs_completions \"$@\"\nelse\n compdef _{{app_name}}_yargs_completions {{app_name}}\nfi\n###-end-{{app_name}}-completions-###\n";
|
|
10
10
|
type Done = (err: Error | null, completions: string[] | undefined) => void;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* yargs' completion — `--get-yargs-completions`, the custom completion function in its
|
|
3
|
+
* three arities, and the bash/zsh script templates — ported for `burgee/yargs`.
|
|
4
|
+
*/
|
|
5
|
+
import { isCommandBuilderCallback } from './command.js';
|
|
6
|
+
import { isPromise, parseCommand } from './utils.js';
|
|
3
7
|
export const completionShTemplate = `###-begin-{{app_name}}-completions-###
|
|
4
8
|
#
|
|
5
9
|
# yargs command completion script
|
|
@@ -269,3 +273,4 @@ function isSyncCompletionFunction(fn) {
|
|
|
269
273
|
function isFallbackCompletionFunction(fn) {
|
|
270
274
|
return fn.length > 3;
|
|
271
275
|
}
|
|
276
|
+
//# sourceMappingURL=completion.js.map
|
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
* `getInternalMethods()` seam are the upstream's — that is what makes a user's
|
|
6
6
|
* existing program run unchanged (J2).
|
|
7
7
|
*/
|
|
8
|
-
import { type Effects, Manifest, type Plugin } from '
|
|
9
|
-
import { type CommandInstance } from './
|
|
10
|
-
import { type CompletionFunction } from './
|
|
11
|
-
import { type Middleware } from './
|
|
12
|
-
import type { PlatformShim } from './
|
|
13
|
-
import { type FailureFunction, type UsageInstance } from './
|
|
14
|
-
import { YError } from './
|
|
15
|
-
import { type ValidationInstance } from './
|
|
8
|
+
import { type Effects, Manifest, type Plugin } from '../manifest.js';
|
|
9
|
+
import { type CommandInstance } from './command.js';
|
|
10
|
+
import { type CompletionFunction } from './completion.js';
|
|
11
|
+
import { type Middleware } from './middleware.js';
|
|
12
|
+
import type { PlatformShim } from './shim.js';
|
|
13
|
+
import { type FailureFunction, type UsageInstance } from './usage.js';
|
|
14
|
+
import { YError } from './utils.js';
|
|
15
|
+
import { type ValidationInstance } from './validation.js';
|
|
16
16
|
export interface Options {
|
|
17
17
|
array: string[];
|
|
18
18
|
boolean: string[];
|
|
@@ -1,16 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* yargs' `YargsInstance`, ported method for method from yargs 18 and graded by yargs'
|
|
3
|
+
* own suite through `compat-oracle`. Every public method, its argsert contract, the
|
|
4
|
+
* parse pipeline, the freeze/unfreeze bookkeeping around `.parse()` and the
|
|
5
|
+
* `getInternalMethods()` seam are the upstream's — that is what makes a user's
|
|
6
|
+
* existing program run unchanged (J2).
|
|
7
|
+
*/
|
|
1
8
|
var _a;
|
|
2
|
-
import { ExitCode } from '
|
|
3
|
-
import { Manifest } from '
|
|
4
|
-
import { serveMcp } from '
|
|
5
|
-
import { schemaOf } from '
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { usage as Usage } from './
|
|
12
|
-
import { applyExtends, argsert, isPromise, maybeAsyncResult, objectKeys, objFilter, setBlocking, YError } from './
|
|
13
|
-
import { validation as Validation } from './
|
|
9
|
+
import { ExitCode } from '../exit-code.js';
|
|
10
|
+
import { Manifest } from '../manifest.js';
|
|
11
|
+
import { serveMcp } from '../mcp.js';
|
|
12
|
+
import { schemaOf } from '../schema.js';
|
|
13
|
+
import { tokenizeArgString } from '../yargs-parser.js';
|
|
14
|
+
import { projectManifest, render } from './burgee.js';
|
|
15
|
+
import { command as Command, isCommandBuilderCallback } from './command.js';
|
|
16
|
+
import { completion as Completion } from './completion.js';
|
|
17
|
+
import { applyMiddleware, GlobalMiddleware } from './middleware.js';
|
|
18
|
+
import { usage as Usage } from './usage.js';
|
|
19
|
+
import { applyExtends, argsert, isPromise, maybeAsyncResult, objectKeys, objFilter, setBlocking, YError } from './utils.js';
|
|
20
|
+
import { validation as Validation } from './validation.js';
|
|
14
21
|
const DEFAULT_LOCALE = 'en_US';
|
|
15
22
|
export function YargsFactory(shim) {
|
|
16
23
|
return (processArgs = [], cwd = shim.process.cwd(), parentRequire) => {
|
|
@@ -64,6 +71,7 @@ export class YargsInstance {
|
|
|
64
71
|
#usageConfig = {};
|
|
65
72
|
#versionOpt = null;
|
|
66
73
|
#validation;
|
|
74
|
+
// ───── burgee: the manifest projection, plugins, --json, the surfaces and the seam ─────
|
|
67
75
|
#burgee = undefined;
|
|
68
76
|
#effects = undefined;
|
|
69
77
|
#manifest = undefined;
|
|
@@ -74,6 +82,7 @@ export class YargsInstance {
|
|
|
74
82
|
this.#parentRequire = parentRequire;
|
|
75
83
|
this.#globalMiddleware = new GlobalMiddleware(this);
|
|
76
84
|
this.$0 = this.#getDollarZero();
|
|
85
|
+
// kReset builds the four collaborators; the definite assignments below are its result.
|
|
77
86
|
this.#options = undefined;
|
|
78
87
|
this.#usage = undefined;
|
|
79
88
|
this.#validation = undefined;
|
|
@@ -593,6 +602,8 @@ export class YargsInstance {
|
|
|
593
602
|
argsert('[string|array] [function|boolean|object] [function]', [args, shortCircuit, _parseFn], arguments.length);
|
|
594
603
|
if (shortCircuit === true)
|
|
595
604
|
return this.#parse(args, shortCircuit, _parseFn);
|
|
605
|
+
// burgee: --json and the seam are per parse. What this parse turns on (json, an exit
|
|
606
|
+
// already reported) is put back afterwards, so the next parse starts as the program left it.
|
|
596
607
|
const before = this.#burgee === undefined ? undefined : { ...this.#burgee };
|
|
597
608
|
const restore = () => {
|
|
598
609
|
this.#burgee = before;
|
|
@@ -611,6 +622,8 @@ export class YargsInstance {
|
|
|
611
622
|
throw err;
|
|
612
623
|
}
|
|
613
624
|
}
|
|
625
|
+
// The seam: the whole run settles to one E1 exit. yargs reports its own failures
|
|
626
|
+
// through exit(); a handler that throws synchronously is the one thing that escapes it.
|
|
614
627
|
seam.exited = false;
|
|
615
628
|
const finish = (argv) => {
|
|
616
629
|
if (!this.#burgee?.exited)
|
|
@@ -662,6 +675,8 @@ export class YargsInstance {
|
|
|
662
675
|
if (!shortCircuit) {
|
|
663
676
|
const served = this.#burgeeSurface(args);
|
|
664
677
|
if (served !== false) {
|
|
678
|
+
// A surface was (or is being) served: the argv handed back is the short-circuit parse,
|
|
679
|
+
// as after --help. Completions and --mcp load lazily, so those two return a promise.
|
|
665
680
|
const settle = () => {
|
|
666
681
|
const argv = this.#runYargsParserAndExecuteCommands(args, true);
|
|
667
682
|
this.#unfreeze();
|
|
@@ -905,6 +920,7 @@ export class YargsInstance {
|
|
|
905
920
|
delete argv['--'];
|
|
906
921
|
}
|
|
907
922
|
catch {
|
|
923
|
+
// a frozen argv keeps its `--`; yargs ignores the failure
|
|
908
924
|
}
|
|
909
925
|
return argv;
|
|
910
926
|
}
|
|
@@ -925,6 +941,8 @@ export class YargsInstance {
|
|
|
925
941
|
const burgee = this.#burgee;
|
|
926
942
|
const line = args.join(' ');
|
|
927
943
|
if (burgee?.json) {
|
|
944
|
+
// Under --json the failure is one envelope on stdout; the help screen and the
|
|
945
|
+
// message yargs prints on the way are kept only as the envelope's message.
|
|
928
946
|
if (line.trim() !== '')
|
|
929
947
|
burgee.lastError = line;
|
|
930
948
|
}
|
|
@@ -1042,6 +1060,7 @@ export class YargsInstance {
|
|
|
1042
1060
|
obj = JSON.parse(this.#shim.readFileSync(pkgJsonPath, 'utf8'));
|
|
1043
1061
|
}
|
|
1044
1062
|
catch {
|
|
1063
|
+
// no package.json above: version reads 'unknown', as upstream
|
|
1045
1064
|
}
|
|
1046
1065
|
this.#pkgs[npath] = obj || {};
|
|
1047
1066
|
return this.#pkgs[npath];
|
|
@@ -1135,19 +1154,32 @@ export class YargsInstance {
|
|
|
1135
1154
|
runHandler: this.#runHandler.bind(this),
|
|
1136
1155
|
};
|
|
1137
1156
|
}
|
|
1157
|
+
// ───── burgee: additive, and guarded so a program that asks for none of it runs as on yargs ─────
|
|
1158
|
+
/**
|
|
1159
|
+
* The manifest every surface reads (J7, J8). Projected on each access from what the
|
|
1160
|
+
* program registered; a command's builder is run on a scratch instance to learn its
|
|
1161
|
+
* options, exactly as yargs' own completion does. Plugin-contributed nodes are kept.
|
|
1162
|
+
*/
|
|
1138
1163
|
get manifest() {
|
|
1139
1164
|
this.#manifest ??= new Manifest();
|
|
1140
1165
|
projectManifest(this.#manifest, this.#snapshot());
|
|
1141
1166
|
return this.#manifest;
|
|
1142
1167
|
}
|
|
1168
|
+
/** burgee: declare what the command does to the world (N6); what exposes it as an MCP tool (N2). */
|
|
1143
1169
|
effects(value) {
|
|
1144
1170
|
this.#effects = value;
|
|
1145
1171
|
return this;
|
|
1146
1172
|
}
|
|
1173
|
+
/** Additive: plugins yargs never had. `preRun`/`postRun` fire around every handler. */
|
|
1147
1174
|
use(plugin) {
|
|
1148
1175
|
this.manifest.use(plugin);
|
|
1149
1176
|
return this;
|
|
1150
1177
|
}
|
|
1178
|
+
/**
|
|
1179
|
+
* Inject the streams and the exit for this instance (T1). Output goes to `stdout`/`stderr`
|
|
1180
|
+
* instead of the console, and `exit` receives an E1 code: OK for help and version, USAGE
|
|
1181
|
+
* for a validation failure, RUNTIME for a handler that threw.
|
|
1182
|
+
*/
|
|
1151
1183
|
burgee(seam) {
|
|
1152
1184
|
this.#burgee = { ...(this.#burgee ?? { json: false, lastError: '' }), ...seam };
|
|
1153
1185
|
return this;
|
|
@@ -1160,6 +1192,7 @@ export class YargsInstance {
|
|
|
1160
1192
|
let positionals = { demanded: [], optional: [] };
|
|
1161
1193
|
let hasHandler = false;
|
|
1162
1194
|
let description;
|
|
1195
|
+
// The default command (`$0`, `*`) is the root's own handler, not a child path.
|
|
1163
1196
|
const isDefault = (h) => /^\$0( |$)/.test(h.original);
|
|
1164
1197
|
for (const [name, handler] of Object.entries(handlers)) {
|
|
1165
1198
|
if (isDefault(handler))
|
|
@@ -1201,6 +1234,7 @@ export class YargsInstance {
|
|
|
1201
1234
|
commands,
|
|
1202
1235
|
};
|
|
1203
1236
|
}
|
|
1237
|
+
/** A command's snapshot: what its builder registered on the scratch, plus the command string's positionals. */
|
|
1204
1238
|
#snapshotOf(handler, name) {
|
|
1205
1239
|
const snap = this.#snapshot();
|
|
1206
1240
|
snap.name = name;
|
|
@@ -1210,6 +1244,7 @@ export class YargsInstance {
|
|
|
1210
1244
|
snap.version = undefined;
|
|
1211
1245
|
return snap;
|
|
1212
1246
|
}
|
|
1247
|
+
/** Run a command's builder on a fresh instance, as yargs' completion does, and hand that instance back. */
|
|
1213
1248
|
#childOf(handler) {
|
|
1214
1249
|
const child = new _a([], this.#cwd, this.#parentRequire, this.#shim);
|
|
1215
1250
|
child.#context.fullCommands.push(handler.original);
|
|
@@ -1226,9 +1261,11 @@ export class YargsInstance {
|
|
|
1226
1261
|
}
|
|
1227
1262
|
}
|
|
1228
1263
|
catch {
|
|
1264
|
+
// A builder that cannot run outside a parse projects only the command string.
|
|
1229
1265
|
}
|
|
1230
1266
|
return child;
|
|
1231
1267
|
}
|
|
1268
|
+
/** `--json` that the program did not declare is burgee's envelope, not an unknown option. */
|
|
1232
1269
|
#takeJson(args) {
|
|
1233
1270
|
const list = typeof args === 'string' ? tokenizeArgString(args) : args;
|
|
1234
1271
|
const terminator = list.indexOf('--');
|
|
@@ -1240,6 +1277,11 @@ export class YargsInstance {
|
|
|
1240
1277
|
this.#burgee = { ...(this.#burgee ?? { lastError: '' }), json: true };
|
|
1241
1278
|
return [...list.slice(0, index), ...list.slice(index + 1)];
|
|
1242
1279
|
}
|
|
1280
|
+
/**
|
|
1281
|
+
* Whether the program declared an option or command by this name — at the root, or in
|
|
1282
|
+
* any command's builder, which the manifest projection runs to find out. Any command in
|
|
1283
|
+
* the tree that declares the flag keeps it: the surface is additive only.
|
|
1284
|
+
*/
|
|
1243
1285
|
#declares(key) {
|
|
1244
1286
|
if (this.#options.key[key] || Object.values(this.#options.alias).some((list) => list.includes(key)))
|
|
1245
1287
|
return true;
|
|
@@ -1247,12 +1289,17 @@ export class YargsInstance {
|
|
|
1247
1289
|
return true;
|
|
1248
1290
|
return this.manifest.commands.some((node) => Object.prototype.hasOwnProperty.call(node.options, key));
|
|
1249
1291
|
}
|
|
1292
|
+
/**
|
|
1293
|
+
* `--schema`, `--mcp` and `completion <shell>` on a yargs-syntax program, from its
|
|
1294
|
+
* manifest (J2). Only when the program declares none of them itself; `--schema` is
|
|
1295
|
+
* synchronous, the other two load lazily and return a promise.
|
|
1296
|
+
*/
|
|
1250
1297
|
#burgeeSurface(args) {
|
|
1251
1298
|
const list = typeof args === 'string' ? tokenizeArgString(args) : args;
|
|
1252
1299
|
const terminator = list.indexOf('--');
|
|
1253
1300
|
const head = terminator === -1 ? list : list.slice(0, terminator);
|
|
1254
1301
|
if (head[0] === 'completion' && this.#completionCommand === null && !this.#declares('completion')) {
|
|
1255
|
-
return import('
|
|
1302
|
+
return import('../completions.js').then(({ renderCompletion, renderFigSpec, SHELLS }) => {
|
|
1256
1303
|
const shell = head[1] ?? '';
|
|
1257
1304
|
if (shell === 'fig') {
|
|
1258
1305
|
this.#logger.log(JSON.stringify(renderFigSpec(this.manifest), null, 2));
|
|
@@ -1295,6 +1342,7 @@ export class YargsInstance {
|
|
|
1295
1342
|
}
|
|
1296
1343
|
return false;
|
|
1297
1344
|
}
|
|
1345
|
+
/** The handler, wrapped in the plugin hooks and followed by the envelope or the rendering. */
|
|
1298
1346
|
#runHandler(handler, argv, original) {
|
|
1299
1347
|
const manifest = this.#manifest;
|
|
1300
1348
|
const settle = (value) => {
|
|
@@ -1335,6 +1383,7 @@ export class YargsInstance {
|
|
|
1335
1383
|
const code = err instanceof YError || err === undefined || typeof err === 'string' ? 'usage' : 'runtime';
|
|
1336
1384
|
this.#logger.log(JSON.stringify({ ok: false, error: { code, message } }));
|
|
1337
1385
|
}
|
|
1386
|
+
/** burgee: where every option value came from (V3), from yargs-parser's own bookkeeping where it keeps any. */
|
|
1338
1387
|
#provenance(argv) {
|
|
1339
1388
|
const out = {};
|
|
1340
1389
|
const defaulted = this.parsed?.defaulted ?? {};
|
|
@@ -1604,3 +1653,4 @@ _a = YargsInstance;
|
|
|
1604
1653
|
export function isYargsInstance(y) {
|
|
1605
1654
|
return !!y && typeof y.getInternalMethods === 'function';
|
|
1606
1655
|
}
|
|
1656
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* yargs' middleware — global, per-command, and the coerce middleware `.coerce()`
|
|
3
|
+
* registers — ported for `burgee/yargs`.
|
|
4
|
+
*/
|
|
5
|
+
import { argsert, isPromise } from './utils.js';
|
|
2
6
|
export class GlobalMiddleware {
|
|
3
7
|
globalMiddleware = [];
|
|
4
8
|
frozens = [];
|
|
@@ -79,3 +83,4 @@ export function applyMiddleware(argv, yargs, middlewares, beforeValidation) {
|
|
|
79
83
|
return isPromise(result) ? result.then((middlewareObj) => Object.assign(acc, middlewareObj)) : Object.assign(acc, result);
|
|
80
84
|
}, argv);
|
|
81
85
|
}
|
|
86
|
+
//# sourceMappingURL=middleware.js.map
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
import { readdirSync, readFileSync } from 'node:fs';
|
|
8
8
|
import { basename, dirname, extname, join, relative, resolve } from 'node:path';
|
|
9
9
|
import { inspect } from 'node:util';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { type Y18N } from './
|
|
10
|
+
import { Parser } from '../yargs-parser.js';
|
|
11
|
+
import { cliui } from './cliui.js';
|
|
12
|
+
import { type Y18N } from './y18n.js';
|
|
13
13
|
export interface PlatformShim {
|
|
14
14
|
assert: {
|
|
15
15
|
notStrictEqual: (a: any, b: any, m?: string) => void;
|
|
@@ -1,15 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* yargs' Node platform shim — the one object every yargs module reaches the platform
|
|
3
|
+
* through — built from burgee's own ports of its dependencies (J9). Anything that
|
|
4
|
+
* yargs 18 took from `cliui`, `escalade`, `get-caller-file`, `string-width`, `y18n`
|
|
5
|
+
* and `yargs-parser` is served from here.
|
|
6
|
+
*/
|
|
1
7
|
import { readdirSync, readFileSync, statSync } from 'node:fs';
|
|
2
8
|
import { createRequire } from 'node:module';
|
|
3
9
|
import { basename, dirname, extname, join, relative, resolve } from 'node:path';
|
|
4
10
|
import { fileURLToPath } from 'node:url';
|
|
5
11
|
import { inspect } from 'node:util';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { getProcessArgvBin } from './
|
|
9
|
-
import { y18n } from './
|
|
12
|
+
import { Parser } from '../yargs-parser.js';
|
|
13
|
+
import { cliui, stringWidth } from './cliui.js';
|
|
14
|
+
import { getProcessArgvBin } from './utils.js';
|
|
15
|
+
import { y18n } from './y18n.js';
|
|
10
16
|
const here = fileURLToPath(import.meta.url);
|
|
11
17
|
const mainFilename = here.substring(0, here.lastIndexOf('node_modules'));
|
|
12
18
|
const nodeRequire = createRequire(import.meta.url);
|
|
19
|
+
/** escalade/sync: walk up from `start`, asking `callback` at each directory. */
|
|
13
20
|
function findUp(start, callback) {
|
|
14
21
|
let dir = resolve('.', start);
|
|
15
22
|
let tmp;
|
|
@@ -27,6 +34,7 @@ function findUp(start, callback) {
|
|
|
27
34
|
}
|
|
28
35
|
return undefined;
|
|
29
36
|
}
|
|
37
|
+
/** get-caller-file: the file that called the function that called this (v8 stack). */
|
|
30
38
|
function getCallerFile(position = 2) {
|
|
31
39
|
if (position >= Error.stackTraceLimit) {
|
|
32
40
|
throw new TypeError(`getCallerFile(position) requires position be less then Error.stackTraceLimit but position was: \`${position}\` and Error.stackTraceLimit was: \`${Error.stackTraceLimit}\``);
|
|
@@ -49,6 +57,16 @@ function strictEqual(actual, expected, message) {
|
|
|
49
57
|
if (actual !== expected)
|
|
50
58
|
throw new Error(message ?? `Expected values to be strictly equal:\n\n${inspect(actual)} !== ${inspect(expected)}\n`);
|
|
51
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Where the 29 locale files live: the package root, not beside this file.
|
|
62
|
+
*
|
|
63
|
+
* This was `resolve(dirname(here), '../locales')`, which was right only while this file sat
|
|
64
|
+
* directly in `dist/`. The first directory added under `src/` made it `dist/locales`, y18n
|
|
65
|
+
* returned the key for every string, and 14 of yargs' own 804 tests failed. Walking up to
|
|
66
|
+
* `package.json` resolves the same from `src/`, from `dist/`, and from
|
|
67
|
+
* `node_modules/burgee/dist/` once published — so a later move cannot repeat it.
|
|
68
|
+
*/
|
|
69
|
+
const locales = resolve(dirname(findUp(here, (_dir, names) => (names.includes('package.json') ? 'package.json' : undefined)) ?? here), 'locales');
|
|
52
70
|
export const shim = {
|
|
53
71
|
assert: { notStrictEqual, strictEqual },
|
|
54
72
|
cliui,
|
|
@@ -80,5 +98,6 @@ export const shim = {
|
|
|
80
98
|
return /^file:\/\//.exec(callerFile) ? fileURLToPath(callerFile) : callerFile;
|
|
81
99
|
},
|
|
82
100
|
stringWidth,
|
|
83
|
-
y18n: y18n({ directory:
|
|
101
|
+
y18n: y18n({ directory: locales, updateFiles: false }),
|
|
84
102
|
};
|
|
103
|
+
//# sourceMappingURL=shim.js.map
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* version string — ported for `burgee/yargs`. Help is rendered through the cliui port,
|
|
4
4
|
* so yargs' usage tests compare whole screens byte for byte.
|
|
5
5
|
*/
|
|
6
|
-
import type { PlatformShim } from './
|
|
6
|
+
import type { PlatformShim } from './shim.js';
|
|
7
7
|
export type FailureFunction = (msg: string | undefined | null, err: Error | undefined, usage: UsageInstance) => void;
|
|
8
8
|
export interface UsageInstance {
|
|
9
9
|
failFn: (f: FailureFunction | boolean) => void;
|