Skip to content

Commit

Permalink
Migrate bisect argument parsing (#11491)
Browse files Browse the repository at this point in the history
Migrate `vc bisect` to updated argument parsing.

I added a `try` block with `handleError`, this seems to be in line with how we do this in other `vc` commands. It might be worth thinking about how we might abstract this logic to centralize it.
  • Loading branch information
erikareads committed Apr 29, 2024
1 parent 97e02ae commit 863199a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .changeset/twenty-clouds-hang.md
@@ -0,0 +1,2 @@
---
---
2 changes: 1 addition & 1 deletion packages/cli/src/commands/bisect/command.ts
Expand Up @@ -27,7 +27,7 @@ export const bisectCommand: Command = {
description: 'Automatically open each URL in the browser',
argument: 'URL',
shorthand: 'o',
type: String,
type: Boolean,
deprecated: false,
},
{
Expand Down
40 changes: 20 additions & 20 deletions packages/cli/src/commands/bisect/index.ts
Expand Up @@ -8,14 +8,16 @@ import { URLSearchParams, parse } from 'url';
import box from '../../util/output/box';
import formatDate from '../../util/format-date';
import link from '../../util/output/link';
import getArgs from '../../util/get-args';
import { parseArguments } from '../../util/get-args';
import Client from '../../util/client';
import { Deployment } from '@vercel-internals/types';
import { normalizeURL } from '../../util/bisect/normalize-url';
import getScope from '../../util/get-scope';
import getDeployment from '../../util/get-deployment';
import { help } from '../help';
import { bisectCommand } from './command';
import { getFlagsSpecification } from '../../util/get-flags-specification';
import handleError from '../../util/handle-error';

interface Deployments {
deployments: Deployment[];
Expand All @@ -25,39 +27,37 @@ export default async function bisect(client: Client): Promise<number> {
const scope = await getScope(client);
const { contextName } = scope;

const argv = getArgs(client.argv.slice(2), {
'--bad': String,
'-b': '--bad',
'--good': String,
'-g': '--good',
'--open': Boolean,
'-o': '--open',
'--path': String,
'-p': '--path',
'--run': String,
'-r': '--run',
});

if (argv['--help']) {
let parsedArgs = null;

const flagsSpecification = getFlagsSpecification(bisectCommand.options);

try {
parsedArgs = parseArguments(client.argv.slice(2), flagsSpecification);
} catch (error) {
handleError(error);
return 1;
}

if (parsedArgs.flags['--help']) {
output.print(help(bisectCommand, { columns: client.stderr.columns }));
return 2;
}

let bad =
argv['--bad'] ||
parsedArgs.flags['--bad'] ||
(await client.input.text({
message: `Specify a URL where the bug occurs:`,
validate: val => (val ? true : 'A URL must be provided'),
}));
let good =
argv['--good'] ||
parsedArgs.flags['--good'] ||
(await client.input.text({
message: `Specify a URL where the bug does not occur:`,
validate: val => (val ? true : 'A URL must be provided'),
}));
let subpath = argv['--path'] || '';
let run = argv['--run'] || '';
const openEnabled = argv['--open'] || false;
let subpath = parsedArgs.flags['--path'] || '';
let run = parsedArgs.flags['--run'] || '';
const openEnabled = parsedArgs.flags['--open'] || false;

if (run) {
run = resolve(run);
Expand Down

0 comments on commit 863199a

Please sign in to comment.