Skip to content

Commit

Permalink
feat(cli): add optional label option to compare command
Browse files Browse the repository at this point in the history
  • Loading branch information
matejchalk committed Aug 19, 2024
1 parent d15f876 commit b3494d6
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
11 changes: 6 additions & 5 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,13 @@ Usage:
Description:
Compare 2 reports and produce a report diff file.

In addition to the [Common Command Options](#common-command-options), the following options are required:
In addition to the [Common Command Options](#common-command-options), the following options are recognized by the `compare` command:

| Option | Type | Description |
| -------------- | -------- | ----------------------------- |
| **`--before`** | `string` | Path to source `report.json`. |
| **`--after`** | `string` | Path to target `report.json`. |
| Option | Required | Type | Description |
| -------------- | :------: | -------- | ----------------------------------- |
| **`--before`** | yes | `string` | Path to source `report.json`. |
| **`--after`** | yes | `string` | Path to target `report.json`. |
| **`--label`** | no | `string` | Label for diff (e.g. project name). |

#### `print-config` command

Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/lib/compare/compare-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ export function yargsCompareCommandObject() {
upload?: UploadConfig;
};

const { before, after, persist, upload } = options;
const { before, after, label, persist, upload } = options;

const outputPaths = await compareReportFiles(
{ before, after },
persist,
upload,
label,
);

ui().logger.info(
Expand Down
22 changes: 22 additions & 0 deletions packages/cli/src/lib/compare/compare-command.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@ describe('compare-command', () => {
format: DEFAULT_PERSIST_FORMAT,
},
expect.any(Object),
undefined,
);
});

it('should forward label from command line', async () => {
await yargsCli(
[
'compare',
'--before=source-report.json',
'--after=target-report.json',
'--label=core',
],
{ ...DEFAULT_CLI_CONFIGURATION, commands: [yargsCompareCommandObject()] },
).parseAsync();

expect(compareReportFiles).toHaveBeenCalledWith<
Parameters<typeof compareReportFiles>
>(
{ before: 'source-report.json', after: 'target-report.json' },
expect.any(Object),
expect.any(Object),
'core',
);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lib/implementation/compare.model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { Diff } from '@code-pushup/utils';

export type CompareOptions = Diff<string>;
export type CompareOptions = Diff<string> & { label?: string };
4 changes: 4 additions & 0 deletions packages/cli/src/lib/implementation/compare.options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ export function yargsCompareOptionsDefinition(): Record<
type: 'string',
demandOption: true,
},
label: {
describe: 'Label for diff (e.g. project name)',
type: 'string',
},
};
}

0 comments on commit b3494d6

Please sign in to comment.