diff --git a/deployctl.ts b/deployctl.ts index f70418db..b91bfe21 100755 --- a/deployctl.ts +++ b/deployctl.ts @@ -25,6 +25,7 @@ SUBCOMMANDS: deploy Deploy a script with static files to Deno Deploy upgrade Upgrade deployctl to the given version (defaults to latest) logs View logs for the given project + env Manage Deploy environment variables `; if (!semverGreaterThanOrEquals(Deno.version.deno, MINIMUM_DENO_VERSION)) { @@ -88,7 +89,7 @@ switch (subcommand) { case "logs": await logsSubcommand(args); break; - case "secrets": + case "env": await envSubcommand(args); break; default: diff --git a/src/subcommands/env.ts b/src/subcommands/env.ts index be348132..0a16b1db 100644 --- a/src/subcommands/env.ts +++ b/src/subcommands/env.ts @@ -49,8 +49,15 @@ export default async function (rawArgs: Record): Promise { error("Missing project ID."); } + let envVars = {}; + try { + envVars = parsePairs(rawArgs._); + } catch (e) { + error(e); + } + const opts = { - envVars: await parsePairs(rawArgs._).catch((e) => error(e)), + envVars, token, project: args.project, }; @@ -78,14 +85,13 @@ async function env(opts: SecretsOpts) { try { await api.setEnvs(project!.id, opts.envVars); envSpinner.succeed( - "A new production deployment will be created automatically with the new environment variables when you next push your code.", + "A new production deployment with the updated environment variables has been made.", ); - } catch (err) { - envSpinner.fail("Failed to update environment variables"); + } catch (err: unknown) { if (err instanceof APIError) { + envSpinner.fail("Failed to update environment variables"); error(err.toString()); - } else { - throw err; } + error(String(err)); } } diff --git a/src/utils/pairs.ts b/src/utils/pairs.ts index 59836a3c..ab457187 100644 --- a/src/utils/pairs.ts +++ b/src/utils/pairs.ts @@ -1,16 +1,13 @@ export function parsePairs( args: string[], -): Promise> { - return new Promise((res, rej) => { - const out: Record = {}; - - for (const arg of args) { - const parts = arg.split("=", 2); - if (parts.length !== 2) { - return rej(`${arg} must be in the format NAME=VALUE`); - } - out[parts[0]] = parts[1]; +): Record { + const out: Record = {}; + for (const arg of args) { + const parts = arg.split("=", 2); + if (parts.length !== 2) { + throw new Error(`${arg} must be in the format NAME=VALUE`); } - return res(out); - }); + out[parts[0]] = parts[1]; + } + return out; }