@camunda8/cli 4.2.0 → 4.2.1-alpha.2
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/PLUGIN-HELP.md +93 -7
- package/dist/commands/plugins.d.ts.map +1 -1
- package/dist/commands/plugins.js +22 -3
- package/dist/commands/plugins.js.map +1 -1
- package/dist/commands/process-instances.d.ts.map +1 -1
- package/dist/commands/process-instances.js +9 -17
- package/dist/commands/process-instances.js.map +1 -1
- package/dist/default-plugins/cluster/c8ctl-plugin.js +92 -86
- package/dist/framework/argv-parser.d.ts +182 -0
- package/dist/framework/argv-parser.d.ts.map +1 -0
- package/dist/framework/argv-parser.js +488 -0
- package/dist/framework/argv-parser.js.map +1 -0
- package/dist/framework/command-registry.d.ts +14 -8
- package/dist/framework/command-registry.d.ts.map +1 -1
- package/dist/framework/command-registry.js +18 -13
- package/dist/framework/command-registry.js.map +1 -1
- package/dist/framework/index.d.ts +2 -0
- package/dist/framework/index.d.ts.map +1 -1
- package/dist/framework/index.js +2 -0
- package/dist/framework/index.js.map +1 -1
- package/dist/framework/plugins/plugin-flags.d.ts +46 -0
- package/dist/framework/plugins/plugin-flags.d.ts.map +1 -0
- package/dist/framework/plugins/plugin-flags.js +80 -0
- package/dist/framework/plugins/plugin-flags.js.map +1 -0
- package/dist/framework/plugins/plugin-loader.d.ts +17 -0
- package/dist/framework/plugins/plugin-loader.d.ts.map +1 -1
- package/dist/framework/plugins/plugin-loader.js +32 -1
- package/dist/framework/plugins/plugin-loader.js.map +1 -1
- package/dist/framework/ui/completion.d.ts.map +1 -1
- package/dist/framework/ui/completion.js +12 -3
- package/dist/framework/ui/completion.js.map +1 -1
- package/dist/framework/ui/help.d.ts.map +1 -1
- package/dist/framework/ui/help.js +8 -0
- package/dist/framework/ui/help.js.map +1 -1
- package/dist/index.d.ts +0 -23
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +186 -310
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -28,7 +28,11 @@ import { fileURLToPath } from 'node:url';
|
|
|
28
28
|
// Version aliases – dynamic discovery with package.json fallback
|
|
29
29
|
// ---------------------------------------------------------------------------
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
// C8CTL_C8RUN_DOWNLOAD_URL overrides the download center base URL (e.g. for
|
|
32
|
+
// mirrors or tests that must not depend on network access).
|
|
33
|
+
const DOWNLOAD_BASE_URL = (
|
|
34
|
+
process.env.C8CTL_C8RUN_DOWNLOAD_URL || 'https://downloads.camunda.cloud/release/camunda/c8run/'
|
|
35
|
+
).replace(/\/*$/, '/');
|
|
32
36
|
|
|
33
37
|
const _pluginPackageJson = JSON.parse(
|
|
34
38
|
readFileSync(join(dirname(fileURLToPath(import.meta.url)), 'package.json'), 'utf-8'),
|
|
@@ -313,6 +317,23 @@ export const metadata = {
|
|
|
313
317
|
'cluster': {
|
|
314
318
|
description:
|
|
315
319
|
'Manage local Camunda 8 cluster — start, stop, status, logs, install, delete, or list versions',
|
|
320
|
+
// A bare-function plugin command only receives parsed positionals from
|
|
321
|
+
// the host; every flag it does not declare is dropped before the handler
|
|
322
|
+
// runs. This command needs raw flags for two reasons: its own
|
|
323
|
+
// --purge / --debug / --c8-version, and the arbitrary flags `cluster
|
|
324
|
+
// secrets` forwards to c8run (--stdin, --all, ...). `passthrough` is the
|
|
325
|
+
// supported way to receive them — the host strips only c8ctl's global
|
|
326
|
+
// flags (--profile, --json, --yes, ...) and forwards everything else
|
|
327
|
+
// verbatim. A command cannot combine `passthrough` with declared `flags`,
|
|
328
|
+
// so the subcommand flags are documented via `flagsHint` instead.
|
|
329
|
+
passthrough: true,
|
|
330
|
+
passthroughHint:
|
|
331
|
+
'--purge, --debug and --c8-version are read by the plugin; everything after `secrets` is forwarded to c8run',
|
|
332
|
+
flagsHint: [
|
|
333
|
+
'--c8-version <version> Camunda version, alias or major.minor (alternative to the positional <version>)',
|
|
334
|
+
'--debug (start, stop) Stream raw c8run output',
|
|
335
|
+
'--purge (stop only) Also delete runtime data after stopping',
|
|
336
|
+
],
|
|
316
337
|
subcommands: [
|
|
317
338
|
{ name: 'start', description: 'Start local Camunda 8 cluster' },
|
|
318
339
|
{ name: 'stop', description: 'Stop local Camunda 8 cluster' },
|
|
@@ -467,7 +488,7 @@ function formatLocalVersionsHint(cacheDir) {
|
|
|
467
488
|
|
|
468
489
|
function getDownloadUrl(version) {
|
|
469
490
|
const platformInfo = getPlatformIdentifier();
|
|
470
|
-
return
|
|
491
|
+
return `${DOWNLOAD_BASE_URL}${version}/camunda8-run-${version}-${platformInfo.platform}-${platformInfo.arch}.${platformInfo.extension}`;
|
|
471
492
|
}
|
|
472
493
|
|
|
473
494
|
async function downloadC8Run(config) {
|
|
@@ -491,7 +512,8 @@ async function downloadC8Run(config) {
|
|
|
491
512
|
throw new Error(
|
|
492
513
|
`Cannot reach the Camunda Download Center.\n` +
|
|
493
514
|
`URL: ${downloadUrl}\n` +
|
|
494
|
-
`Error: ${error.message}\n
|
|
515
|
+
`Error: ${error.message}\n` +
|
|
516
|
+
`Please check your network connection and proxy settings, then try again.\n\n` +
|
|
495
517
|
formatLocalVersionsHint(cacheDir),
|
|
496
518
|
);
|
|
497
519
|
});
|
|
@@ -1152,7 +1174,10 @@ export function processStartSignature(pid) {
|
|
|
1152
1174
|
`$p = Get-CimInstance Win32_Process -Filter "ProcessId=${pid}"; ` +
|
|
1153
1175
|
`if ($p) { $p.CreationDate.ToString('o') }`,
|
|
1154
1176
|
],
|
|
1155
|
-
|
|
1177
|
+
// PowerShell start-up plus a CIM query can exceed 5 s on a loaded
|
|
1178
|
+
// machine; a timeout yields no signature, which makes a live orphan
|
|
1179
|
+
// look stopped, so allow a generous budget.
|
|
1180
|
+
{ encoding: 'utf-8', timeout: 10000 },
|
|
1156
1181
|
).trim();
|
|
1157
1182
|
return out ? `win:${out}` : null;
|
|
1158
1183
|
}
|
|
@@ -1539,6 +1564,18 @@ export function hasRunningClusterPidfiles(cacheDir) {
|
|
|
1539
1564
|
return liveRecordedPids(cacheDir).length > 0;
|
|
1540
1565
|
}
|
|
1541
1566
|
|
|
1567
|
+
// `c8run stop` only signals the cluster processes; Java can keep running for a
|
|
1568
|
+
// while as it shuts down. Wait for them to exit so a follow-up purge does not
|
|
1569
|
+
// mistake a shutting-down cluster for a live one. The timeout is a safety net.
|
|
1570
|
+
export async function waitForClusterExit(cacheDir, { timeoutMs = 60_000, intervalMs = 250 } = {}) {
|
|
1571
|
+
const deadline = Date.now() + timeoutMs;
|
|
1572
|
+
while (hasRunningClusterPidfiles(cacheDir)) {
|
|
1573
|
+
if (Date.now() >= deadline) return false;
|
|
1574
|
+
await sleep(intervalMs);
|
|
1575
|
+
}
|
|
1576
|
+
return true;
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1542
1579
|
export async function stopC8Run(config, debug = false) {
|
|
1543
1580
|
const logger = getLogger();
|
|
1544
1581
|
const markerFile = join(config.cacheDir, ACTIVE_MARKER_FILE);
|
|
@@ -1777,87 +1814,25 @@ export async function stopC8Run(config, debug = false) {
|
|
|
1777
1814
|
// it only locates the right c8run binary and forwards the call to it.
|
|
1778
1815
|
// ---------------------------------------------------------------------------
|
|
1779
1816
|
|
|
1780
|
-
// Global c8ctl flags, mirrored from src/framework/command-registry.ts's
|
|
1781
|
-
// GLOBAL_FLAGS (a plugin cannot import src/ — see the layering rules in
|
|
1782
|
-
// AGENTS.md). Needed to correctly identify the "cluster secrets" token pair
|
|
1783
|
-
// in raw argv: c8ctl accepts these flags anywhere on the command line, not
|
|
1784
|
-
// just before the verb, so one can legitimately sit between "cluster" and
|
|
1785
|
-
// "secrets" (e.g. `c8ctl cluster --profile prod secrets set KEY --stdin`).
|
|
1786
|
-
const GLOBAL_BOOLEAN_FLAGS = new Set(['--help', '-h', '--dry-run', '--verbose', '--json', '--yes', '-y']);
|
|
1787
|
-
const GLOBAL_STRING_FLAGS = new Set(['--profile', '--fields', '--version', '-v']);
|
|
1788
|
-
|
|
1789
|
-
/** True for a recognized global boolean flag token (never consumes a following token). */
|
|
1790
|
-
function isGlobalBooleanFlagToken(token) {
|
|
1791
|
-
return GLOBAL_BOOLEAN_FLAGS.has(token);
|
|
1792
|
-
}
|
|
1793
|
-
|
|
1794
1817
|
/**
|
|
1795
|
-
*
|
|
1796
|
-
*
|
|
1797
|
-
*
|
|
1818
|
+
* `--yes` / `-y` are c8ctl GLOBAL flags, so the host consumes them (it sets
|
|
1819
|
+
* `ctx.yes`) and strips them from a passthrough command's args. c8run's own
|
|
1820
|
+
* `secrets delete` has a `--yes` flag that skips its confirmation prompt, so
|
|
1821
|
+
* restore it when the user asked for it. Scoped to `delete` — the only verb
|
|
1822
|
+
* documented to take it — so it is never appended to a c8run verb that may
|
|
1823
|
+
* not accept the flag. Never mutates `tail`.
|
|
1798
1824
|
*/
|
|
1799
|
-
function
|
|
1800
|
-
const
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
* Recover the raw argv tail that follows "cluster secrets", reading
|
|
1811
|
-
* `argv` (normally `process.argv.slice(2)`) directly instead of the array
|
|
1812
|
-
* the c8ctl host passes to a plugin command. The host's top-level parser
|
|
1813
|
-
* treats an unrecognized flag as a boolean and strips it from the
|
|
1814
|
-
* positionals a plugin receives (see #364 in src/index.ts), which would
|
|
1815
|
-
* silently drop flags like --stdin, --all, and --yes before they ever
|
|
1816
|
-
* reached this plugin.
|
|
1817
|
-
*
|
|
1818
|
-
* Walks argv from the start, skipping recognized global flags (in both
|
|
1819
|
-
* "--flag value" and "--flag=value" form) wherever they appear — including
|
|
1820
|
-
* between "cluster" and "secrets" — until it finds that pair, then returns
|
|
1821
|
-
* everything after it. Falls back to `hostArgs.slice(1)` — the args array a
|
|
1822
|
-
* plugin host actually delivers — only when no such pair is found at all,
|
|
1823
|
-
* e.g. a direct/programmatic call, or "cluster" is followed by some other
|
|
1824
|
-
* verb.
|
|
1825
|
-
*/
|
|
1826
|
-
export function sliceSecretsArgv(argv, hostArgs) {
|
|
1827
|
-
let i = 0;
|
|
1828
|
-
let foundCluster = false;
|
|
1829
|
-
|
|
1830
|
-
while (i < argv.length) {
|
|
1831
|
-
const token = argv[i];
|
|
1832
|
-
|
|
1833
|
-
if (!foundCluster && token === 'cluster') {
|
|
1834
|
-
foundCluster = true;
|
|
1835
|
-
i += 1;
|
|
1836
|
-
continue;
|
|
1837
|
-
}
|
|
1838
|
-
|
|
1839
|
-
if (foundCluster && token === 'secrets') {
|
|
1840
|
-
return argv.slice(i + 1);
|
|
1841
|
-
}
|
|
1842
|
-
|
|
1843
|
-
if (isGlobalBooleanFlagToken(token)) {
|
|
1844
|
-
i += 1;
|
|
1845
|
-
continue;
|
|
1846
|
-
}
|
|
1847
|
-
if (isGlobalStringFlagToken(token)) {
|
|
1848
|
-
i += stringFlagTokenWidth(token);
|
|
1849
|
-
continue;
|
|
1850
|
-
}
|
|
1851
|
-
|
|
1852
|
-
// After "cluster", anything that isn't a recognized global flag and
|
|
1853
|
-
// isn't "secrets" means this isn't the invocation we're looking for
|
|
1854
|
-
// (e.g. "cluster start") — give up and fall back.
|
|
1855
|
-
if (foundCluster) break;
|
|
1856
|
-
|
|
1857
|
-
i += 1;
|
|
1858
|
-
}
|
|
1859
|
-
|
|
1860
|
-
return hostArgs.slice(1);
|
|
1825
|
+
export function withForwardedYes(tail, ctx) {
|
|
1826
|
+
const verbIndex = tail[0]?.startsWith('--c8-version=') ? 1 : tail[0] === '--c8-version' ? 2 : 0;
|
|
1827
|
+
if (ctx?.yes !== true || tail[verbIndex] !== 'delete') return tail;
|
|
1828
|
+
// Everything after a `--` terminator is literal for c8run, so the flag goes
|
|
1829
|
+
// immediately before it, and a `--yes` that only appears after it does not count.
|
|
1830
|
+
const terminator = tail.indexOf('--');
|
|
1831
|
+
const options = terminator < 0 ? tail : tail.slice(0, terminator);
|
|
1832
|
+
if (options.includes('--yes') || options.includes('-y')) return tail;
|
|
1833
|
+
return terminator < 0
|
|
1834
|
+
? [...tail, '--yes']
|
|
1835
|
+
: [...tail.slice(0, terminator), '--yes', ...tail.slice(terminator)];
|
|
1861
1836
|
}
|
|
1862
1837
|
|
|
1863
1838
|
/**
|
|
@@ -2549,6 +2524,18 @@ export function parsePluginArgs(args) {
|
|
|
2549
2524
|
continue;
|
|
2550
2525
|
}
|
|
2551
2526
|
|
|
2527
|
+
if (arg.startsWith('--c8-version=')) {
|
|
2528
|
+
const value = arg.slice('--c8-version='.length);
|
|
2529
|
+
if (!value) {
|
|
2530
|
+
throw new Error(
|
|
2531
|
+
'Missing value for --c8-version. Please provide a version, for example: c8ctl cluster start --c8-version 8.6.0'
|
|
2532
|
+
);
|
|
2533
|
+
}
|
|
2534
|
+
result.version = value;
|
|
2535
|
+
i += 1;
|
|
2536
|
+
continue;
|
|
2537
|
+
}
|
|
2538
|
+
|
|
2552
2539
|
if (arg === '--debug') {
|
|
2553
2540
|
result.debug = true;
|
|
2554
2541
|
i += 1;
|
|
@@ -2587,7 +2574,10 @@ export function parsePluginArgs(args) {
|
|
|
2587
2574
|
const VALID_SUBCOMMANDS = ['start', 'stop', 'status', 'list', 'list-remote', 'install', 'delete', 'purge', 'log', 'logs'];
|
|
2588
2575
|
|
|
2589
2576
|
export const commands = {
|
|
2590
|
-
|
|
2577
|
+
// `cluster` is a passthrough command (see the metadata): `args` is the raw
|
|
2578
|
+
// argv tail after `cluster` with c8ctl's global flags already removed, and
|
|
2579
|
+
// `ctx` is the plugin host context. No need to re-read process.argv.
|
|
2580
|
+
'cluster': async (args, _flags, ctx) => {
|
|
2591
2581
|
const logger = getLogger();
|
|
2592
2582
|
|
|
2593
2583
|
// Secrets passthrough (#314) is intercepted before parsePluginArgs:
|
|
@@ -2596,7 +2586,7 @@ export const commands = {
|
|
|
2596
2586
|
if (args[0] === 'secrets') {
|
|
2597
2587
|
let parsedSecrets;
|
|
2598
2588
|
try {
|
|
2599
|
-
parsedSecrets = parseSecretsArgs(
|
|
2589
|
+
parsedSecrets = parseSecretsArgs(withForwardedYes(args.slice(1), ctx));
|
|
2600
2590
|
} catch (error) {
|
|
2601
2591
|
logger.error(error.message);
|
|
2602
2592
|
process.exit(1);
|
|
@@ -2608,7 +2598,14 @@ export const commands = {
|
|
|
2608
2598
|
return;
|
|
2609
2599
|
}
|
|
2610
2600
|
|
|
2611
|
-
|
|
2601
|
+
let parsed;
|
|
2602
|
+
try {
|
|
2603
|
+
parsed = parsePluginArgs(args);
|
|
2604
|
+
} catch (error) {
|
|
2605
|
+
logger.error(error.message);
|
|
2606
|
+
process.exit(1);
|
|
2607
|
+
return;
|
|
2608
|
+
}
|
|
2612
2609
|
|
|
2613
2610
|
if (!parsed.subcommand || !VALID_SUBCOMMANDS.includes(parsed.subcommand)) {
|
|
2614
2611
|
console.log('Usage:');
|
|
@@ -2820,6 +2817,15 @@ export const commands = {
|
|
|
2820
2817
|
`Version ${stoppedVersion} is no longer installed; its runtime data is already gone. Nothing to purge.`,
|
|
2821
2818
|
);
|
|
2822
2819
|
} else {
|
|
2820
|
+
// C8CTL_STOP_WAIT_TIMEOUT_MS is an internal override so tests can bound the wait.
|
|
2821
|
+
const override = Number(process.env.C8CTL_STOP_WAIT_TIMEOUT_MS);
|
|
2822
|
+
const timeoutMs = Number.isFinite(override) && override > 0 ? override : undefined;
|
|
2823
|
+
if (!(await waitForClusterExit(theCacheDir, { timeoutMs }))) {
|
|
2824
|
+
throw new Error(
|
|
2825
|
+
'Cluster processes are still shutting down, so runtime data was not purged. ' +
|
|
2826
|
+
`Once they have exited, run: c8ctl cluster purge ${stoppedVersion}`,
|
|
2827
|
+
);
|
|
2828
|
+
}
|
|
2823
2829
|
await purgeClusterData(theCacheDir, stoppedVersion);
|
|
2824
2830
|
}
|
|
2825
2831
|
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Two-stage command-line parser.
|
|
3
|
+
*
|
|
4
|
+
* ```
|
|
5
|
+
* c8ctl [global flags] <verb> [<resource>] [verb flags + post-verb globals] [args]
|
|
6
|
+
* ```
|
|
7
|
+
*
|
|
8
|
+
* - **Stage 1** ({@link splitGlobals}) parses `GLOBAL_FLAGS` only, walking the
|
|
9
|
+
* argv from the start, and stops at the first positional — the verb. Every
|
|
10
|
+
* token after the verb is returned untouched (`rest`) so stage 2 can parse
|
|
11
|
+
* it against the flag table of *that* command.
|
|
12
|
+
* - **Stage 2** ({@link parseBuiltinVerbArgs} for built-in verbs, or
|
|
13
|
+
* {@link parseFlags} with a caller-built table for plugin verbs) parses
|
|
14
|
+
* `rest` against `GLOBAL_FLAGS ∪ effectiveFlags(verb, resource)`. Globals
|
|
15
|
+
* stay accepted after the verb (the lenient variant), so
|
|
16
|
+
* `c8ctl list pi --json` keeps working.
|
|
17
|
+
*
|
|
18
|
+
* Because each command is parsed against its own table, a flag name can mean
|
|
19
|
+
* different things on different commands without any handler re-reading
|
|
20
|
+
* `process.argv`: `--variables` is boolean for `get pi` and a string for
|
|
21
|
+
* `create pi`; `--version` is a boolean global before the verb (show the CLI
|
|
22
|
+
* version) and the string definition-version filter after `list pi`.
|
|
23
|
+
*
|
|
24
|
+
* This module also owns the raw-argv helpers the host needs for plugin
|
|
25
|
+
* commands (global-flag stripping for passthrough plugins, blocked-flag
|
|
26
|
+
* stripping for the plugin flag re-parse), so there is one place that knows
|
|
27
|
+
* how to walk flag tokens.
|
|
28
|
+
*/
|
|
29
|
+
import { parseArgs } from "node:util";
|
|
30
|
+
/** One entry of a `node:util` `parseArgs` options table. */
|
|
31
|
+
export interface ParseOption {
|
|
32
|
+
type: "string" | "boolean";
|
|
33
|
+
short?: string;
|
|
34
|
+
multiple?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/** A `parseArgs` options table. Null-prototype so flag names like `__proto__` are inert. */
|
|
37
|
+
export type ParseOptions = Record<string, ParseOption>;
|
|
38
|
+
/** Values produced by `parseArgs` with `strict: false`. */
|
|
39
|
+
export type ParsedValues = Record<string, string | boolean | (string | boolean)[] | undefined>;
|
|
40
|
+
/** A token as reported by `parseArgs({ tokens: true })`. */
|
|
41
|
+
export type ArgToken = NonNullable<ReturnType<typeof parseArgs>["tokens"]>[number];
|
|
42
|
+
/** `GLOBAL_FLAGS` exactly as declared (`--version` is a string: the post-verb definition-version filter). */
|
|
43
|
+
export declare function globalOptions(): ParseOptions;
|
|
44
|
+
/**
|
|
45
|
+
* The one place `parseArgs` is called for command-line parsing. Lenient
|
|
46
|
+
* (`strict: false`): unknown flags never throw — they are reported later as
|
|
47
|
+
* warnings by the unknown-flag detector.
|
|
48
|
+
*/
|
|
49
|
+
export declare function parseFlags({ args, options, }: {
|
|
50
|
+
args: readonly string[];
|
|
51
|
+
options: ParseOptions;
|
|
52
|
+
}): {
|
|
53
|
+
values: ParsedValues;
|
|
54
|
+
positionals: string[];
|
|
55
|
+
tokens: ArgToken[];
|
|
56
|
+
};
|
|
57
|
+
/** A flag found before the verb that is not a global flag. */
|
|
58
|
+
export interface MisplacedFlag {
|
|
59
|
+
/** The token exactly as typed, e.g. `--limit` or `--limit=5`. */
|
|
60
|
+
token: string;
|
|
61
|
+
/** Flag name without dashes (`limit`, or `x` for `-x`). */
|
|
62
|
+
name: string;
|
|
63
|
+
/** True for the `--name=value` form (the value is part of the token). */
|
|
64
|
+
inlineValue: boolean;
|
|
65
|
+
/** Index of the token in argv. */
|
|
66
|
+
index: number;
|
|
67
|
+
}
|
|
68
|
+
export interface Stage1Result {
|
|
69
|
+
/** Global flags that appeared before the verb. `version` is `true` when `--version` / `-v` was given. */
|
|
70
|
+
globals: ParsedValues;
|
|
71
|
+
/** The raw verb token (may be an alias or a plugin verb), or `undefined` when there is none. */
|
|
72
|
+
verb: string | undefined;
|
|
73
|
+
/** Every argv token after the verb, verbatim. */
|
|
74
|
+
rest: string[];
|
|
75
|
+
/**
|
|
76
|
+
* Non-global flags that appeared before the verb. Only globals are valid
|
|
77
|
+
* there, so the host reports these instead of dispatching: the "verb"
|
|
78
|
+
* stage 1 stopped at may really be such a flag's value.
|
|
79
|
+
*/
|
|
80
|
+
misplaced: MisplacedFlag[];
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Stage 1: parse `GLOBAL_FLAGS` from the front of `argv` and stop at the
|
|
84
|
+
* verb. A `--` terminator is skipped, so `c8ctl -- list pi` still dispatches
|
|
85
|
+
* `list`; a `--` after the verb is left in `rest` for stage 2.
|
|
86
|
+
*/
|
|
87
|
+
export declare function splitGlobals(argv: readonly string[]): Stage1Result;
|
|
88
|
+
/**
|
|
89
|
+
* `effectiveFlags(verb, resource)` as stage 2 parses it: the globals, the
|
|
90
|
+
* verb-level flags, and the flag bucket of `resource` only — never the
|
|
91
|
+
* buckets of sibling resources.
|
|
92
|
+
*/
|
|
93
|
+
export declare function stage2Options({ verb, resource, }: {
|
|
94
|
+
verb: string;
|
|
95
|
+
resource: string;
|
|
96
|
+
}): ParseOptions;
|
|
97
|
+
export interface VerbArgs {
|
|
98
|
+
/** Canonical verb (aliases resolved). */
|
|
99
|
+
verb: string;
|
|
100
|
+
/** The resource as typed (alias/plural form), or `""`. */
|
|
101
|
+
resource: string;
|
|
102
|
+
/** The canonical resource name, or `""`. */
|
|
103
|
+
normalizedResource: string;
|
|
104
|
+
/** Positionals after the resource. */
|
|
105
|
+
args: string[];
|
|
106
|
+
/** Post-verb flag values (globals included). */
|
|
107
|
+
values: ParsedValues;
|
|
108
|
+
/** The parse tokens of the post-verb argv (spelling as typed). */
|
|
109
|
+
tokens: ArgToken[];
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Stage 2: find the resource, pick `effectiveFlags(verb, resource)`, and
|
|
113
|
+
* parse `rest` against exactly that table.
|
|
114
|
+
*
|
|
115
|
+
* A verb that is not in the registry (a plugin verb, the reserved `help` /
|
|
116
|
+
* `menu` verbs, or a typo) is parsed against `GLOBAL_FLAGS` alone: a plugin's
|
|
117
|
+
* own flags are re-parsed from `rest` by the host once it has loaded the
|
|
118
|
+
* plugin's flag declarations.
|
|
119
|
+
*/
|
|
120
|
+
export declare function parseVerbArgs({ rawVerb, rest, }: {
|
|
121
|
+
rawVerb: string;
|
|
122
|
+
rest: readonly string[];
|
|
123
|
+
}): VerbArgs;
|
|
124
|
+
/**
|
|
125
|
+
* Strip GLOBAL_FLAGS (and the value of any string-typed global flag) from
|
|
126
|
+
* the argv tail forwarded to a passthrough plugin handler.
|
|
127
|
+
* GLOBAL_FLAGS already affect the c8ctl runtime via their regular handling in
|
|
128
|
+
* `main()`; the plugin must not see them again.
|
|
129
|
+
*
|
|
130
|
+
* Conservative behaviour: an isolated `--` terminator is preserved and
|
|
131
|
+
* everything after it is forwarded verbatim, matching POSIX convention.
|
|
132
|
+
*/
|
|
133
|
+
export declare function stripGlobalFlags(argv: readonly string[]): string[];
|
|
134
|
+
/**
|
|
135
|
+
* Remove tokens for blocked plugin flags from an argv slice so they cannot
|
|
136
|
+
* shift positionals during the plugin-flag re-parse.
|
|
137
|
+
*
|
|
138
|
+
* "Blocked" exclusively means "collides with a GLOBAL flag".
|
|
139
|
+
* The user may have supplied a value token (`--name value`) intending
|
|
140
|
+
* either:
|
|
141
|
+
* - the GLOBAL's interpretation (global type === "string"), or
|
|
142
|
+
* - the PLUGIN's interpretation (plugin type === "string", e.g. global
|
|
143
|
+
* is boolean but the plugin declared the same name as string).
|
|
144
|
+
*
|
|
145
|
+
* Either way the value is meaningless to both sides (plugin's flag is
|
|
146
|
+
* blocked; global is consumed by the host elsewhere) and must not leak
|
|
147
|
+
* into the plugin's positional args. Strip the following non-flag token
|
|
148
|
+
* if either side typed the flag as string. A reserved short alias
|
|
149
|
+
* (`reservedShorts`, e.g. a plugin's `-y` that is also c8ctl's `-y`) is
|
|
150
|
+
* stripped the same way.
|
|
151
|
+
*/
|
|
152
|
+
export declare function stripBlockedFlagTokens({ argv, blocked, reservedShorts, pluginFlagDefs, globalFlagDefs, }: {
|
|
153
|
+
argv: readonly string[];
|
|
154
|
+
blocked: ReadonlySet<string>;
|
|
155
|
+
reservedShorts?: readonly {
|
|
156
|
+
name: string;
|
|
157
|
+
short: string;
|
|
158
|
+
}[];
|
|
159
|
+
pluginFlagDefs: Record<string, {
|
|
160
|
+
type: string;
|
|
161
|
+
}>;
|
|
162
|
+
globalFlagDefs: Record<string, {
|
|
163
|
+
type: string;
|
|
164
|
+
short?: string;
|
|
165
|
+
}>;
|
|
166
|
+
}): string[];
|
|
167
|
+
type TypedFlagDefs = Record<string, {
|
|
168
|
+
type: string;
|
|
169
|
+
short?: string;
|
|
170
|
+
} | undefined>;
|
|
171
|
+
/**
|
|
172
|
+
* Error text for non-global flags placed before the command. Names the
|
|
173
|
+
* surface (globals before the command, command flags after it) and, when it
|
|
174
|
+
* can be verified, shows the corrected order.
|
|
175
|
+
*/
|
|
176
|
+
export declare function describeMisplacedFlags({ argv, misplaced, pluginFlags, }: {
|
|
177
|
+
argv: readonly string[];
|
|
178
|
+
misplaced: readonly MisplacedFlag[];
|
|
179
|
+
pluginFlags: Record<string, TypedFlagDefs>;
|
|
180
|
+
}): string;
|
|
181
|
+
export {};
|
|
182
|
+
//# sourceMappingURL=argv-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"argv-parser.d.ts","sourceRoot":"","sources":["../../src/framework/argv-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAatC,4DAA4D;AAC5D,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,4FAA4F;AAC5F,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAEvD,2DAA2D;AAC3D,MAAM,MAAM,YAAY,GAAG,MAAM,CAChC,MAAM,EACN,MAA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