diff --git a/README.md b/README.md index 507150ae..23a6eb7f 100644 --- a/README.md +++ b/README.md @@ -339,8 +339,8 @@ If planned renames clash, the process is halted and no change is applied to any | | **`--tail`** Shorthand for setting both --name-delimiter-tail and --content-delimiter-tail. Use --no-tail to not print the delimiter after the last name and the last content. The specific tail flags win over --tail. [boolean] | | | **`--nl`** Let what is printed to stdout and stderr (the names, or the content from -o, -m or piped data) always end with a new line. No extra new line if it already ends with a new line, or if nothing was printed. [boolean] | | `-H` | **`--halt`**, **`--bail`** Halt on first error [boolean] [default: false] | -| `-c` | **`--status-compact`** As the last thing before ending any execution a status report will be printed as one line of JSON. Will print even in combination with `--quiet-total`. Will incude extra info about the inner workings of the engine in combination with the `--verbose` flag. [boolean] | -| | **`--status`** Same as `--status-compact`, but always starting with a `\n` followed by pretty printed JSON. [boolean] | +| `-c` | **`--status-compact`** As the last thing before ending any execution a status report will be printed as one line of JSON. Will print even in combination with `--quiet-total`. Will include extra info about the inner workings of the engine in combination with the `--verbose` flag. [boolean] | +| | **`--status`** Same as `--status-compact`, but always starting with a `\n` followed by pretty printed JSON. `--status-compact` wins when both are given. [boolean] | | `-d` | **`--debug`** Print only the status report, with what went into the engine and what it did. Does not block the output of --output and --output-match. [boolean] | | `-€` | **`--void-euro`** Void having `€` as alias for `$`. The alias is used in all inputs, but never in globs, file names or piped data. [boolean] | diff --git a/src/cli.ts b/src/cli.ts index c2142faf..1f629acb 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -515,13 +515,13 @@ Z z .alias('c', 'status-compact') .describe( 'c', - 'As the last thing before ending any execution a status report will be printed as one line of JSON. Will print even in combination with `--quiet-total`. Will incude extra info about the inner workings of the engine in combination with the `--verbose` flag.' + 'As the last thing before ending any execution a status report will be printed as one line of JSON. Will print even in combination with `--quiet-total`. Will include extra info about the inner workings of the engine in combination with the `--verbose` flag.' ) .boolean('status') .describe( 'status', - 'Same as `--status-compact`, but always starting with a `\\n` followed by pretty printed JSON.' + 'Same as `--status-compact`, but always starting with a `\\n` followed by pretty printed JSON. `--status-compact` wins when both are given.' ) .boolean('d') @@ -539,11 +539,12 @@ Z z // The engine resolves with the status of the run, or throws a panic when the run can not go on. // The CLI is the only part that acts on the process. +// Compact wins when both are given, as asking for it is asking for less output function printStatus(config, status) { - if (config.status) { - writeTo(process.stdout, '\n' + JSON.stringify(status, null, 2) + '\n'); - } else if (config.statusCompact) { + if (config.statusCompact) { writeTo(process.stdout, JSON.stringify(status) + '\n'); + } else if (config.status) { + writeTo(process.stdout, '\n' + JSON.stringify(status, null, 2) + '\n'); } } diff --git a/test/fix/742.test.js b/test/fix/742.test.js index 5693cbcb..53a5ae1f 100644 --- a/test/fix/742.test.js +++ b/test/fix/742.test.js @@ -208,6 +208,14 @@ describe('#742 the CLI', () => { } ); + test('prints the status report on one line when both --status and --status-compact are given', async () => { + fs.writeFileSync('a.file', 'foo'); + const result = await sh($`bun ${cli} o x a.file --status --status-compact --quiet-total`); + expect(result.out).toBe( + '{"files":{"searched":["a.file"],"updated":["a.file"]},"pipe":null,"warnings":[],"errors":[]}\n' + ); + }); + test('sets the exit code to 2 when a file gives an error, and prints the status report', async () => { fs.writeFileSync('a.file', 'foo'); fs.chmodSync('a.file', 0);