Skip to content

Commit c26301a

Browse files
committed
feat(fmt): add -w alias for write
1 parent 9e57744 commit c26301a

6 files changed

Lines changed: 27 additions & 3 deletions

File tree

‎packages/rstack/src/fmt/cli.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ${color.yellow(' $ rs fmt [options] [files/globs...]')}
2929
Format files with Prettier.
3030
3131
${color.cyan('Options')}:
32-
--write Write formatted files in place (default)
32+
-w, --write Write formatted files in place (default)
3333
--check Check whether files are formatted
3434
--list-different Print paths of unformatted files
3535
--ignore-path <path> Path to an additional ignore file (repeatable)
@@ -57,7 +57,7 @@ const parseFmtCLIArgs = (args: string[]): ParsedFmtCLIArgs => {
5757
const { values, positionals } = parseArgs({
5858
args,
5959
options: {
60-
write: { type: 'boolean' },
60+
write: { type: 'boolean', short: 'w' },
6161
check: { type: 'boolean' },
6262
'list-different': { type: 'boolean' },
6363
'ignore-path': { type: 'string', multiple: true },

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,17 @@ test('formats the current directory with Prettier defaults', () => {
128128
expect(readProjectFile('index.ts')).toBe('const message = "hello";\n');
129129
});
130130

131+
test('accepts -w as an alias for --write', () => {
132+
writeProjectFile('index.ts', 'const message="hello"');
133+
134+
const result = runFmt(['-w', 'index.ts']);
135+
136+
expect(result.status).toBe(0);
137+
expectWriteSummary(result.stdout, 1, 1);
138+
expect(result.stderr).toBe('');
139+
expect(readProjectFile('index.ts')).toBe('const message = "hello";\n');
140+
});
141+
131142
test('formats files in node_modules with --with-node-modules', () => {
132143
const source = 'const message="hello"';
133144
writeProjectFile('node_modules/example/index.ts', source);

‎packages/rstack/tests/fmt/__snapshots__/cli.test.ts.snap‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ exports[`provides command help 1`] = `
77
Format files with Prettier.
88
99
Options:
10-
--write Write formatted files in place (default)
10+
-w, --write Write formatted files in place (default)
1111
--check Check whether files are formatted
1212
--list-different Print paths of unformatted files
1313
--ignore-path <path> Path to an additional ignore file (repeatable)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ test('uses write mode by default', () => {
3131
});
3232

3333
test.each([
34+
['-w', 'write'],
3435
['--write', 'write'],
3536
['--check', 'check'],
3637
['--list-different', 'list-different'],

‎website/docs/en/guide/cli/fmt.mdx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,10 @@ Write formatted files in place. This is the default mode, so specifying `--write
167167
rs fmt src --write
168168
```
169169

170+
The short option `-w` is an alias for `--write`:
171+
172+
```bash
173+
rs fmt -w src
174+
```
175+
170176
`--write` cannot be combined with `--check` or `--list-different`.

‎website/docs/zh/guide/cli/fmt.mdx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,10 @@ rs fmt --with-node-modules node_modules/example/index.js
167167
rs fmt src --write
168168
```
169169

170+
短选项 `-w` 是 `--write` 的别名:
171+
172+
```bash
173+
rs fmt -w src
174+
```
175+
170176
`--write` 不能与 `--check` 或 `--list-different` 同时使用。

0 commit comments

Comments
 (0)