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

[cli] Migrate vc dns to updated argument parsing utilities #11537

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
6 changes: 3 additions & 3 deletions packages/cli/src/commands/dns/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,16 @@ export const dnsCommand: Command = {
description: 'Show next page of results',
argument: 'MS',
shorthand: 'n',
type: String,
type: Number,
deprecated: false,
},
{
name: 'limit',
shorthand: 'n',
shorthand: null,
description:
'Number of results to return per page (default: 20, max: 100)',
argument: 'NUMBER',
type: String,
type: Number,
deprecated: false,
},
],
Expand Down
27 changes: 14 additions & 13 deletions packages/cli/src/commands/dns/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Client from '../../util/client';
import getArgs from '../../util/get-args';
import { parseArguments } from '../../util/get-args';
import getSubcommand from '../../util/get-subcommand';
import handleError from '../../util/handle-error';

Expand All @@ -9,6 +9,7 @@ import ls from './ls';
import rm from './rm';
import { dnsCommand } from './command';
import { help } from '../help';
import { getFlagsSpecification } from '../../util/get-flags-specification';

const COMMAND_CONFIG = {
add: ['add'],
Expand All @@ -18,33 +19,33 @@ const COMMAND_CONFIG = {
};

export default async function dns(client: Client) {
let argv;
let parsedArgs;

const flagsSpecification = getFlagsSpecification(dnsCommand.options);
try {
argv = getArgs(client.argv.slice(2), {
'--next': Number,
'-N': '--next',
'--limit': Number,
});
parsedArgs = parseArguments(client.argv.slice(2), flagsSpecification);
} catch (error) {
handleError(error);
return 1;
}

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

const { subcommand, args } = getSubcommand(argv._.slice(1), COMMAND_CONFIG);
const { subcommand, args } = getSubcommand(
parsedArgs.args.slice(1),
COMMAND_CONFIG
);
switch (subcommand) {
case 'add':
return add(client, argv, args);
return add(client, parsedArgs.flags, args);
case 'import':
return importZone(client, argv, args);
return importZone(client, parsedArgs.flags, args);
case 'rm':
return rm(client, argv, args);
return rm(client, parsedArgs.flags, args);
default:
return ls(client, argv, args);
return ls(client, parsedArgs.flags, args);
}
}
22 changes: 10 additions & 12 deletions packages/cli/test/unit/commands/__snapshots__/help.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -925,13 +925,12 @@ exports[`help command > dns help output snapshots > dns help column width 40 1`]

Options:

-n, --limit <NUMBER> Number of
results to
return per page
(default: 20,
max: 100)
-n, --next <MS> Show next page
of results
--limit <NUMBER> Number of results to
return per page
(default: 20, max:
100)
-n, --next <MS> Show next page of
results


Global Options:
Expand Down Expand Up @@ -1024,9 +1023,8 @@ exports[`help command > dns help output snapshots > dns help column width 80 1`]

Options:

-n, --limit <NUMBER> Number of results to return per page (default: 20, max:
100)
-n, --next <MS> Show next page of results
--limit <NUMBER> Number of results to return per page (default: 20, max: 100)
-n, --next <MS> Show next page of results


Global Options:
Expand Down Expand Up @@ -1094,8 +1092,8 @@ exports[`help command > dns help output snapshots > dns help column width 120 1`

Options:

-n, --limit <NUMBER> Number of results to return per page (default: 20, max: 100)
-n, --next <MS> Show next page of results
--limit <NUMBER> Number of results to return per page (default: 20, max: 100)
-n, --next <MS> Show next page of results


Global Options:
Expand Down