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 certs argument parsing #11493

Draft
wants to merge 3 commits 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
2 changes: 2 additions & 0 deletions .changeset/empty-zebras-sip.md
@@ -0,0 +1,2 @@
---
---
10 changes: 6 additions & 4 deletions packages/cli/src/commands/certs/command.ts
Expand Up @@ -49,7 +49,7 @@ export const certsCommand: Command = {
name: 'challenge-only',
description: 'Only show challenges needed to issue a cert',
shorthand: null,
type: String,
type: Boolean,
deprecated: false,
},
{
Expand Down Expand Up @@ -82,16 +82,18 @@ export const certsCommand: Command = {
'Number of results to return per page (default: 20, max: 100)',
argument: 'VALUE',
shorthand: null,
type: String,
type: Number,
deprecated: false,
},
{
name: 'next',
description: 'Show next page of results',
shorthand: 'n',
type: String,
shorthand: 'N',
type: Number,
deprecated: false,
},
{ name: 'overwrite', shorthand: null, type: Boolean, deprecated: false },
{ name: 'output', shorthand: null, type: String, deprecated: false },
Comment on lines +95 to +96
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to add a description and show help text for these flags? We've been parsing them but not showing them in the help until now.

],
examples: [
{
Expand Down
34 changes: 15 additions & 19 deletions packages/cli/src/commands/certs/index.ts
@@ -1,7 +1,7 @@
// @ts-ignore
import { handleError } from '../../util/error';

import getArgs from '../../util/get-args';
import { parseArguments } from '../../util/get-args';
import getSubcommand from '../../util/get-subcommand';

import add from './add';
Expand All @@ -11,6 +11,7 @@ import rm from './rm';
import { certsCommand } from './command';
import { help } from '../help';
import Client from '../../util/client';
import { getFlagsSpecification } from '../../util/get-flags-specification';

const COMMAND_CONFIG = {
add: ['add'],
Expand All @@ -21,41 +22,36 @@ const COMMAND_CONFIG = {
};

export default async function main(client: Client) {
let argv;
let parsedArgs = null;

const flagsSpecification = getFlagsSpecification(certsCommand.options);

try {
argv = getArgs(client.argv.slice(2), {
'--challenge-only': Boolean,
'--overwrite': Boolean,
'--output': String,
'--crt': String,
'--key': String,
'--ca': String,
'--next': Number,
'-N': '--next',
'--limit': Number,
});
parsedArgs = parseArguments(client.argv.slice(2), flagsSpecification);
} catch (err) {
handleError(err);
return 1;
}

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

const { output } = client;
const { subcommand, args } = getSubcommand(argv._.slice(1), COMMAND_CONFIG);
const { subcommand, args } = getSubcommand(
parsedArgs.args.slice(1),
COMMAND_CONFIG
);
switch (subcommand) {
case 'issue':
return issue(client, argv, args);
return issue(client, parsedArgs.flags, args);
case 'ls':
return ls(client, argv, args);
return ls(client, parsedArgs.flags, args);
case 'rm':
return rm(client, argv, args);
return rm(client, parsedArgs.flags, args);
case 'add':
return add(client, argv, args);
return add(client, parsedArgs.flags, args);
case 'renew':
output.error('Renewing certificates is deprecated, issue a new one.');
return 1;
Expand Down
Expand Up @@ -392,7 +392,7 @@ exports[`help command > certs help output snapshots > certs help column width 40
return per page
(default: 20, max:
100)
-n, --next Show next page of
-N, --next Show next page of
results


Expand Down Expand Up @@ -472,7 +472,7 @@ exports[`help command > certs help output snapshots > certs help column width 80
--crt <FILE> Certificate file
--key <FILE> Certificate key file
--limit <VALUE> Number of results to return per page (default: 20, max: 100)
-n, --next Show next page of results
-N, --next Show next page of results


Global Options:
Expand Down Expand Up @@ -527,7 +527,7 @@ exports[`help command > certs help output snapshots > certs help column width 12
--crt <FILE> Certificate file
--key <FILE> Certificate key file
--limit <VALUE> Number of results to return per page (default: 20, max: 100)
-n, --next Show next page of results
-N, --next Show next page of results


Global Options:
Expand Down