diff --git a/packages/rstack/src/cli/commands.ts b/packages/rstack/src/cli/commands.ts index 6cdea3c..315ce4c 100644 --- a/packages/rstack/src/cli/commands.ts +++ b/packages/rstack/src/cli/commands.ts @@ -15,16 +15,16 @@ ${color.cyan('Usage')}: ${color.yellow(' $ rs [command] [...options]')} ${color.cyan('Commands')}: - dev Run the app dev server - build Build the app for production - preview Preview the app production build - lib Build library - doc Serve or build docs - fmt Format code - lint Lint code - test Run tests - staged Run tasks on staged Git files - setup Install Git hooks + dev Run the app dev server + build Build the app for production + preview Preview the app production build + lib Build library + doc Serve or build docs + fmt, format Format code + lint Lint code + test Run tests + staged Run tasks on staged Git files + setup Install Git hooks ${color.dim(`For command-specific options, run: $ rs -h`)} @@ -144,7 +144,7 @@ export async function setupCommands(): Promise { return; } - if (command === 'fmt') { + if (command === 'fmt' || command === 'format') { const { runFmtCLI } = await import( /* rspackChunkName: 'fmt' */ '../fmt/cli.ts' diff --git a/packages/rstack/tests/cli/fmt/index.test.ts b/packages/rstack/tests/cli/fmt/index.test.ts index 6f30566..6312782 100644 --- a/packages/rstack/tests/cli/fmt/index.test.ts +++ b/packages/rstack/tests/cli/fmt/index.test.ts @@ -45,12 +45,23 @@ test('displays fmt help without loading config', () => { const fmt = runFmt(['--help']); expect(topLevel.status).toBe(0); - expect(topLevel.stdout).toContain('fmt Format code'); + expect(topLevel.stdout).toContain('fmt, format Format code'); expect(fmt.status).toBe(0); expect(fmt.stdout).toContain('Usage:\n $ rs fmt [options] [files/globs...]'); expect(fmt.stderr).toBe(''); }); +test('supports format as an alias for fmt', () => { + writeProjectFile('index.ts', 'const message="hello"'); + + const result = runCLI(['format', 'index.ts']); + + expect(result.status).toBe(0); + expect(result.stdout).toBe('index.ts\n'); + expect(result.stderr).toBe(''); + expect(readProjectFile('index.ts')).toBe('const message = "hello";\n'); +}); + test('returns exit code 1 for invalid arguments', () => { const result = runFmt(['--write', '--check']); diff --git a/packages/rstack/tests/cli/setup/index.test.ts b/packages/rstack/tests/cli/setup/index.test.ts index 63d2e67..2429e69 100644 --- a/packages/rstack/tests/cli/setup/index.test.ts +++ b/packages/rstack/tests/cli/setup/index.test.ts @@ -43,7 +43,7 @@ afterEach(() => { }); test('displays setup help', ({ execCli, expect }) => { - expect(execCli('--help', { cwd })).toContain('setup Install Git hooks'); + expect(execCli('--help', { cwd })).toMatch(/setup\s+Install Git hooks/); const output = execCli('setup --help', { cwd });