Skip to content

Commit 53ac95f

Browse files
chenjiahanCopilot
andauthored
feat: include extra tools in help message (#88)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 9cdf5c8 commit 53ac95f

2 files changed

Lines changed: 47 additions & 4 deletions

File tree

src/index.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,18 @@ export type Argv = {
9797
'package-name'?: string;
9898
};
9999

100-
export const BUILTIN_TOOLS = ['eslint', 'prettier', 'biome'];
100+
export const BUILTIN_TOOLS = ['biome', 'eslint', 'prettier'];
101+
102+
function logHelpMessage(
103+
name: string,
104+
templates: string[],
105+
extraTools?: ExtraTool[],
106+
) {
107+
const extraToolNames = extraTools?.map((tool) => tool.value) ?? [];
108+
const toolsList = [...BUILTIN_TOOLS, ...extraToolNames].join(
109+
', ',
110+
);
101111

102-
function logHelpMessage(name: string, templates: string[]) {
103112
logger.log(`
104113
Usage: create-${name} [dir] [options]
105114
@@ -108,7 +117,7 @@ function logHelpMessage(name: string, templates: string[]) {
108117
-h, --help display help for command
109118
-d, --dir <dir> create project in specified directory
110119
-t, --template <tpl> specify the template to use
111-
--tools <tool> select additional tools (biome, eslint, prettier)
120+
--tools <tool> select additional tools (${toolsList})
112121
--override override files in target directory
113122
--packageName <name> specify the package name
114123
@@ -270,7 +279,7 @@ export async function create({
270279
const argv = parseArgv(processArgv);
271280

272281
if (argv.help) {
273-
logHelpMessage(name, templates);
282+
logHelpMessage(name, templates, extraTools);
274283
return;
275284
}
276285

test/help.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { expect, test } from '@rstest/core';
2+
import { logger } from 'rslog';
3+
import { create } from '../src';
4+
5+
test('help message includes extra tools', async () => {
6+
const logs: string[] = [];
7+
const originalLog = logger.log;
8+
9+
logger.override({
10+
log: (message?: unknown) => {
11+
logs.push(String(message ?? ''));
12+
},
13+
});
14+
15+
try {
16+
await create({
17+
name: 'test',
18+
root: '.',
19+
templates: ['vanilla'],
20+
getTemplateName: async () => 'vanilla',
21+
extraTools: [{ value: 'custom-tool', label: 'Custom Tool' }],
22+
argv: ['node', 'test', '--help'],
23+
});
24+
} finally {
25+
logger.override({
26+
log: originalLog,
27+
});
28+
}
29+
30+
const logOutput = logs.join('\n');
31+
expect(logOutput).toContain(
32+
'--tools <tool> select additional tools (biome, eslint, prettier, custom-tool)',
33+
);
34+
});

0 commit comments

Comments
 (0)