Skip to content

Commit 076ad73

Browse files
authored
feat: add verbose option to staged command (#10)
1 parent e8db73a commit 076ad73

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

packages/rstack/src/staged.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Runs lint-staged with tasks from define.staged in rstack.config.
1111
Options:
1212
--allow-empty allow empty commits when tasks revert all staged changes
1313
-p, --concurrent <number|boolean> the number of tasks to run concurrently, or false for serial
14+
-v, --verbose show task output even when tasks succeed; by default only failed output is shown
1415
-h, --help Display this help message`;
1516

1617
export async function runStagedCLI(args: string[]): Promise<void> {
@@ -21,6 +22,7 @@ export async function runStagedCLI(args: string[]): Promise<void> {
2122
allowEmpty: { type: 'boolean' },
2223
concurrent: { type: 'string', short: 'p' },
2324
help: { type: 'boolean', short: 'h' },
25+
verbose: { type: 'boolean', short: 'v' },
2426
},
2527
allowPositionals: false,
2628
strict: true,
@@ -47,6 +49,7 @@ export async function runStagedCLI(args: string[]): Promise<void> {
4749
allowEmpty: values['allow-empty'] ?? values.allowEmpty ?? false,
4850
concurrent: values.concurrent === undefined ? true : JSON.parse(values.concurrent),
4951
config: stagedConfig,
52+
verbose: values.verbose ?? false,
5053
});
5154
if (!success) {
5255
process.exitCode = 1;

packages/rstack/test/cli/staged/index.test.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ define.staged({ '*.txt': 'node revert.mjs' });
2525
for (const file of process.argv.slice(2)) {
2626
writeFileSync(file, 'initial\\n');
2727
}
28+
29+
console.log('staged task output');
2830
`,
2931
),
3032
writeFile(path.join(cwd, 'file.txt'), 'initial\n'),
@@ -66,6 +68,7 @@ test('should display the staged help message', ({ execCli, expect }) => {
6668
expect(output).toContain('Usage:\n $ rs staged [options]');
6769
expect(output).toContain('Runs lint-staged with tasks from define.staged in rstack.config.');
6870
expect(output).toContain('--allow-empty');
71+
expect(output).toContain('-v, --verbose');
6972
expect(output).toContain('-h, --help');
7073
});
7174

@@ -85,14 +88,19 @@ test('should allow an empty commit with --allow-empty', async ({ execCli }) => {
8588
});
8689
});
8790

88-
test('should run staged tasks with --concurrent false', async ({ execCli }) => {
89-
await withGitFixture((cwd) => {
90-
execCli(`staged --allow-empty --concurrent false`, { cwd });
91+
for (const option of ['--concurrent false', '-p 1']) {
92+
test(`should run staged tasks with ${option}`, async ({ execCli }) => {
93+
await withGitFixture((cwd) => {
94+
execCli(`staged --allow-empty ${option}`, { cwd });
95+
});
9196
});
92-
});
97+
}
9398

94-
test('should run staged tasks with -p 1', async ({ execCli }) => {
95-
await withGitFixture((cwd) => {
96-
execCli(`staged --allow-empty -p 1`, { cwd });
99+
for (const option of ['--verbose', '-v']) {
100+
test(`should show successful task output with ${option}`, async ({ execCli, expect }) => {
101+
await withGitFixture((cwd) => {
102+
const output = execCli(`staged --allow-empty ${option}`, { cwd });
103+
expect(output).toContain('staged task output');
104+
});
97105
});
98-
});
106+
}

0 commit comments

Comments
 (0)