Skip to content
This repository was archived by the owner on Apr 8, 2026. It is now read-only.

Commit 5984ad5

Browse files
authored
adding support for multiple files on the who command (#52)
1 parent 4b778f4 commit 5984ad5

4 files changed

Lines changed: 28 additions & 11 deletions

File tree

src/cli.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,18 @@ commander.command('validate')
6060
});
6161

6262

63-
commander.command('who <file>')
64-
.description('lists owners of a specific file')
63+
commander.command('who <files...>')
64+
.description('lists owners of a specific file or files')
6565
.option('-d, --dir <dirPath>', 'path to VCS directory', process.cwd())
6666
.option('-c, --codeowners <filePath>', 'path to codeowners file (default: "<dir>/.github/CODEOWNERS")')
6767
.option('-o, --output <outputFormat>', `how to output format eg: ${Object.values(OUTPUT_FORMAT).join(', ')}`, OUTPUT_FORMAT.SIMPLE)
68-
.action(async (file, options) => {
68+
.action(async (files, options) => {
6969
try {
70-
if (!file) {
70+
if (files.length < 1) {
7171
throw new Error('a file must be defined');
7272
}
7373

74-
options.file = file;
74+
options.files = files;
7575

7676
if (!options.codeowners) {
7777
options.codeowners = path.resolve(options.dir, '.github/CODEOWNERS');
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`who should list ownership for all files: stderr 1`] = `""`;
3+
exports[`who should list ownership for multiple files: stderr 1`] = `""`;
44

5-
exports[`who should list ownership for all files: stdout 1`] = `
5+
exports[`who should list ownership for multiple files: stdout 1`] = `
6+
"explicit-ignore.js @js-owner
7+
default-wildcard-owners.md @global-owner1 @global-owner2
8+
"
9+
`;
10+
11+
exports[`who should list ownership for one file: stderr 1`] = `""`;
12+
13+
exports[`who should list ownership for one file: stdout 1`] = `
614
"default-wildcard-owners.md @global-owner1 @global-owner2
715
"
816
`;

src/commands/who.test.int.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,15 @@ describe('who', () => {
2121
return exec(`node ../../../dist/cli.js ${args}`, { cwd: testDir });
2222
};
2323

24-
it('should list ownership for all files', async () => {
24+
it('should list ownership for one file', async () => {
2525
const { stdout, stderr } = await runCli('who default-wildcard-owners.md');
2626
expect(stdout).toMatchSnapshot('stdout');
2727
expect(stderr).toMatchSnapshot('stderr');
2828
});
29+
30+
it('should list ownership for multiple files', async () => {
31+
const { stdout, stderr } = await runCli('who explicit-ignore.js default-wildcard-owners.md');
32+
expect(stdout).toMatchSnapshot('stdout');
33+
expect(stderr).toMatchSnapshot('stderr');
34+
});
2935
});

src/commands/who.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import { getOwnership } from '../lib/ownership';
22
import { OUTPUT_FORMAT } from '../lib/types';
33

44
interface WhoOptions {
5-
file: string;
5+
files: string[];
66
dir: string;
77
codeowners: string;
88
output: OUTPUT_FORMAT;
99
}
1010

1111
export const who = async (options: WhoOptions) => {
12-
const [file] = await getOwnership(options.codeowners, [options.file]);
13-
file.write(options.output, process.stdout);
12+
const files = await getOwnership(options.codeowners, options.files);
13+
14+
for (const file of files) {
15+
file.write(options.output, process.stdout);
16+
}
1417
};

0 commit comments

Comments
 (0)