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 env to updated argument parsing utilities #11539

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
4 changes: 3 additions & 1 deletion packages/cli/src/commands/env/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const envCommand: Command = {
description:
'Set the Environment (development, preview, production) when pulling Environment Variables',
shorthand: null,
type: Boolean,
type: String,
deprecated: false,
},
{
Expand All @@ -106,6 +106,8 @@ export const envCommand: Command = {
type: Boolean,
deprecated: false,
},
{ name: 'sensitive', type: Boolean, shorthand: null, deprecated: false },
{ name: 'force', type: Boolean, shorthand: null, deprecated: false },
],
examples: [
{
Expand Down
28 changes: 13 additions & 15 deletions packages/cli/src/commands/env/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
getEnvTargetPlaceholder,
isValidEnvTarget,
} from '../../util/env/env-target';
import getArgs from '../../util/get-args';
import { parseArguments } from '../../util/get-args';
import getInvalidSubcommand from '../../util/get-invalid-subcommand';
import getSubcommand from '../../util/get-subcommand';
import handleError from '../../util/handle-error';
Expand All @@ -17,6 +17,7 @@ import ls from './ls';
import pull from './pull';
import rm from './rm';
import { envCommand } from './command';
import { getFlagsSpecification } from '../../util/get-flags-specification';

const COMMAND_CONFIG = {
ls: ['ls', 'list'],
Expand All @@ -26,32 +27,29 @@ const COMMAND_CONFIG = {
};

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

const flagsSpecification = getFlagsSpecification(envCommand.options);

try {
argv = getArgs(client.argv.slice(2), {
'--yes': Boolean,
'-y': '--yes',
'--environment': String,
'--git-branch': String,
'--sensitive': Boolean,
'--force': Boolean,
});
parsedArgs = parseArguments(client.argv.slice(2), flagsSpecification);
} catch (error) {
handleError(error);
return 1;
}

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

const subArgs = argv._.slice(1);
const subArgs = parsedArgs.args.slice(1);
const { subcommand, args } = getSubcommand(subArgs, COMMAND_CONFIG);
const { cwd, output, config } = client;

const target = argv['--environment']?.toLowerCase() || 'development';
const target =
parsedArgs.flags['--environment']?.toLowerCase() || 'development';
if (!isValidEnvTarget(target)) {
output.error(
`Invalid environment \`${chalk.cyan(
Expand All @@ -76,11 +74,11 @@ export default async function main(client: Client) {
config.currentTeam = org.type === 'team' ? org.id : undefined;
switch (subcommand) {
case 'ls':
return ls(client, project, argv, args, output);
return ls(client, project, parsedArgs.flags, args, output);
case 'add':
return add(client, project, argv, args, output);
return add(client, project, parsedArgs.flags, args, output);
case 'rm':
return rm(client, project, argv, args, output);
return rm(client, project, parsedArgs.flags, args, output);
case 'pull':
return pull(
client,
Expand Down