Skip to content

Commit

Permalink
[eas-cli] Fix flags and args
Browse files Browse the repository at this point in the history
Fixed flags and args in `secret` commands

See: https://linear.app/expo/issue/ENG-9175/update-oclif-in-eas-cli
  • Loading branch information
radoslawkrzemien committed Dec 1, 2023
1 parent 00d3322 commit 8e46cfc
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 17 deletions.
57 changes: 44 additions & 13 deletions packages/eas-cli/src/commands/secret/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import { EnvironmentSecretMutation } from '../../graphql/mutations/EnvironmentSe
import {
EnvironmentSecretScope,
EnvironmentSecretsQuery,
getEnvironmentSecretScope,
} from '../../graphql/queries/EnvironmentSecretsQuery';
import {
SecretType,
SecretTypeToEnvironmentSecretType,
maybeGetSecretType,
} from '../../graphql/types/EnvironmentSecret';
import Log from '../../log';
import {
Expand All @@ -22,14 +24,35 @@ import {
} from '../../project/projectUtils';
import { promptAsync, selectAsync } from '../../prompts';

interface RawSecretCreateFlags {
scope: string;
name?: string;
value?: string;
type?: string;
force: boolean;
'non-interactive'?: boolean;
}

interface SecretCreateCommandFlags {
scope: EnvironmentSecretScope;
name?: string;
value?: string;
type?: SecretType;
force: boolean;
'non-interactive': boolean;
}

const SCOPE_FLAG_OPTIONS = [EnvironmentSecretScope.ACCOUNT, EnvironmentSecretScope.PROJECT];
const TYPE_FLAG_OPTIONS = [SecretType.STRING, SecretType.FILE];

export default class EnvironmentSecretCreate extends EasCommand {
static override description =
'create an environment secret on the current project or owner account';

static override flags = {
scope: Flags.enum({
scope: Flags.string({
description: 'Scope for the secret',
options: [EnvironmentSecretScope.ACCOUNT, EnvironmentSecretScope.PROJECT],
options: SCOPE_FLAG_OPTIONS,
default: EnvironmentSecretScope.PROJECT,
}),
name: Flags.string({
Expand All @@ -38,9 +61,9 @@ export default class EnvironmentSecretCreate extends EasCommand {
value: Flags.string({
description: 'Text value or path to a file to store in the secret',
}),
type: Flags.enum({
type: Flags.string({
description: 'The type of secret',
options: [SecretType.STRING, SecretType.FILE],
options: TYPE_FLAG_OPTIONS,
}),
force: Flags.boolean({
description: 'Delete and recreate existing secrets',
Expand All @@ -55,16 +78,15 @@ export default class EnvironmentSecretCreate extends EasCommand {
};

async runAsync(): Promise<void> {
const { flags } = await this.parse(EnvironmentSecretCreate);
let {
flags: {
name,
value: secretValue,
scope,
force,
type: secretType,
'non-interactive': nonInteractive,
},
} = await this.parse(EnvironmentSecretCreate);
name,
value: secretValue,
scope,
force,
type: secretType,
'non-interactive': nonInteractive,
} = await this.sanitizeFlagsAsync(flags);
const {
privateProjectConfig: { projectId },
loggedIn: { graphqlClient },
Expand Down Expand Up @@ -265,4 +287,13 @@ export default class EnvironmentSecretCreate extends EasCommand {
}
}
}

private async sanitizeFlagsAsync(flags: RawSecretCreateFlags): Promise<SecretCreateCommandFlags> {
return {
...flags,
scope: getEnvironmentSecretScope(flags.scope),
type: maybeGetSecretType(flags.type),
'non-interactive': flags['non-interactive'] ?? false,
};
}
}
37 changes: 33 additions & 4 deletions packages/eas-cli/src/commands/secret/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { EnvironmentSecretMutation } from '../../graphql/mutations/EnvironmentSe
import {
EnvironmentSecretScope,
EnvironmentSecretsQuery,
getEnvironmentSecretScope,
} from '../../graphql/queries/EnvironmentSecretsQuery';
import Log from '../../log';
import { ora } from '../../ora';
Expand All @@ -22,13 +23,29 @@ import {
import { promptAsync } from '../../prompts';
import intersection from '../../utils/expodash/intersection';

interface RawSecretPushFlags {
scope: string;
'env-file'?: string;
force: boolean;
'non-interactive'?: boolean;
}

interface SecretPushCommandFlags {
scope: EnvironmentSecretScope;
'env-file'?: string;
force: boolean;
'non-interactive': boolean;
}

const SCOPE_FLAG_OPTIONS = [EnvironmentSecretScope.ACCOUNT, EnvironmentSecretScope.PROJECT];

export default class EnvironmentSecretPush extends EasCommand {
static override description = 'read environment secrets from env file and store on the server';

static override flags = {
scope: Flags.enum({
scope: Flags.string({
description: 'Scope for the secrets',
options: [EnvironmentSecretScope.ACCOUNT, EnvironmentSecretScope.PROJECT],
options: SCOPE_FLAG_OPTIONS,
default: EnvironmentSecretScope.PROJECT,
}),
'env-file': Flags.string({
Expand All @@ -47,9 +64,13 @@ export default class EnvironmentSecretPush extends EasCommand {
};

async runAsync(): Promise<void> {
const { flags } = await this.parse(EnvironmentSecretPush);
const {
flags: { scope, force, 'env-file': maybeEnvFilePath, 'non-interactive': nonInteractive },
} = await this.parse(EnvironmentSecretPush);
scope,
force,
'env-file': maybeEnvFilePath,
'non-interactive': nonInteractive,
} = await this.sanitizeFlagsAsync(flags);
const {
privateProjectConfig: { projectId },
loggedIn: { graphqlClient },
Expand Down Expand Up @@ -94,6 +115,14 @@ export default class EnvironmentSecretPush extends EasCommand {
Log.log(`- ${secretName}`);
}
}

private async sanitizeFlagsAsync(flags: RawSecretPushFlags): Promise<SecretPushCommandFlags> {
return {
...flags,
scope: getEnvironmentSecretScope(flags.scope),
'non-interactive': flags['non-interactive'] ?? false,
};
}
}

async function resolveEnvFilePathAsync(
Expand Down

0 comments on commit 8e46cfc

Please sign in to comment.