Skip to content

Commit 26328ea

Browse files
authored
feat: add relative option to staged command (#14)
1 parent a5785b6 commit 26328ea

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

packages/rstack/src/staged.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Options:
1313
-p, --concurrent <number|boolean> The number of tasks to run concurrently, or false for serial
1414
--no-stash Disable the backup stash. Implies "--no-revert".
1515
-q, --quiet Disable lint-staged's own console output
16+
-r, --relative Pass relative filepaths to tasks
1617
-v, --verbose Show task output even when tasks succeed; by default only failed output is shown
1718
-h, --help Display this help message`;
1819

@@ -26,6 +27,7 @@ export async function runStagedCLI(args: string[]): Promise<void> {
2627
help: { type: 'boolean', short: 'h' },
2728
'no-stash': { type: 'boolean' },
2829
quiet: { type: 'boolean', short: 'q' },
30+
relative: { type: 'boolean', short: 'r' },
2931
verbose: { type: 'boolean', short: 'v' },
3032
},
3133
allowPositionals: false,
@@ -54,6 +56,7 @@ export async function runStagedCLI(args: string[]): Promise<void> {
5456
concurrent: values.concurrent === undefined ? true : JSON.parse(values.concurrent),
5557
config: stagedConfig,
5658
quiet: values.quiet ?? false,
59+
relative: values.relative ?? false,
5760
stash: !values['no-stash'],
5861
verbose: values.verbose ?? false,
5962
});

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ for (const file of process.argv.slice(2)) {
2727
}
2828
2929
console.log('staged task output');
30+
console.log('staged file:', process.argv[2]);
3031
`,
3132
),
3233
writeFile(path.join(cwd, 'file.txt'), 'initial\n'),
@@ -70,6 +71,7 @@ test('should display the staged help message', ({ execCli, expect }) => {
7071
expect(output).toContain('--allow-empty');
7172
expect(output).toContain('--no-stash');
7273
expect(output).toContain('-q, --quiet');
74+
expect(output).toContain('-r, --relative');
7375
expect(output).toContain('-v, --verbose');
7476
expect(output).toContain('-h, --help');
7577
});
@@ -122,3 +124,12 @@ for (const option of ['--quiet', '-q']) {
122124
});
123125
});
124126
}
127+
128+
for (const option of ['--relative', '-r']) {
129+
test(`should pass relative filepaths with ${option}`, async ({ execCli, expect }) => {
130+
await withGitFixture((cwd) => {
131+
const output = execCli(`staged --allow-empty --verbose ${option}`, { cwd });
132+
expect(output).toContain('staged file: file.txt');
133+
});
134+
});
135+
}

0 commit comments

Comments
 (0)