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

496 consistent boolean flags #683

Merged
merged 5 commits into from
Aug 24, 2022
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
12 changes: 12 additions & 0 deletions src/base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ValidationErrors } from '.';
import AppService from './app-config/service';
import { prettyValidationErrors } from './common/dependency-manager/validation';
import LoginRequiredError from './common/errors/login-required';
import { isBooleanStringFlag } from './common/utils/oclif';
import SentryService from './sentry';

const DEPRECATED_LABEL = '[deprecated]';
Expand Down Expand Up @@ -78,7 +79,18 @@ export default abstract class BaseCommand extends Command {
const args = [];
const flags = [];
let flag_option = false;

const new_args = [];
for (const arg of argv) {
if (!arg.startsWith('-')) {
new_args.push(arg);
} else {
const flag = arg.startsWith('--') ? flag_definitions[arg.replace('--', '')] : Object.values(flag_definitions).find((f: any) => f.char === arg.replace('-', ''));
new_args.push(isBooleanStringFlag(flag) ? `${arg}=true` : arg);
}
}

for (const arg of new_args) {
const is_flag = arg.startsWith('-');

if (is_flag || flag_option) {
Expand Down
22 changes: 11 additions & 11 deletions src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import PipelineUtils from '../architect/pipeline/pipeline.utils';
import BaseCommand from '../base-command';
import { DeploymentFailedError, PipelineAbortedError, PollingTimeout } from '../common/errors/pipeline-errors';
import DeployUtils from '../common/utils/deploy.utils';
import { booleanString } from '../common/utils/oclif';
import { buildSpecFromPath } from '../dependency-manager/spec/utils/component-builder';
import { ComponentVersionSlugUtils } from '../dependency-manager/spec/utils/slugs';
import Dev from "./dev";
Expand Down Expand Up @@ -80,17 +81,19 @@ export default class Deploy extends DeployCommand {
...DeployCommand.flags,
...AccountUtils.flags,
...EnvironmentUtils.flags,
local: Flags.boolean({
local: booleanString({
char: 'l',
description: `${BaseCommand.DEPRECATED} Deploy the stack locally instead of via Architect Cloud`,
exclusive: ['account', 'auto-approve', 'auto_approve', 'refresh'],
hidden: true,
sensitive: false,
default: undefined,
}),
production: Flags.boolean({
production: booleanString({
description: `${BaseCommand.DEPRECATED} Please use --environment.`,
dependsOn: ['local'],
sensitive: false,
default: undefined,
}),
compose_file: Flags.string({
description: `${BaseCommand.DEPRECATED} Please use --compose-file.`,
Expand All @@ -105,11 +108,12 @@ export default class Deploy extends DeployCommand {
exclusive: ['account', 'environment', 'auto-approve', 'auto_approve', 'refresh'],
sensitive: false,
}),
detached: Flags.boolean({
detached: booleanString({
description: 'Run in detached mode',
char: 'd',
dependsOn: ['local'],
sensitive: false,
default: undefined,
}),
parameter: Flags.string({
char: 'p',
Expand Down Expand Up @@ -146,30 +150,26 @@ export default class Deploy extends DeployCommand {
multiple: true,
description: `${BaseCommand.DEPRECATED} Please use --secret-file.`,
}),
'deletion-protection': Flags.boolean({
'deletion-protection': booleanString({
default: true,
allowNo: true,
description: '[default: true] Toggle for deletion protection on deployments',
exclusive: ['local'],
sensitive: false,
}),
recursive: Flags.boolean({
recursive: booleanString({
char: 'r',
default: true,
allowNo: true,
description: '[default: true] Toggle to automatically deploy all dependencies',
sensitive: false,
}),
refresh: Flags.boolean({
refresh: booleanString({
default: true,
hidden: true,
allowNo: true,
exclusive: ['local', 'compose-file', 'compose_file'],
sensitive: false,
}),
browser: Flags.boolean({
browser: booleanString({
default: true,
allowNo: true,
description: '[default: true] Automatically open urls in the browser for local deployments',
sensitive: false,
}),
Expand Down
17 changes: 9 additions & 8 deletions src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export default class Dev extends BaseCommand {

static examples = [
'architect dev ./mycomponent/architect.yml',
'architect dev --port=81 --no-browser --debug=true --secret-file=./mycomponent/mysecrets.yml ./mycomponent/architect.yml',
'architect dev --port=81 --browser=false --debug=true --secret-file=./mycomponent/mysecrets.yml ./mycomponent/architect.yml',
];

static flags = {
Expand Down Expand Up @@ -236,16 +236,14 @@ export default class Dev extends BaseCommand {
multiple: true,
default: [],
}),
recursive: Flags.boolean({
recursive: booleanString({
char: 'r',
default: true,
allowNo: true,
description: '[default: true] Toggle to automatically deploy all dependencies',
sensitive: false,
}),
browser: Flags.boolean({
browser: booleanString({
default: true,
allowNo: true,
description: '[default: true] Automatically open urls in the browser for local deployments',
sensitive: false,
}),
Expand All @@ -254,18 +252,20 @@ export default class Dev extends BaseCommand {
sensitive: false,
}),
// Used for proxy from deploy to dev. These will be removed once --local is deprecated
local: Flags.boolean({
local: booleanString({
char: 'l',
description: `${Command.DEPRECATED} Deploy the stack locally instead of via Architect Cloud`,
exclusive: ['account', 'auto-approve', 'auto_approve', 'refresh'],
hidden: true,
sensitive: false,
default: undefined,
}),
production: Flags.boolean({
production: booleanString({
description: `${Command.DEPRECATED} Please use --environment.`,
dependsOn: ['local'],
hidden: true,
sensitive: false,
default: undefined,
}),
compose_file: Flags.string({
description: `${Command.DEPRECATED} Please use --compose-file.`,
Expand All @@ -278,10 +278,11 @@ export default class Dev extends BaseCommand {
hidden: true,
description: `${Command.DEPRECATED} Please use --secret-file.`,
}),
detached: Flags.boolean({
detached: booleanString({
description: 'Run in detached mode',
char: 'd',
sensitive: false,
default: false,
}),
debug: booleanString({
description: `[default: true] Turn debug mode on (true) or off (false)`,
Expand Down
10 changes: 6 additions & 4 deletions src/commands/environments/destroy.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { CliUx, Flags, Interfaces } from '@oclif/core';
import { CliUx, Interfaces } from '@oclif/core';
import chalk from 'chalk';
import inquirer from 'inquirer';
import AccountUtils from '../../architect/account/account.utils';
import { EnvironmentUtils } from '../../architect/environment/environment.utils';
import BaseCommand from '../../base-command';
import { booleanString } from '../../common/utils/oclif';

export default class EnvironmentDestroy extends BaseCommand {
static aliases = ['environment:destroy', 'envs:destroy', 'env:destroy', 'env:deregister', 'environment:deregister'];
Expand All @@ -15,17 +16,18 @@ export default class EnvironmentDestroy extends BaseCommand {
static flags = {
...BaseCommand.flags,
...AccountUtils.flags,
auto_approve: Flags.boolean({
auto_approve: booleanString({
description: `${BaseCommand.DEPRECATED} Please use --auto-approve.`,
hidden: true,
sensitive: false,
default: false,
}),
['auto-approve']: Flags.boolean({
['auto-approve']: booleanString({
description: 'Automatically apply the changes',
default: false,
sensitive: false,
}),
force: Flags.boolean({
force: booleanString({
description: 'Force the deletion even if the environment is not empty',
char: 'f',
default: false,
Expand Down
7 changes: 3 additions & 4 deletions src/commands/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import AccountUtils from '../architect/account/account.utils';
import { EnvironmentUtils, Replica } from '../architect/environment/environment.utils';
import BaseCommand from '../base-command';
import { DockerComposeUtils } from '../common/docker-compose';
import { booleanString } from '../common/utils/oclif';

enum RemoteExecCommandOutputStatus {
SUCCESS = 'Success',
Expand Down Expand Up @@ -46,16 +47,14 @@ export default class Exec extends BaseCommand {
...BaseCommand.flags,
...AccountUtils.flags,
...EnvironmentUtils.flags,
stdin: Flags.boolean({
stdin: booleanString({
description: 'Pass stdin to the container. Only works on remote deploys.',
char: 'i',
allowNo: true,
default: true,
}),
tty: Flags.boolean({
tty: booleanString({
description: 'Stdin is a TTY. If the flag isn\'t supplied, tty or no-tty is automatically detected.',
char: 't',
allowNo: true,
default: undefined,
sensitive: false,
}),
Expand Down
7 changes: 4 additions & 3 deletions src/commands/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Environment from '../architect/environment/environment.entity';
import { EnvironmentUtils, Replica } from '../architect/environment/environment.utils';
import BaseCommand from '../base-command';
import { DockerComposeUtils } from '../common/docker-compose';
import { booleanString } from '../common/utils/oclif';

export default class Logs extends BaseCommand {
async auth_required(): Promise<boolean> {
Expand All @@ -25,7 +26,7 @@ export default class Logs extends BaseCommand {
...BaseCommand.flags,
...AccountUtils.flags,
...EnvironmentUtils.flags,
follow: Flags.boolean({
follow: booleanString({
description: 'Specify if the logs should be streamed.',
char: 'f',
default: false,
Expand All @@ -36,7 +37,7 @@ export default class Logs extends BaseCommand {
default: '',
sensitive: false,
}),
raw: Flags.boolean({
raw: booleanString({
description: 'Show the raw output of the logs.',
default: false,
sensitive: false,
Expand All @@ -46,7 +47,7 @@ export default class Logs extends BaseCommand {
default: -1,
sensitive: false,
}),
timestamps: Flags.boolean({
timestamps: booleanString({
description: 'Include timestamps on each line in the log output.',
default: false,
sensitive: false,
Expand Down
9 changes: 7 additions & 2 deletions src/commands/platforms/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import PipelineUtils from '../../architect/pipeline/pipeline.utils';
import { CreatePlatformInput } from '../../architect/platform/platform.utils';
import BaseCommand from '../../base-command';
import { KubernetesPlatformUtils } from '../../common/utils/kubernetes-platform.utils';
import { booleanString } from '../../common/utils/oclif';

export default class PlatformCreate extends BaseCommand {
static aliases = ['platforms:register', 'platform:create', 'platforms:create'];
Expand All @@ -25,12 +26,16 @@ export default class PlatformCreate extends BaseCommand {
static flags = {
...BaseCommand.flags,
...AccountUtils.flags,
auto_approve: Flags.boolean({
auto_approve: booleanString({
description: `${BaseCommand.DEPRECATED} Please use --auto-approve.`,
hidden: true,
sensitive: false,
default: false,
}),
['auto-approve']: booleanString({
sensitive: false,
default: false,
}),
['auto-approve']: Flags.boolean({ sensitive: false }),
type: Flags.string({
char: 't',
options: ['KUBERNETES', 'kubernetes'],
Expand Down
10 changes: 6 additions & 4 deletions src/commands/platforms/destroy.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { CliUx, Flags, Interfaces } from '@oclif/core';
import { CliUx, Interfaces } from '@oclif/core';
import chalk from 'chalk';
import inquirer from 'inquirer';
import AccountUtils from '../../architect/account/account.utils';
import PlatformUtils from '../../architect/platform/platform.utils';
import BaseCommand from '../../base-command';
import { booleanString } from '../../common/utils/oclif';

export default class PlatformDestroy extends BaseCommand {
static aliases = ['platforms:deregister', 'platform:destroy', 'platforms:destroy'];
Expand All @@ -15,17 +16,18 @@ export default class PlatformDestroy extends BaseCommand {
static flags = {
...BaseCommand.flags,
...AccountUtils.flags,
auto_approve: Flags.boolean({
auto_approve: booleanString({
description: `${BaseCommand.DEPRECATED} Please use --auto-approve.`,
hidden: true,
sensitive: false,
default: false,
}),
['auto-approve']: Flags.boolean({
['auto-approve']: booleanString({
description: 'Automatically apply the changes',
default: false,
sensitive: false,
}),
force: Flags.boolean({
force: booleanString({
description: 'Force the deletion even if the platform is not empty',
char: 'f',
default: false,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/secrets/upload.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Flags } from '@oclif/core';
import fs from 'fs-extra';
import yaml from 'js-yaml';
import path from 'path';
Expand All @@ -9,6 +8,7 @@ import { EnvironmentUtils } from '../../architect/environment/environment.utils'
import SecretUtils, { Secret } from '../../architect/secret/secret.utils';
import UserUtils from '../../architect/user/user.utils';
import BaseCommand from '../../base-command';
import { booleanString } from '../../common/utils/oclif';
import { SecretsDict } from '../../dependency-manager/secrets/type';

export default class SecretsUpload extends BaseCommand {
Expand All @@ -22,7 +22,7 @@ export default class SecretsUpload extends BaseCommand {
...BaseCommand.flags,
...AccountUtils.flags,
...EnvironmentUtils.flags,
override: Flags.boolean({
override: booleanString({
description: 'Allow override of existing secrets',
default: false,
sensitive: false,
Expand Down
4 changes: 3 additions & 1 deletion src/commands/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { EnvironmentUtils } from '../architect/environment/environment.utils';
import BaseCommand from '../base-command';
import { DockerComposeUtils } from '../common/docker-compose';
import * as Docker from '../common/utils/docker';
import { booleanString } from '../common/utils/oclif';

export default class TaskExec extends BaseCommand {
static aliases = ['task:exec'];
Expand All @@ -25,11 +26,12 @@ export default class TaskExec extends BaseCommand {
...AccountUtils.flags,
...EnvironmentUtils.flags,

local: Flags.boolean({
local: booleanString({
char: 'l',
description: 'Deploy the stack locally instead of via Architect Cloud',
exclusive: ['account', 'auto-approve', 'auto_approve', 'refresh'],
sensitive: false,
default: false,
}),
compose_file: Flags.string({
description: `${BaseCommand.DEPRECATED} Please use --compose-file.`,
Expand Down
5 changes: 3 additions & 2 deletions src/commands/unlink.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Flags } from '@oclif/core';
import chalk from 'chalk';
import path from 'path';
import untildify from 'untildify';
import { buildSpecFromPath } from '../';
import BaseCommand from '../base-command';
import { booleanString } from '../common/utils/oclif';

export default class Unlink extends BaseCommand {
async auth_required(): Promise<boolean> {
Expand All @@ -18,9 +18,10 @@ export default class Unlink extends BaseCommand {
];
static flags = {
...BaseCommand.flags,
all: Flags.boolean({
all: booleanString({
description: 'Unlink all components registered locally',
sensitive: false,
default: false,
}),
};

Expand Down