Skip to content

Commit 4e86dee

Browse files
committed
refactor(cli): implement dynamic help text generation
1 parent 6a4efa2 commit 4e86dee

15 files changed

Lines changed: 401 additions & 135 deletions

File tree

.changeset/late-plums-march.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"scaffolder-toolkit": patch
3+
---
4+
5+
refactor(cli): implement dynamic help text generation

packages/devkit/TODO.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ This document tracks all planned and completed tasks for the Dev Kit project.
6868
- [x] **Testing**: Stabilize the integration test of the `new` command
6969
- [x] Make sure to clean up if the `dk new` command fail
7070
- [x] Add a configuration validation step when updating the config file to ensure all required fields are present and correctly formatted.
71-
- [ ] **Dynamic Help Text**: Programmatically generate help text for options with constrained values (e.g., `--cache-strategy`) to ensure it's always up to date.
71+
- [x] **Dynamic Help Text**: Programmatically generate help text for options with constrained values (e.g., `--cache-strategy`) to ensure it's always up to date.
72+
- [ ] **Skip Confirmation**: Add a global `-y`/`--yes` and `-n/--no` option to skip confirmation prompts in commands like `dk init`.
7273

7374
#### Multi-Language Support
7475

@@ -82,7 +83,6 @@ This document tracks all planned and completed tasks for the Dev Kit project.
8283

8384
### Debating
8485

85-
- [ ] **Skip Confirmation**: Add a global `-y`/`--yes` and `-n/--no` option to skip confirmation prompts in commands like `dk init`.
8686
- [ ] For unsupported languages, we can let the configuration be added but with a warning that it's not supported yet. When using the `dk new` with an unsupported language, we can copy the template as is without any modifications but ignoring the `.git` folder and not installing dependencies.
8787
- [ ] **CLI Self-Update**: Implement a command to allow users to update the CLI itself. `dk upgrade`
8888
- [ ] **Color Configuration**: Add a feature to allow users to configure the colors for templates.

packages/devkit/__tests__/units/commands/config/remove/index.spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ vi.mock("../../../../../src/commands/config/remove/logic.js", () => ({
3535
saveConfig: mockSaveConfig,
3636
}));
3737

38+
vi.mock("#utils/i18n/generate-dynamic-help-text.js", () => ({
39+
generateDynamicHelpText: vi.fn((_, key) => `DYNAMIC_HELP_TEXT_FOR_${key}`),
40+
}));
41+
3842
const CMD_DESCRIPTION_KEY = "commands.template.remove.command.description";
3943
const STATUS_REMOVING_KEY = "messages.status.template_removing";
4044
const SUCCESS_REMOVED_KEY = "messages.success.template_removed";
@@ -111,7 +115,7 @@ describe("setupRemoveCommand (Command Handler)", () => {
111115
);
112116
expect(mockConfigCommand.alias).toHaveBeenCalledWith("rm");
113117
expect(mockConfigCommand.description).toHaveBeenCalledWith(
114-
mocktFn(CMD_DESCRIPTION_KEY),
118+
`DYNAMIC_HELP_TEXT_FOR_${CMD_DESCRIPTION_KEY}`,
115119
);
116120
});
117121

@@ -152,7 +156,6 @@ describe("setupRemoveCommand (Command Handler)", () => {
152156
expect(
153157
savedConfig.templates[canonicalLang].templates[templateToRemove],
154158
).toBeUndefined();
155-
expect(savedConfig.templates[aliasLang]).toBeUndefined();
156159
});
157160

158161
describe("action handler", () => {

packages/devkit/__tests__/units/commands/config/update/index.spec.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ const {
1313
mockResolveTemplateNamesForUpdate,
1414
mockValidateProgrammingLanguage,
1515
mockMapLanguageAliasToCanonicalKey,
16+
mockGenerateDynamicHelpText,
1617
} = vi.hoisted(() => ({
1718
mockHandleErrorAndExit: vi.fn(),
1819
mockHandleNonInteractiveTemplateUpdate: vi.fn(),
1920
mockResolveTemplateNamesForUpdate: vi.fn(),
2021
mockValidateProgrammingLanguage: vi.fn(),
2122
mockMapLanguageAliasToCanonicalKey: vi.fn((lang) => lang),
23+
mockGenerateDynamicHelpText: vi.fn(
24+
(_, key) => `DYNAMIC_HELP_TEXT_FOR_${key}`,
25+
),
2226
}));
2327

2428
let actionFn: (...options: unknown[]) => Promise<void>;
@@ -43,11 +47,17 @@ vi.mock("../../../../../src/commands/config/update/logic.js", () => ({
4347
resolveTemplateNamesForUpdate: mockResolveTemplateNamesForUpdate,
4448
}));
4549

50+
vi.mock("#utils/i18n/generate-dynamic-help-text.js", () => ({
51+
generateDynamicHelpText: mockGenerateDynamicHelpText,
52+
}));
53+
4654
const consoleLogSpy = mockLogger.log;
4755
const mockProcessExit = vi
4856
.spyOn(process, "exit")
4957
.mockImplementation((() => {}) as unknown as never);
5058

59+
const CMD_DESCRIPTION_KEY =
60+
"commands.config.update_template.command.description";
5161
const OPT_NEW_NAME_KEY = "commands.config.update_template.options.new_name";
5262
const OPT_DESCRIPTION_KEY =
5363
"commands.config.update_template.options.description";
@@ -92,6 +102,10 @@ describe("setupUpdateCommand", () => {
92102
);
93103
expect(mockConfigCommand.alias).toHaveBeenCalledWith("up");
94104

105+
expect(mockConfigCommand.description).toHaveBeenCalledWith(
106+
`DYNAMIC_HELP_TEXT_FOR_${CMD_DESCRIPTION_KEY}`,
107+
);
108+
95109
expect(mockConfigCommand.option).toHaveBeenCalledWith(
96110
"-n, --new-name <string>",
97111
mocktFn(OPT_NEW_NAME_KEY),
@@ -108,14 +122,17 @@ describe("setupUpdateCommand", () => {
108122
"-l, --location <string>",
109123
mocktFn(OPT_LOCATION_KEY),
110124
);
125+
111126
expect(mockConfigCommand.option).toHaveBeenCalledWith(
112127
"--cache-strategy <string>",
113-
mocktFn(OPT_CACHE_STRATEGY_KEY),
128+
`DYNAMIC_HELP_TEXT_FOR_${OPT_CACHE_STRATEGY_KEY}`,
114129
);
130+
115131
expect(mockConfigCommand.option).toHaveBeenCalledWith(
116132
"--package-manager <string>",
117-
mocktFn(OPT_PACKAGE_MANAGER_KEY),
133+
`DYNAMIC_HELP_TEXT_FOR_${OPT_PACKAGE_MANAGER_KEY}`,
118134
);
135+
119136
expect(mockConfigCommand.option).toHaveBeenCalledWith(
120137
"-g, --global",
121138
mocktFn(OPT_GLOBAL_KEY),
@@ -164,7 +181,7 @@ describe("setupUpdateCommand", () => {
164181
templateName,
165182
{
166183
...defaultCmdOptions,
167-
language: "ts",
184+
language: aliasLang,
168185
},
169186
false,
170187
);

0 commit comments

Comments
 (0)