Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate bisect argument parsing #11491

Merged
merged 3 commits into from Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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