@canonical/summon-core 0.34.0 → 0.36.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/dist/esm/discovery/discoverGeneratorTree.js +14 -10
- package/dist/esm/discovery/discoverGeneratorTree.js.map +1 -1
- package/dist/esm/execute/collectAnswers.js +21 -16
- package/dist/esm/execute/collectAnswers.js.map +1 -1
- package/dist/esm/execute/execute.js +67 -22
- package/dist/esm/execute/execute.js.map +1 -1
- package/dist/esm/execute/index.js +1 -1
- package/dist/esm/execute/index.js.map +1 -1
- package/dist/esm/execute/validateAnswers.js +19 -5
- package/dist/esm/execute/validateAnswers.js.map +1 -1
- package/dist/esm/format/effects.js +197 -51
- package/dist/esm/format/effects.js.map +1 -1
- package/dist/esm/format/formatFlagName.js +17 -0
- package/dist/esm/format/formatFlagName.js.map +1 -0
- package/dist/esm/format/index.js +24 -1
- package/dist/esm/format/index.js.map +1 -1
- package/dist/esm/index.js +3 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/projection/answers.js +84 -0
- package/dist/esm/projection/answers.js.map +1 -0
- package/dist/esm/projection/buildOptionInfo.js +77 -0
- package/dist/esm/projection/buildOptionInfo.js.map +1 -0
- package/dist/esm/projection/commander/configureGroupedHelp.js +39 -0
- package/dist/esm/projection/commander/configureGroupedHelp.js.map +1 -0
- package/dist/esm/projection/commander/emitToProcess.js +15 -0
- package/dist/esm/projection/commander/emitToProcess.js.map +1 -0
- package/dist/esm/projection/commander/index.js +20 -0
- package/dist/esm/projection/commander/index.js.map +1 -0
- package/dist/esm/projection/commander/registerGeneratorCommands.js +222 -0
- package/dist/esm/projection/commander/registerGeneratorCommands.js.map +1 -0
- package/dist/esm/projection/decideInteraction.js +73 -0
- package/dist/esm/projection/decideInteraction.js.map +1 -0
- package/dist/esm/projection/extractAnswers.js +52 -0
- package/dist/esm/projection/extractAnswers.js.map +1 -0
- package/dist/esm/projection/groupedHelp.js +74 -0
- package/dist/esm/projection/groupedHelp.js.map +1 -0
- package/dist/esm/projection/index.js +26 -0
- package/dist/esm/projection/index.js.map +1 -0
- package/dist/esm/projection/kebab.js +18 -0
- package/dist/esm/projection/kebab.js.map +1 -0
- package/dist/esm/projection/projectGenerator.js +46 -0
- package/dist/esm/projection/projectGenerator.js.map +1 -0
- package/dist/esm/projection/types.js +16 -0
- package/dist/esm/projection/types.js.map +1 -0
- package/dist/esm/projection/usage.js +144 -0
- package/dist/esm/projection/usage.js.map +1 -0
- package/dist/esm/prompt/answerPromptWithDefaults.js +7 -5
- package/dist/esm/prompt/answerPromptWithDefaults.js.map +1 -1
- package/dist/esm/prompt/autoPrompt.js +2 -3
- package/dist/esm/prompt/autoPrompt.js.map +1 -1
- package/dist/esm/prompt/ink/Wizard.js +44 -8
- package/dist/esm/prompt/ink/Wizard.js.map +1 -1
- package/dist/esm/prompt/ink/mount.js +20 -8
- package/dist/esm/prompt/ink/mount.js.map +1 -1
- package/dist/esm/prompt/ink/progressWindow.js +131 -3
- package/dist/esm/prompt/ink/progressWindow.js.map +1 -1
- package/dist/esm/prompt/ink/session.js +135 -14
- package/dist/esm/prompt/ink/session.js.map +1 -1
- package/dist/esm/prompt/inkPrompt.js +18 -2
- package/dist/esm/prompt/inkPrompt.js.map +1 -1
- package/dist/esm/prompt/mcpPrompt.js +1 -1
- package/dist/esm/prompt/mcpPrompt.js.map +1 -1
- package/dist/esm/stamp/applyStamp.js +50 -52
- package/dist/esm/stamp/applyStamp.js.map +1 -1
- package/dist/esm/stamp/createStampOnEffectStart.js +4 -1
- package/dist/esm/stamp/createStampOnEffectStart.js.map +1 -1
- package/dist/esm/stamp/runTaskWithStamp.js +8 -9
- package/dist/esm/stamp/runTaskWithStamp.js.map +1 -1
- package/dist/esm/template/index.js +2 -0
- package/dist/esm/template/index.js.map +1 -1
- package/dist/esm/template/loadTemplate.js +43 -0
- package/dist/esm/template/loadTemplate.js.map +1 -0
- package/dist/esm/template/prependStamp.js +11 -8
- package/dist/esm/template/prependStamp.js.map +1 -1
- package/dist/esm/template/rawFile.js +25 -0
- package/dist/esm/template/rawFile.js.map +1 -0
- package/dist/esm/template/tasks/template.js +12 -3
- package/dist/esm/template/tasks/template.js.map +1 -1
- package/dist/esm/template/tasks/templateDir.js +5 -0
- package/dist/esm/template/tasks/templateDir.js.map +1 -1
- package/dist/esm/testing/conformance/fixtures.js +0 -2
- package/dist/esm/testing/conformance/fixtures.js.map +1 -1
- package/dist/esm/testing/conformance/flagizeAnswers.js +91 -0
- package/dist/esm/testing/conformance/flagizeAnswers.js.map +1 -0
- package/dist/esm/testing/conformance/index.js +1 -0
- package/dist/esm/testing/conformance/index.js.map +1 -1
- package/dist/esm/testing/index.js +1 -1
- package/dist/esm/testing/index.js.map +1 -1
- package/dist/types/discovery/discoverGeneratorTree.d.ts +3 -3
- package/dist/types/discovery/discoverGeneratorTree.d.ts.map +1 -1
- package/dist/types/execute/collectAnswers.d.ts +4 -3
- package/dist/types/execute/collectAnswers.d.ts.map +1 -1
- package/dist/types/execute/execute.d.ts +27 -1
- package/dist/types/execute/execute.d.ts.map +1 -1
- package/dist/types/execute/index.d.ts +1 -1
- package/dist/types/execute/index.d.ts.map +1 -1
- package/dist/types/execute/validateAnswers.d.ts.map +1 -1
- package/dist/types/format/effects.d.ts +61 -7
- package/dist/types/format/effects.d.ts.map +1 -1
- package/dist/types/format/formatFlagName.d.ts +14 -0
- package/dist/types/format/formatFlagName.d.ts.map +1 -0
- package/dist/types/format/index.d.ts +21 -1
- package/dist/types/format/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +5 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/projection/answers.d.ts +54 -0
- package/dist/types/projection/answers.d.ts.map +1 -0
- package/dist/types/projection/buildOptionInfo.d.ts +25 -0
- package/dist/types/projection/buildOptionInfo.d.ts.map +1 -0
- package/dist/types/projection/commander/configureGroupedHelp.d.ts +29 -0
- package/dist/types/projection/commander/configureGroupedHelp.d.ts.map +1 -0
- package/dist/types/projection/commander/emitToProcess.d.ts +10 -0
- package/dist/types/projection/commander/emitToProcess.d.ts.map +1 -0
- package/dist/types/projection/commander/index.d.ts +21 -0
- package/dist/types/projection/commander/index.d.ts.map +1 -0
- package/dist/types/projection/commander/registerGeneratorCommands.d.ts +95 -0
- package/dist/types/projection/commander/registerGeneratorCommands.d.ts.map +1 -0
- package/dist/types/projection/decideInteraction.d.ts +70 -0
- package/dist/types/projection/decideInteraction.d.ts.map +1 -0
- package/dist/types/projection/extractAnswers.d.ts +23 -0
- package/dist/types/projection/extractAnswers.d.ts.map +1 -0
- package/dist/types/projection/groupedHelp.d.ts +25 -0
- package/dist/types/projection/groupedHelp.d.ts.map +1 -0
- package/dist/types/projection/index.d.ts +29 -0
- package/dist/types/projection/index.d.ts.map +1 -0
- package/dist/types/projection/kebab.d.ts +16 -0
- package/dist/types/projection/kebab.d.ts.map +1 -0
- package/dist/types/projection/projectGenerator.d.ts +22 -0
- package/dist/types/projection/projectGenerator.d.ts.map +1 -0
- package/dist/types/projection/types.d.ts +118 -0
- package/dist/types/projection/types.d.ts.map +1 -0
- package/dist/types/projection/usage.d.ts +92 -0
- package/dist/types/projection/usage.d.ts.map +1 -0
- package/dist/types/prompt/answerPromptWithDefaults.d.ts +5 -3
- package/dist/types/prompt/answerPromptWithDefaults.d.ts.map +1 -1
- package/dist/types/prompt/autoPrompt.d.ts.map +1 -1
- package/dist/types/prompt/index.d.ts +1 -1
- package/dist/types/prompt/index.d.ts.map +1 -1
- package/dist/types/prompt/ink/Wizard.d.ts.map +1 -1
- package/dist/types/prompt/ink/mount.d.ts +3 -2
- package/dist/types/prompt/ink/mount.d.ts.map +1 -1
- package/dist/types/prompt/ink/progressWindow.d.ts +98 -2
- package/dist/types/prompt/ink/progressWindow.d.ts.map +1 -1
- package/dist/types/prompt/ink/session.d.ts +87 -4
- package/dist/types/prompt/ink/session.d.ts.map +1 -1
- package/dist/types/prompt/inkPrompt.d.ts +36 -2
- package/dist/types/prompt/inkPrompt.d.ts.map +1 -1
- package/dist/types/stamp/applyStamp.d.ts +6 -2
- package/dist/types/stamp/applyStamp.d.ts.map +1 -1
- package/dist/types/stamp/createStampOnEffectStart.d.ts.map +1 -1
- package/dist/types/stamp/runTaskWithStamp.d.ts +3 -1
- package/dist/types/stamp/runTaskWithStamp.d.ts.map +1 -1
- package/dist/types/template/index.d.ts +4 -0
- package/dist/types/template/index.d.ts.map +1 -1
- package/dist/types/template/loadTemplate.d.ts +40 -0
- package/dist/types/template/loadTemplate.d.ts.map +1 -0
- package/dist/types/template/prependStamp.d.ts +5 -2
- package/dist/types/template/prependStamp.d.ts.map +1 -1
- package/dist/types/template/rawFile.d.ts +32 -0
- package/dist/types/template/rawFile.d.ts.map +1 -0
- package/dist/types/template/tasks/template.d.ts +8 -0
- package/dist/types/template/tasks/template.d.ts.map +1 -1
- package/dist/types/template/tasks/templateDir.d.ts.map +1 -1
- package/dist/types/template/tasks/types.d.ts +2 -0
- package/dist/types/template/tasks/types.d.ts.map +1 -1
- package/dist/types/testing/conformance/fixtures.d.ts.map +1 -1
- package/dist/types/testing/conformance/flagizeAnswers.d.ts +38 -0
- package/dist/types/testing/conformance/flagizeAnswers.d.ts.map +1 -0
- package/dist/types/testing/conformance/index.d.ts +1 -0
- package/dist/types/testing/conformance/index.d.ts.map +1 -1
- package/dist/types/testing/index.d.ts +1 -1
- package/dist/types/testing/index.d.ts.map +1 -1
- package/dist/types/types/GeneratorDefinition.d.ts +10 -1
- package/dist/types/types/GeneratorDefinition.d.ts.map +1 -1
- package/dist/types/types/ReservedOption.d.ts +1 -1
- package/dist/types/types/ReservedOption.d.ts.map +1 -1
- package/package.json +22 -9
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Answer-set arithmetic over a command's prompts: apply defaults, decide
|
|
3
|
+
* completeness, and derive the wizard's asking list. `applyDefaults` and
|
|
4
|
+
* `hasAllRequiredAnswers` are moved verbatim from the summon bin;
|
|
5
|
+
* `explicitAnswersComplete` and `pendingPrompts` are the two derived facts the
|
|
6
|
+
* shared interaction decision and the wizards stand on.
|
|
7
|
+
*
|
|
8
|
+
* `pendingPrompts` is the wizard-script parity anchor: BOTH products' wizards
|
|
9
|
+
* ask exactly this list (declared order, explicitly-answered prompts skipped,
|
|
10
|
+
* conditional prompts included — their `when` is evaluated live by the wizard).
|
|
11
|
+
*/
|
|
12
|
+
/** Whether a prompt is conditional (live `when`, or the projected marker). */
|
|
13
|
+
function isConditional(prompt) {
|
|
14
|
+
return prompt.when !== undefined || prompt.conditional === true;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Check if all required prompts have answers.
|
|
18
|
+
*
|
|
19
|
+
* A prompt is required when it is unconditional and has no default; the check
|
|
20
|
+
* passes when every such prompt is present in `answers`.
|
|
21
|
+
*
|
|
22
|
+
* @param prompts - The command's prompts (live or projected).
|
|
23
|
+
* @param answers - The answer set to check (typically defaults already applied).
|
|
24
|
+
* @returns True when no required prompt is missing.
|
|
25
|
+
*/
|
|
26
|
+
export function hasAllRequiredAnswers(prompts, answers) {
|
|
27
|
+
for (const prompt of prompts) {
|
|
28
|
+
if (isConditional(prompt))
|
|
29
|
+
continue;
|
|
30
|
+
if (!Object.hasOwn(answers, prompt.name) && prompt.default === undefined) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Apply defaults for prompts that don't have answers.
|
|
38
|
+
*
|
|
39
|
+
* @param prompts - The command's prompts (live or projected).
|
|
40
|
+
* @param answers - The provided answers (never mutated).
|
|
41
|
+
* @returns A new answer set with declared defaults filled in.
|
|
42
|
+
*/
|
|
43
|
+
export function applyDefaults(prompts, answers) {
|
|
44
|
+
const result = { ...answers };
|
|
45
|
+
for (const prompt of prompts) {
|
|
46
|
+
if (!Object.hasOwn(result, prompt.name) && prompt.default !== undefined) {
|
|
47
|
+
result[prompt.name] = prompt.default;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Whether the EXPLICIT answers alone fully determine a run: every
|
|
54
|
+
* unconditional prompt is explicitly answered (defaults do not count).
|
|
55
|
+
* Conditional prompts are skipped — whether they even apply is a live-wizard
|
|
56
|
+
* question, and every input they could depend on is already pinned.
|
|
57
|
+
*
|
|
58
|
+
* @param prompts - The command's prompts (live or projected).
|
|
59
|
+
* @param explicit - The explicitly provided answers (no defaults).
|
|
60
|
+
* @returns True when nothing would need to be asked or defaulted.
|
|
61
|
+
*/
|
|
62
|
+
export function explicitAnswersComplete(prompts, explicit) {
|
|
63
|
+
for (const prompt of prompts) {
|
|
64
|
+
if (isConditional(prompt))
|
|
65
|
+
continue;
|
|
66
|
+
if (!Object.hasOwn(explicit, prompt.name))
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The prompts a wizard must still ask, in declared order: every prompt not
|
|
73
|
+
* explicitly answered. Conditional prompts are INCLUDED — the live wizard
|
|
74
|
+
* evaluates their `when` against the answers collected so far and skips the
|
|
75
|
+
* inapplicable ones itself.
|
|
76
|
+
*
|
|
77
|
+
* @param prompts - The command's prompts (live or projected).
|
|
78
|
+
* @param explicit - The explicitly provided answers (no defaults).
|
|
79
|
+
* @returns The asking list, a subsequence of `prompts`.
|
|
80
|
+
*/
|
|
81
|
+
export function pendingPrompts(prompts, explicit) {
|
|
82
|
+
return prompts.filter((prompt) => !Object.hasOwn(explicit, prompt.name));
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=answers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"answers.js","sourceRoot":"","sources":["../../../src/projection/answers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,8EAA8E;AAC9E,SAAS,aAAa,CAAC,MAAkB;IACvC,OAAO,MAAM,CAAC,IAAI,K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Ac,CAC5B,OAAqB,EACrB,QAA2C;IAE3C,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;AAC3E,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derive the Commander option for one prompt — the single flag-shape authority
|
|
3
|
+
* both binaries register from (moved verbatim from the summon bin's
|
|
4
|
+
* registration layer).
|
|
5
|
+
*
|
|
6
|
+
* The shapes: a default-`true` confirm registers ONLY its `--no-<kebab>` form
|
|
7
|
+
* (the positive state is the default and needs no flag); a default-`false`
|
|
8
|
+
* confirm registers the positive `--<kebab>`; a select takes `<value>` with its
|
|
9
|
+
* choices listed in the description; a multiselect takes a comma-separated
|
|
10
|
+
* `<values>`; text takes `<value>`.
|
|
11
|
+
*
|
|
12
|
+
* NOTE: defaults are deliberately NOT passed to Commander (`defaultValue` stays
|
|
13
|
+
* unset). Defaults are applied by `applyDefaults()` after answer extraction, so
|
|
14
|
+
* the surface can distinguish "user didn't provide" from "user provided the
|
|
15
|
+
* default value" — which is what keeps explicit answers explicit.
|
|
16
|
+
*/
|
|
17
|
+
import toKebabCase from "./kebab.js";
|
|
18
|
+
/**
|
|
19
|
+
* Build the Commander option metadata for a prompt.
|
|
20
|
+
*
|
|
21
|
+
* @param prompt - The prompt (live or projected).
|
|
22
|
+
* @returns The option's flags, help text, group and name mapping.
|
|
23
|
+
*/
|
|
24
|
+
export default function buildOptionInfo(prompt) {
|
|
25
|
+
const kebabName = toKebabCase(prompt.name);
|
|
26
|
+
const flagName = `--${kebabName}`;
|
|
27
|
+
switch (prompt.type) {
|
|
28
|
+
case "confirm": {
|
|
29
|
+
const defaultVal = prompt.default === true;
|
|
30
|
+
if (defaultVal) {
|
|
31
|
+
return {
|
|
32
|
+
flags: `--no-${kebabName}`,
|
|
33
|
+
description: `${prompt.message}`,
|
|
34
|
+
group: prompt.group,
|
|
35
|
+
promptName: prompt.name,
|
|
36
|
+
kebabName,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
flags: flagName,
|
|
41
|
+
description: `${prompt.message}`,
|
|
42
|
+
group: prompt.group,
|
|
43
|
+
promptName: prompt.name,
|
|
44
|
+
kebabName,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
case "select": {
|
|
48
|
+
const choices = prompt.choices?.map((c) => c.value).join("|") ?? "";
|
|
49
|
+
return {
|
|
50
|
+
flags: `${flagName} <value>`,
|
|
51
|
+
description: `${prompt.message} [${choices}]`,
|
|
52
|
+
group: prompt.group,
|
|
53
|
+
promptName: prompt.name,
|
|
54
|
+
kebabName,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
case "multiselect": {
|
|
58
|
+
return {
|
|
59
|
+
flags: `${flagName} <values>`,
|
|
60
|
+
description: `${prompt.message} (comma-separated)`,
|
|
61
|
+
group: prompt.group,
|
|
62
|
+
promptName: prompt.name,
|
|
63
|
+
kebabName,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
default: {
|
|
67
|
+
return {
|
|
68
|
+
flags: `${flagName} <value>`,
|
|
69
|
+
description: `${prompt.message}`,
|
|
70
|
+
group: prompt.group,
|
|
71
|
+
promptName: prompt.name,
|
|
72
|
+
kebabName,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=buildOptionInfo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildOptionInfo.js","sourceRoot":"","sources":["../../../src/projection/buildOptionInfo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,WAAW,MAAM,YAAY,CAAC;AAGrC;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,MAAkB;IACxD,MAAM,SAAS,GAAG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ClD,KAAK,EAAE,MAAM,CAAC,KAAK;gBACnB,UAAU,EAAE,MAAM,CAAC,IAAI;gBACvB,SAAS;aACV,CAAC;QACJ,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;YACR,OAAO;gBACL,KAAK,EAAE,GAAG,QAAQ,UAAU;gBAC5B,WAAW,EAAE,GAAG,MAAM,CAAC,OAAO,EAAE;gBAChC,KAAK,EAAE,MAAM,CAAC,KAAK;gBACnB,UAAU,EAAE,MAAM,CAAC,IAAI;gBACvB,SAAS;aACV,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The grouped-help INSTALLER — the Commander half of the split: reads the
|
|
3
|
+
* command's usage and description through Commander's help formatter and
|
|
4
|
+
* hands them to the data seam's pure {@link renderGroupedHelp}.
|
|
5
|
+
*
|
|
6
|
+
* Module-internal to the adapter (exported for its tests, never on the
|
|
7
|
+
* subpath index): both hosts reach it only through
|
|
8
|
+
* `registerGeneratorCommands`.
|
|
9
|
+
*/
|
|
10
|
+
import { buildOptionGroups, renderGroupedHelp } from "../groupedHelp.js";
|
|
11
|
+
/**
|
|
12
|
+
* Configure custom help with grouped options for a command. Under the default
|
|
13
|
+
* presentation, a command whose prompts declare no groups (and collapse to at
|
|
14
|
+
* most one) keeps Commander's default help; a host renderer installs
|
|
15
|
+
* UNCONDITIONALLY — the host chose one help style for every leaf, and leaving
|
|
16
|
+
* its ungrouped generators on Commander's default would reintroduce exactly
|
|
17
|
+
* the inconsistency it supplied the renderer to remove.
|
|
18
|
+
*
|
|
19
|
+
* @param cmd - The command to configure.
|
|
20
|
+
* @param prompts - The command's prompts (live or projected).
|
|
21
|
+
* @param hostFlags - The host's standard-flag rows for the global block.
|
|
22
|
+
* @param renderHelp - The host's own presentation, when it supplies one
|
|
23
|
+
* (see `CommanderHost.renderHelp`); omitted means `renderGroupedHelp`.
|
|
24
|
+
* @note Impure — installs a `configureHelp` override on the command.
|
|
25
|
+
*/
|
|
26
|
+
export default function configureGroupedHelp(cmd, prompts, hostFlags, renderHelp) {
|
|
27
|
+
const groups = buildOptionGroups(prompts);
|
|
28
|
+
// The default presentation only takes over when there are grouped options
|
|
29
|
+
if (renderHelp === undefined &&
|
|
30
|
+
groups.size <= 1 &&
|
|
31
|
+
!prompts.some((p) => p.group)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const render = renderHelp ?? renderGroupedHelp;
|
|
35
|
+
cmd.configureHelp({
|
|
36
|
+
formatHelp: (helpCmd, helper) => render(helper.commandUsage(helpCmd), helper.commandDescription(helpCmd), groups, hostFlags),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=configureGroupedHelp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configureGroupedHelp.js","sourceRoot":"","sources":["../../../../src/projection/commander/configureGroupedHelp.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAGzE;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAC1C,GAAY,EACZ,OAA8B,EAC9B,SAAoB,EACpB,UAAqC;IAErC,MAAM,MAAM,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAE1C,0EAA0E;IAC1E,IACE,UAAU,KAAK,SAAS;QACxB,MAAM,CAAC,IAAI,IAAI,CAAC;QAChB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,EAC7B,CAAC;QACD,OAAO;IACT,CAAC;IAED,MAAM,MAAM,GAAG,UAAU,IAAI,iBAAiB,CAAC;IAC/C,GAAG,CAAC,aAAa,CAAC;QAChB,UAAU,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAC9B,MAAM,CACJ,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,EAC5B,MAAM,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAClC,MAAM,EACN,SAAS,CACV;KACJ,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The default {@link MountOutcome} presentation both bins share — the ONLY
|
|
3
|
+
* process-touching export in either projection seam: the parity bytes on
|
|
4
|
+
* stderr, the outcome's code on `process.exitCode`.
|
|
5
|
+
*
|
|
6
|
+
* @note Impure — writes stderr, sets the process exit code.
|
|
7
|
+
*/
|
|
8
|
+
import { renderUsageError } from "../usage.js";
|
|
9
|
+
export default function emitToProcess(outcome) {
|
|
10
|
+
process.stderr.write(outcome.kind === "usage-error"
|
|
11
|
+
? `${renderUsageError(outcome.error)}\n`
|
|
12
|
+
: outcome.help);
|
|
13
|
+
process.exitCode = outcome.exitCode;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=emitToProcess.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitToProcess.js","sourceRoot":"","sources":["../../../../src/projection/commander/emitToProcess.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/C,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,OAAqB;IACzD,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,OAAO,CAAC,IAAI,KAAK,aAAa;QAC5B,CAAC,CAAC,GAAG,gBAAgB,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI;QACxC,CAAC,CAAC,OAAO,CAAC,IAAI,CACjB,CAAC;IACF,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@canonical/summon-core/projection/commander` — the Commander ADAPTER seam.
|
|
3
|
+
*
|
|
4
|
+
* The one registration path both binaries mount their generator grammar
|
|
5
|
+
* through. Everything Commander-shaped lives here; the parser-agnostic data
|
|
6
|
+
* half stays in `@canonical/summon-core/projection`. Every designed
|
|
7
|
+
* non-action outcome (the two usage errors, the bare-namespace help) is
|
|
8
|
+
* delivered to the host's required `emit` sink as a `MountOutcome` — the
|
|
9
|
+
* adapter decides the bytes and the exit code, the host effects them, and
|
|
10
|
+
* `emitToProcess` is the one shared default effect.
|
|
11
|
+
*
|
|
12
|
+
* IMPORT DISCIPLINE (pinned by `lazyGraph.test.ts`): this subpath's runtime
|
|
13
|
+
* graph reaches only `commander` and Node built-ins — never react/ink/ejs/
|
|
14
|
+
* chalk/@canonical/task, and never a summon-core module outside
|
|
15
|
+
* `src/projection/` — so a host may import it statically on its
|
|
16
|
+
* `--help`/`__complete` fast path.
|
|
17
|
+
*/
|
|
18
|
+
export { default as emitToProcess } from "./emitToProcess.js";
|
|
19
|
+
export { default as registerGeneratorCommands } from "./registerGeneratorCommands.js";
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/projection/commander/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAK9D,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,MAAM,gCAAgC,CAAC"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Register a command barrel onto a Commander program — the ONE registration
|
|
3
|
+
* path both binaries mount the generator tree through. The projection owns
|
|
4
|
+
* everything derivable from the prompts: the command spec (`name
|
|
5
|
+
* [kebab-positional]`), the prompt-derived options, the grouped help, the
|
|
6
|
+
* usage line, and the namespace parents. The HOST owns everything host-shaped
|
|
7
|
+
* — its standard flags, its action body, its outcome effects, and
|
|
8
|
+
* (optionally) its namespace behavior — injected through
|
|
9
|
+
* {@link CommanderHost}.
|
|
10
|
+
*
|
|
11
|
+
* Every designed non-action outcome (the two usage errors, the bare-namespace
|
|
12
|
+
* help) is DECIDED here — content and exit code, the parity facts — and
|
|
13
|
+
* DELIVERED to the host's required `emit` sink as a {@link MountOutcome}.
|
|
14
|
+
* Not one write to `process.stderr` or `process.exitCode` happens in this
|
|
15
|
+
* module; the canonical effect both bins share is
|
|
16
|
+
* {@link import("./emitToProcess.js").default}.
|
|
17
|
+
*
|
|
18
|
+
* @note Impure — mutates the Commander program.
|
|
19
|
+
*/
|
|
20
|
+
import buildOptionInfo from "../buildOptionInfo.js";
|
|
21
|
+
import toKebabCase from "../kebab.js";
|
|
22
|
+
import { excessPositionalError, unknownSegmentError, } from "../usage.js";
|
|
23
|
+
import configureGroupedHelp from "./configureGroupedHelp.js";
|
|
24
|
+
/** Add prompt-based options to a Commander command. */
|
|
25
|
+
function addPromptOptions(cmd, prompts) {
|
|
26
|
+
for (const prompt of prompts) {
|
|
27
|
+
const info = buildOptionInfo(prompt);
|
|
28
|
+
cmd.option(info.flags, info.description, info.defaultValue);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** The command's full name chain (root/bin name first, leaf last). */
|
|
32
|
+
function commandChain(cmd) {
|
|
33
|
+
const chain = [];
|
|
34
|
+
let current = cmd;
|
|
35
|
+
while (current) {
|
|
36
|
+
chain.unshift(current.name());
|
|
37
|
+
current = current.parent;
|
|
38
|
+
}
|
|
39
|
+
return chain;
|
|
40
|
+
}
|
|
41
|
+
/** The sibling and child segment sets of one barrel entry. */
|
|
42
|
+
function segmentNeighbours(entry, barrel) {
|
|
43
|
+
const siblings = new Set();
|
|
44
|
+
const children = new Set();
|
|
45
|
+
const parent = entry.path.slice(0, -1).join("/");
|
|
46
|
+
const self = entry.path.join("/");
|
|
47
|
+
for (const other of barrel) {
|
|
48
|
+
const otherParent = other.path.slice(0, -1).join("/");
|
|
49
|
+
const last = other.path[other.path.length - 1];
|
|
50
|
+
if (otherParent === parent && other.path.join("/") !== self) {
|
|
51
|
+
siblings.add(last);
|
|
52
|
+
}
|
|
53
|
+
if (otherParent === self) {
|
|
54
|
+
children.add(last);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return { siblings, children };
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Normalize Commander's action calling convention: the positional value is the
|
|
61
|
+
* first argument only when the command spec declared one, and it counts only
|
|
62
|
+
* when actually given (a non-empty string).
|
|
63
|
+
*
|
|
64
|
+
* Module-internal to the adapter (exported for its tests, never on the
|
|
65
|
+
* subpath index): both hosts reach it only through
|
|
66
|
+
* {@link registerGeneratorCommands}.
|
|
67
|
+
*
|
|
68
|
+
* @param actionArgs - Commander's raw action arguments.
|
|
69
|
+
* @param hasPositional - Whether the command spec declared a positional.
|
|
70
|
+
* @returns The positional's value (if given) and the parsed options.
|
|
71
|
+
*/
|
|
72
|
+
export function splitGeneratorActionArgs(actionArgs, hasPositional) {
|
|
73
|
+
const [first, second] = actionArgs;
|
|
74
|
+
const options = (hasPositional ? second : first) ??
|
|
75
|
+
{};
|
|
76
|
+
const positionalValue = hasPositional && typeof first === "string" && first ? first : undefined;
|
|
77
|
+
return { positionalValue, options };
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Configure a command with generator options and action.
|
|
81
|
+
*
|
|
82
|
+
* The leaf opts into Commander's excess-argument tolerance and the action
|
|
83
|
+
* wrapper OWNS the overflow instead: a stray operand beyond the declared
|
|
84
|
+
* positional emits the designed `unexpected argument` outcome (exit 2) and
|
|
85
|
+
* never reaches the host action — in both CLIs. This is what kills the
|
|
86
|
+
* silent-positional-drop class (`summon component react MyComponent Extra`
|
|
87
|
+
* used to bind nothing and say nothing).
|
|
88
|
+
*
|
|
89
|
+
* @param cmd - The command to configure.
|
|
90
|
+
* @param entry - The barrel entry (carries the generator).
|
|
91
|
+
* @param barrel - The whole barrel (for sibling/child suggestions).
|
|
92
|
+
* @param host - The host seam.
|
|
93
|
+
* @param positionalPrompt - The generator's positional prompt, when the
|
|
94
|
+
* command spec declared one.
|
|
95
|
+
*/
|
|
96
|
+
function configureGeneratorCommand(cmd, entry, barrel, host, positionalPrompt) {
|
|
97
|
+
const generator = entry.generator;
|
|
98
|
+
/* v8 ignore next -- defensive: callers configure only generator entries. */
|
|
99
|
+
if (!generator)
|
|
100
|
+
return;
|
|
101
|
+
// Add prompt-based options
|
|
102
|
+
addPromptOptions(cmd, generator.prompts);
|
|
103
|
+
// Configure grouped help display (the host's own renderer, when supplied)
|
|
104
|
+
configureGroupedHelp(cmd, generator.prompts, host.helpFlags, host.renderHelp);
|
|
105
|
+
// The wrapper owns excess operands (designed outcome, not Commander's).
|
|
106
|
+
cmd.allowExcessArguments(true);
|
|
107
|
+
const declaredPositionals = positionalPrompt ? 1 : 0;
|
|
108
|
+
const { siblings, children } = segmentNeighbours(entry, barrel);
|
|
109
|
+
// Add action: guard excess operands, normalize Commander's calling
|
|
110
|
+
// convention, then hand off.
|
|
111
|
+
cmd.action(async (...actionArgs) => {
|
|
112
|
+
if (cmd.args.length > declaredPositionals) {
|
|
113
|
+
const stray = cmd.args[declaredPositionals];
|
|
114
|
+
const error = excessPositionalError(commandChain(cmd), stray, cmd.args, siblings, children);
|
|
115
|
+
host.emit({ kind: "usage-error", error, exitCode: 2 });
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const { positionalValue, options } = splitGeneratorActionArgs(actionArgs, positionalPrompt !== undefined);
|
|
119
|
+
await host.action(entry, positionalValue, options);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Configure a namespace (non-runnable) command: the projection owns the
|
|
124
|
+
* unknown child segment (the shared did-you-mean, exit 2) and the bare
|
|
125
|
+
* invocation (the namespace's own help, exit 1 — both hosts' established
|
|
126
|
+
* shape), each delivered as a {@link MountOutcome}. Excess tolerance makes
|
|
127
|
+
* Commander route an unrecognized first operand to this action instead of
|
|
128
|
+
* its host-divergent `unknownCommand` path; a KNOWN segment still dispatches
|
|
129
|
+
* to the child before the action is consulted, and a runnable entry
|
|
130
|
+
* registered at the same path replaces this action with the leaf's own.
|
|
131
|
+
*/
|
|
132
|
+
function configureNamespaceCommand(cmd, host) {
|
|
133
|
+
cmd.allowExcessArguments(true);
|
|
134
|
+
cmd.action(() => {
|
|
135
|
+
const stray = cmd.args[0];
|
|
136
|
+
if (stray !== undefined) {
|
|
137
|
+
const children = cmd.commands.map((child) => child.name());
|
|
138
|
+
host.emit({
|
|
139
|
+
kind: "usage-error",
|
|
140
|
+
error: unknownSegmentError(commandChain(cmd), stray, children),
|
|
141
|
+
exitCode: 2,
|
|
142
|
+
});
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
// Bare namespace: its own help, exit 1. The help is laid out for the
|
|
146
|
+
// stream the parity bytes go to: `{ error: true }` selects the ERROR
|
|
147
|
+
// output context (stderr's width), where the bare call would measure
|
|
148
|
+
// stdout's. Byte-identical under pipes (both default to 80). Computed
|
|
149
|
+
// eagerly on purpose: both shipped hosts consume it, and this is a
|
|
150
|
+
// terminal error path, never a fast path.
|
|
151
|
+
host.emit({
|
|
152
|
+
kind: "namespace-help",
|
|
153
|
+
help: cmd.helpInformation({ error: true }),
|
|
154
|
+
exitCode: 1,
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Register all commands from a command barrel onto a Commander program.
|
|
160
|
+
*
|
|
161
|
+
* @param rootCmd - The program (or parent command) to register onto.
|
|
162
|
+
* @param barrel - The flattened command entries, parents before children.
|
|
163
|
+
* @param host - The host seam (flags, action, namespace hook, emit sink).
|
|
164
|
+
* @note Impure — mutates the Commander program.
|
|
165
|
+
*/
|
|
166
|
+
export default function registerGeneratorCommands(rootCmd, barrel, host) {
|
|
167
|
+
const commandMap = new Map();
|
|
168
|
+
commandMap.set("", rootCmd);
|
|
169
|
+
for (const entry of barrel) {
|
|
170
|
+
const name = entry.path[entry.path.length - 1];
|
|
171
|
+
const parentPath = entry.path.slice(0, -1).join("/");
|
|
172
|
+
const currentPath = entry.path.join("/");
|
|
173
|
+
// Already registered (a namespace + runnable at the same path): a
|
|
174
|
+
// runnable entry upgrades the existing namespace command into a FULL
|
|
175
|
+
// leaf — the declared positional (the namespace spec carried none, so
|
|
176
|
+
// Commander must learn the argument or the action would mis-slot its
|
|
177
|
+
// arguments), the leaf usage line, and the host's standard flags —
|
|
178
|
+
// exactly what the fresh-registration path below gives a leaf. A
|
|
179
|
+
// duplicate namespace entry is skipped.
|
|
180
|
+
const existingCmd = commandMap.get(currentPath);
|
|
181
|
+
if (existingCmd) {
|
|
182
|
+
if (entry.generator) {
|
|
183
|
+
const positionalPrompt = entry.generator.prompts.find((p) => p.positional);
|
|
184
|
+
if (positionalPrompt) {
|
|
185
|
+
const positionalName = toKebabCase(positionalPrompt.name);
|
|
186
|
+
existingCmd.argument(`[${positionalName}]`);
|
|
187
|
+
existingCmd.usage(`[${positionalName}] [options]`);
|
|
188
|
+
}
|
|
189
|
+
host.registerFlags(existingCmd);
|
|
190
|
+
configureGeneratorCommand(existingCmd, entry, barrel, host, positionalPrompt);
|
|
191
|
+
}
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
// Get or create parent command
|
|
195
|
+
const parentCmd = commandMap.get(parentPath) ?? rootCmd;
|
|
196
|
+
if (entry.generator) {
|
|
197
|
+
const positionalPrompt = entry.generator.prompts.find((p) => p.positional);
|
|
198
|
+
const commandSpec = positionalPrompt
|
|
199
|
+
? `${name} [${toKebabCase(positionalPrompt.name)}]`
|
|
200
|
+
: name;
|
|
201
|
+
const cmd = parentCmd
|
|
202
|
+
.command(commandSpec)
|
|
203
|
+
.description(entry.generator.meta.description);
|
|
204
|
+
host.registerFlags(cmd);
|
|
205
|
+
if (positionalPrompt) {
|
|
206
|
+
const positionalName = toKebabCase(positionalPrompt.name);
|
|
207
|
+
cmd.usage(`[${positionalName}] [options]`);
|
|
208
|
+
}
|
|
209
|
+
configureGeneratorCommand(cmd, entry, barrel, host, positionalPrompt);
|
|
210
|
+
commandMap.set(currentPath, cmd);
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
const cmd = parentCmd
|
|
214
|
+
.command(name)
|
|
215
|
+
.description(entry.description ?? `${name} commands`);
|
|
216
|
+
configureNamespaceCommand(cmd, host);
|
|
217
|
+
host.onNamespace?.(cmd, entry);
|
|
218
|
+
commandMap.set(currentPath, cmd);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=registerGeneratorCommands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registerGeneratorCommands.js","sourceRoot":"","sources":["../../../../src/projection/commander/registerGeneratorCommands.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,OAAO,eAAe,MAAM,uBAAuB,CAAC;AAEpD,OAAO,WAAW,MAAM,aAAa,CAAC;AAOtC,OAAO,EACL,qBAAqB,EAErB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AACrB,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAwD7D,uDAAuD;AACvD,SAAS,gBAAgB,CAAC,GAAY,EAAE,OAA8B;IACpE,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,MAAM,IAAI,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;QACrC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC;AAED,sEAAsE;AACtE,SAAS,YAAY,CAAC,GAAY;IAChC,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,OAAO,GAAmB,GAAG,CAAC;IAClC,OAAO,OAAO,EAAE,CAAC;QACf,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QAC9B,OAA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AC;iBACb,WAAW,CAAC,KAAK,CAAC,WAAW,IAAI,GAAG,IAAI,WAAW,CAAC,CAAC;YAExD,yBAAyB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YACrC,IAAI,CAAC,WAAW,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YAC/B,UAAU,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ONE interaction decision (R2). Both products call this — the summon bin
|
|
3
|
+
* and pragma's `create` — so a given (flags, TTY, answers) state produces the
|
|
4
|
+
* same mode in either binary. The normative table lives in
|
|
5
|
+
* the cross-CLI matrix, which executes this module's decision; the exhaustive 32-cell
|
|
6
|
+
* test in `decideInteraction.test.ts` pins every row.
|
|
7
|
+
*
|
|
8
|
+
* Precedence: `--dry-run` > `--undo` > the rest. The batch modes ignore TTY —
|
|
9
|
+
* a dry-run or undo is a batch render wherever it runs. Then `--yes` means
|
|
10
|
+
* run-with-defaults; a TTY gets the wizard (which asks only `pendingPrompts`);
|
|
11
|
+
* a non-TTY with a fully-explicit answer set is a legitimate scripted run; and
|
|
12
|
+
* a non-TTY mutation with incomplete input REFUSES — exit 2 with recovery —
|
|
13
|
+
* rather than silently scaffolding from defaults.
|
|
14
|
+
*/
|
|
15
|
+
import buildOptionInfo from "./buildOptionInfo.js";
|
|
16
|
+
/**
|
|
17
|
+
* Decide the interaction mode for one invocation.
|
|
18
|
+
*
|
|
19
|
+
* @param input - The five decision inputs.
|
|
20
|
+
* @returns The mode (and the `refusal` marker on row 6).
|
|
21
|
+
*/
|
|
22
|
+
export function decideInteraction(input) {
|
|
23
|
+
if (input.dryRun)
|
|
24
|
+
return { mode: "batch-dry-run" };
|
|
25
|
+
if (input.undo)
|
|
26
|
+
return { mode: "batch-undo" };
|
|
27
|
+
if (input.yes)
|
|
28
|
+
return { mode: "run" };
|
|
29
|
+
if (input.isTTY)
|
|
30
|
+
return { mode: "wizard" };
|
|
31
|
+
if (input.explicitComplete)
|
|
32
|
+
return { mode: "run" };
|
|
33
|
+
return { mode: "refuse", refusal: true };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The PRIMARY registered long-form flag of each unconditional prompt absent
|
|
37
|
+
* from the explicit answers, in declared order — the `Missing:` list of the
|
|
38
|
+
* refusal message. Every token is derived through {@link buildOptionInfo},
|
|
39
|
+
* the single flag-shape authority both binaries register from, so every
|
|
40
|
+
* listed token is one the command actually answers to: a default-`true`
|
|
41
|
+
* confirm is listed as its only registered form `--no-<kebab>` (kebab-casing
|
|
42
|
+
* the prompt NAME advertised `--<kebab>`, a flag neither host registers —
|
|
43
|
+
* following the refusal's own instruction then exited 2), everything else as
|
|
44
|
+
* `--<kebab>`.
|
|
45
|
+
*
|
|
46
|
+
* @param prompts - The command's prompts (live or projected).
|
|
47
|
+
* @param explicit - The explicitly provided answers (no defaults).
|
|
48
|
+
* @returns Registered long-form flag tokens (`--` included).
|
|
49
|
+
*/
|
|
50
|
+
export function missingExplicitFlags(prompts, explicit) {
|
|
51
|
+
return prompts
|
|
52
|
+
.filter((prompt) => !(prompt.when !== undefined || prompt.conditional === true) &&
|
|
53
|
+
!Object.hasOwn(explicit, prompt.name))
|
|
54
|
+
.map((prompt) => buildOptionInfo(prompt).flags.split(" ")[0]);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The refusal message — authored ONCE here, written verbatim by BOTH CLIs
|
|
58
|
+
* (stderr, exit 2). The tokens are rendered VERBATIM — they arrive as full
|
|
59
|
+
* registered flags (see {@link missingExplicitFlags}); re-prefixing here
|
|
60
|
+
* would double the dashes.
|
|
61
|
+
*
|
|
62
|
+
* @param missingFlags - The missing flag tokens (see
|
|
63
|
+
* {@link missingExplicitFlags}).
|
|
64
|
+
* @returns The complete refusal message.
|
|
65
|
+
*/
|
|
66
|
+
export function refusalMessage(missingFlags) {
|
|
67
|
+
const base = "Refusing to scaffold in a non-interactive run without complete input. " +
|
|
68
|
+
"Pass --yes to accept defaults, --dry-run to preview, or provide every answer as a flag.";
|
|
69
|
+
if (missingFlags.length === 0)
|
|
70
|
+
return base;
|
|
71
|
+
return `${base} Missing: ${missingFlags.join(", ")}.`;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=decideInteraction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decideInteraction.js","sourceRoot":"","sources":["../../../src/projection/decideInteraction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,eAAe,MAAM,sBAAsB,CAAC;AA+BnD;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAAuB;IAEvB,IAAI,KAAK,CAAC,MAAM;QAAE,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;IACnD,IAAI,KAAK,CAAC,IAAI;QAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;IAC9C,IAAI,KAAK,CAAC,GAAG;QAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IACtC,IAAI,KAAK,CAAC,KAAK;QAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAC3C,IAAI,KAAK,CAAC,gBAAgB;QAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IACnD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3C,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,oBAAoB,CAClC,OAA8B,EAC9B,QAA2C;IAE3C,OAAO,OAAO;SACX,MAAM,CACL,CAAC,MAAM,EAAE,EAAE,CACT,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,SAAS,IAAI,MAAM,CAAC,WAAW,KAAK,IAAI,CAAC;QAC3D,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,CACxC;SACA,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAAC,YAA+B;IAC5D,MAAM,IAAI,GACR,wEAAwE;QACxE,yFAAyF,CAAC;IAC5F,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3C,OAAO,GAAG,IAAI,aAAa,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract the EXPLICITLY provided answers from parsed Commander options —
|
|
3
|
+
* moved verbatim from the summon bin's registration layer. Explicit-only is
|
|
4
|
+
* the invariant: defaults never enter the result (Commander was registered
|
|
5
|
+
* without them — see `buildOptionInfo`), so downstream decisions can tell a
|
|
6
|
+
* typed flag from an untouched one.
|
|
7
|
+
*
|
|
8
|
+
* The one unavoidable ambiguity: Commander reports a default-`true` confirm's
|
|
9
|
+
* `--no-<kebab>` as `true` when the flag was NOT passed. Equality-vs-default
|
|
10
|
+
* filters that out — a confirm value equal to its declared default is treated
|
|
11
|
+
* as unprovided. (Typing the flag that restates the default is therefore
|
|
12
|
+
* indistinguishable from omitting it; every consumer inherits that fact.)
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Extract answers from Commander options based on prompts.
|
|
16
|
+
*
|
|
17
|
+
* @param options - Commander's parsed option values.
|
|
18
|
+
* @param prompts - The command's prompts (live or projected).
|
|
19
|
+
* @returns Only the explicitly provided answers, keyed by prompt name.
|
|
20
|
+
*/
|
|
21
|
+
export default function extractAnswers(options, prompts) {
|
|
22
|
+
const answers = {};
|
|
23
|
+
for (const prompt of prompts) {
|
|
24
|
+
// Own-property read: Commander's options object is an ordinary object,
|
|
25
|
+
// so a prompt named like an inherited member (`toString`) would
|
|
26
|
+
// otherwise read the prototype's function and count as provided.
|
|
27
|
+
const value = Object.hasOwn(options, prompt.name)
|
|
28
|
+
? options[prompt.name]
|
|
29
|
+
: undefined;
|
|
30
|
+
if (value !== undefined) {
|
|
31
|
+
switch (prompt.type) {
|
|
32
|
+
case "confirm": {
|
|
33
|
+
const boolValue = Boolean(value);
|
|
34
|
+
if (boolValue !== prompt.default) {
|
|
35
|
+
answers[prompt.name] = boolValue;
|
|
36
|
+
}
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
case "multiselect":
|
|
40
|
+
answers[prompt.name] =
|
|
41
|
+
typeof value === "string"
|
|
42
|
+
? value.split(",").map((v) => v.trim())
|
|
43
|
+
: value;
|
|
44
|
+
break;
|
|
45
|
+
default:
|
|
46
|
+
answers[prompt.name] = value;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return answers;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=extractAnswers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractAnswers.js","sourceRoot":"","sources":["../../../src/projection/extractAnswers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CACpC,OAAgC,EAChC,OAA8B;IAE9B,MAAM,OAAO,GAA4B,EAAE,CAAC;IAE5C,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,uEAAuE;QACvE,gEAAgE;QAChE,iEAAiE;QACjE,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC;YAC/C,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;YACtB,CAAC,CAAC,SAAS,CAAC;QAEd,IAAI,KAAK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