Skip to content

Commit

Permalink
Enable merge baselines command (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebekebe authored Aug 30, 2024
1 parent 32d0f88 commit 3f1e241
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
5 changes: 5 additions & 0 deletions visual-js/.changeset/tidy-penguins-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@saucelabs/visual": patch
---

Enable merge baselines command
2 changes: 2 additions & 0 deletions visual-js/visual/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
options as buildOptions,
} from './cli/build.js';
import { regionOption } from './cli/common-options.js';
import { baselinesCommand, baselinesOptions } from './cli/baselines.js';

const defaultCommand = new Command()
.name('default')
Expand All @@ -30,6 +31,7 @@ program.name('visual').description('Interacts with Sauce Visual');
program.addOption(regionOption);
program.addCommand(defaultCommand, { isDefault: true, hidden: true });
program.addCommand(buildCommand(), buildOptions);
program.addCommand(baselinesCommand(), baselinesOptions);

(async function () {
try {
Expand Down
20 changes: 9 additions & 11 deletions visual-js/visual/src/cli/baselines.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Command, CommandOptions } from 'commander';
import { VisualApiRegion } from '../common/regions';
import { VisualApi, getApi } from '../api';
import { VisualApi, getApi } from '../common/api';
import { regionOption } from './common-options';

function apiFromOptions(opts: { region: VisualApiRegion }): VisualApi {
Expand All @@ -23,7 +23,8 @@ export async function baselineMergeCommand(_: unknown, cmd: Command) {
const visualApi = apiFromOptions(options);
const result = await visualApi.mergeBaselines({
projectName: options.project,
...options,
sourceBranch: options.sourceBranch,
targetBranch: options.targetBranch,
});
console.log(`Merged baselines: ${result.baselines?.length}`);
}
Expand All @@ -33,25 +34,22 @@ const mergeCommand = () =>
.name('merge')
.description('Merge baselines from a source branch into a target branch')
.addOption(regionOption)
.requiredOption('-p, --project', 'Project name')
.requiredOption('-p, --project <project>', 'Project name')
.requiredOption(
'-s, --source-branch',
'-s, --source-branch <branch>',
'Branch from which to copy the baselines',
)
.requiredOption(
'-t, --target-branch',
'Branch into which copy the baselines',
'-t, --target-branch <branch>',
'Branch into which to copy the baselines',
)
.action(baselineMergeCommand);

/**
* command: visual baselines
*/
export const options: CommandOptions = {
hidden: false,
isDefault: false,
};
export const command = () =>
export const baselinesOptions: CommandOptions = {};
export const baselinesCommand = () =>
new Command()
.name('baselines')
.description('Interacts with Sauce Visual baselines')
Expand Down
6 changes: 3 additions & 3 deletions visual-js/visual/src/cli/common-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const regionParser = (

export const regionOption = new Option(
'-r, --region <region>',
'The Sauce Labs region. Options: us-west-1, eu-central-1 (Default: "us-west-1)"',
'The Sauce Labs region. Options: us-west-1, eu-central-1',
)
.argParser(regionParser)
.default(VisualApiRegion.fromName('us-west-1'));
.default(VisualApiRegion.fromName('us-west-1'), 'us-west-1')
.argParser(regionParser);

0 comments on commit 3f1e241

Please sign in to comment.