mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-09 21:07:46 +00:00
[cli] Migrate alias command to use parseArguments and getFlagsSpecification (#11467)
Migrating `vc alias` to use new argument parsing utilities. Note that our snapshot tests show that our help text was out of sync with what we were actually parsing from the user. In particular, we were showing `-n` as the shorthand for both `next` and `limit` and neither of these had this shortflag. `next` was parsing `-N` (capital), so I've updated it to that. `--json` was parsed, but wasn't mentioned in the help text. I've kept it this way, but it may be worth adding a description. We may want to have a separate discussion about the nature and role of `json` output from our CLI as a whole.
This commit is contained in:
@@ -52,7 +52,7 @@ export const aliasCommand: Command = {
|
||||
name: 'next',
|
||||
description: 'Show next page of results',
|
||||
argument: 'MS',
|
||||
shorthand: 'n',
|
||||
shorthand: 'N',
|
||||
type: String,
|
||||
deprecated: false,
|
||||
},
|
||||
@@ -65,13 +65,14 @@ export const aliasCommand: Command = {
|
||||
},
|
||||
{
|
||||
name: 'limit',
|
||||
shorthand: 'n',
|
||||
shorthand: null,
|
||||
description:
|
||||
'Number of results to return per page (default: 20, max: 100)',
|
||||
argument: 'NUMBER',
|
||||
type: String,
|
||||
deprecated: false,
|
||||
},
|
||||
{ name: 'json', shorthand: null, type: Boolean, deprecated: false },
|
||||
],
|
||||
examples: [
|
||||
{
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { handleError } from '../../util/error';
|
||||
import Client from '../../util/client';
|
||||
import getArgs from '../../util/get-args';
|
||||
import { parseArguments } from '../../util/get-args';
|
||||
import getSubcommand from '../../util/get-subcommand';
|
||||
import { help } from '../help';
|
||||
import ls from './ls';
|
||||
import rm from './rm';
|
||||
import set from './set';
|
||||
import { aliasCommand } from './command';
|
||||
import { getFlagsSpecification } from '../../util/get-flags-specification';
|
||||
|
||||
const COMMAND_CONFIG = {
|
||||
default: ['set'],
|
||||
@@ -16,35 +17,33 @@ const COMMAND_CONFIG = {
|
||||
};
|
||||
|
||||
export default async function alias(client: Client) {
|
||||
let argv;
|
||||
let parsedArguments;
|
||||
|
||||
const flagsSpecification = getFlagsSpecification(aliasCommand.options);
|
||||
|
||||
try {
|
||||
argv = getArgs(client.argv.slice(2), {
|
||||
'--json': Boolean,
|
||||
'--yes': Boolean,
|
||||
'--next': Number,
|
||||
'--limit': Number,
|
||||
'-y': '--yes',
|
||||
'-N': '--next',
|
||||
});
|
||||
parsedArguments = parseArguments(client.argv.slice(2), flagsSpecification);
|
||||
} catch (err) {
|
||||
handleError(err);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (argv['--help']) {
|
||||
if (parsedArguments.flags['--help']) {
|
||||
client.output.print(help(aliasCommand, { columns: client.stderr.columns }));
|
||||
return 2;
|
||||
}
|
||||
|
||||
const { subcommand, args } = getSubcommand(argv._.slice(1), COMMAND_CONFIG);
|
||||
const { subcommand, args } = getSubcommand(
|
||||
parsedArguments.args.slice(1),
|
||||
COMMAND_CONFIG
|
||||
);
|
||||
|
||||
switch (subcommand) {
|
||||
case 'ls':
|
||||
return ls(client, argv, args);
|
||||
return ls(client, parsedArguments.flags, args);
|
||||
case 'rm':
|
||||
return rm(client, argv, args);
|
||||
return rm(client, parsedArguments.flags, args);
|
||||
default:
|
||||
return set(client, argv, args);
|
||||
return set(client, parsedArguments.flags, args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,18 +24,16 @@ exports[`help command > alias help output snapshots > alias help column width 40
|
||||
|
||||
[2mOptions[22m:
|
||||
|
||||
-n, --limit <NUMBER> Number of
|
||||
results to
|
||||
return per page
|
||||
(default: 20,
|
||||
max: 100)
|
||||
-n, --next <MS> Show next page
|
||||
of results
|
||||
-y, --yes Skip the
|
||||
confirmation
|
||||
prompt when
|
||||
removing an
|
||||
alias
|
||||
--limit <NUMBER> Number of results to
|
||||
return per page
|
||||
(default: 20, max:
|
||||
100)
|
||||
-N, --next <MS> Show next page of
|
||||
results
|
||||
-y, --yes Skip the
|
||||
confirmation prompt
|
||||
when removing an
|
||||
alias
|
||||
|
||||
|
||||
[2mGlobal Options[22m:
|
||||
@@ -108,10 +106,9 @@ exports[`help command > alias help output snapshots > alias help column width 80
|
||||
|
||||
[2mOptions[22m:
|
||||
|
||||
-n, --limit <NUMBER> Number of results to return per page (default: 20, max:
|
||||
100)
|
||||
-n, --next <MS> Show next page of results
|
||||
-y, --yes Skip the confirmation prompt when removing an alias
|
||||
--limit <NUMBER> Number of results to return per page (default: 20, max: 100)
|
||||
-N, --next <MS> Show next page of results
|
||||
-y, --yes Skip the confirmation prompt when removing an alias
|
||||
|
||||
|
||||
[2mGlobal Options[22m:
|
||||
@@ -160,9 +157,9 @@ exports[`help command > alias help output snapshots > alias help column width 12
|
||||
|
||||
[2mOptions[22m:
|
||||
|
||||
-n, --limit <NUMBER> Number of results to return per page (default: 20, max: 100)
|
||||
-n, --next <MS> Show next page of results
|
||||
-y, --yes Skip the confirmation prompt when removing an alias
|
||||
--limit <NUMBER> Number of results to return per page (default: 20, max: 100)
|
||||
-N, --next <MS> Show next page of results
|
||||
-y, --yes Skip the confirmation prompt when removing an alias
|
||||
|
||||
|
||||
[2mGlobal Options[22m:
|
||||
|
||||
Reference in New Issue
Block a user