Skip to content

Commit db33067

Browse files
authored
feat(cli): add format alias for fmt (#126)
1 parent 18ac809 commit db33067

3 files changed

Lines changed: 24 additions & 13 deletions

File tree

packages/rstack/src/cli/commands.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ ${color.cyan('Usage')}:
1515
${color.yellow(' $ rs [command] [...options]')}
1616
1717
${color.cyan('Commands')}:
18-
dev Run the app dev server
19-
build Build the app for production
20-
preview Preview the app production build
21-
lib Build library
22-
doc Serve or build docs
23-
fmt Format code
24-
lint Lint code
25-
test Run tests
26-
staged Run tasks on staged Git files
27-
setup Install Git hooks
18+
dev Run the app dev server
19+
build Build the app for production
20+
preview Preview the app production build
21+
lib Build library
22+
doc Serve or build docs
23+
fmt, format Format code
24+
lint Lint code
25+
test Run tests
26+
staged Run tasks on staged Git files
27+
setup Install Git hooks
2828
2929
${color.dim(`For command-specific options, run:
3030
$ rs <command> -h`)}
@@ -144,7 +144,7 @@ export async function setupCommands(): Promise<void> {
144144
return;
145145
}
146146

147-
if (command === 'fmt') {
147+
if (command === 'fmt' || command === 'format') {
148148
const { runFmtCLI } = await import(
149149
/* rspackChunkName: 'fmt' */
150150
'../fmt/cli.ts'

packages/rstack/tests/cli/fmt/index.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,23 @@ test('displays fmt help without loading config', () => {
4545
const fmt = runFmt(['--help']);
4646

4747
expect(topLevel.status).toBe(0);
48-
expect(topLevel.stdout).toContain('fmt Format code');
48+
expect(topLevel.stdout).toContain('fmt, format Format code');
4949
expect(fmt.status).toBe(0);
5050
expect(fmt.stdout).toContain('Usage:\n $ rs fmt [options] [files/globs...]');
5151
expect(fmt.stderr).toBe('');
5252
});
5353

54+
test('supports format as an alias for fmt', () => {
55+
writeProjectFile('index.ts', 'const message="hello"');
56+
57+
const result = runCLI(['format', 'index.ts']);
58+
59+
expect(result.status).toBe(0);
60+
expect(result.stdout).toBe('index.ts\n');
61+
expect(result.stderr).toBe('');
62+
expect(readProjectFile('index.ts')).toBe('const message = "hello";\n');
63+
});
64+
5465
test('returns exit code 1 for invalid arguments', () => {
5566
const result = runFmt(['--write', '--check']);
5667

packages/rstack/tests/cli/setup/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ afterEach(() => {
4343
});
4444

4545
test('displays setup help', ({ execCli, expect }) => {
46-
expect(execCli('--help', { cwd })).toContain('setup Install Git hooks');
46+
expect(execCli('--help', { cwd })).toMatch(/setup\s+Install Git hooks/);
4747

4848
const output = execCli('setup --help', { cwd });
4949

0 commit comments

Comments
 (0)