From 30a4de9198f72bb2cc445c932501b0c846729c33 Mon Sep 17 00:00:00 2001 From: Kristopher Rahim Afful-Brown Date: Fri, 3 Nov 2023 11:06:53 +0000 Subject: [PATCH 1/4] rename the success message --- src/subcommands/env.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/subcommands/env.ts b/src/subcommands/env.ts index be348132..5417487a 100644 --- a/src/subcommands/env.ts +++ b/src/subcommands/env.ts @@ -78,7 +78,7 @@ 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"); From 57e80c07f05ca6809619b0b3fc55265506d9709b Mon Sep 17 00:00:00 2001 From: Kristopher Rahim Afful-Brown Date: Fri, 3 Nov 2023 11:10:57 +0000 Subject: [PATCH 2/4] print error instead of throwing just like with deploy subcommnad --- src/subcommands/env.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/subcommands/env.ts b/src/subcommands/env.ts index 5417487a..d7ade02f 100644 --- a/src/subcommands/env.ts +++ b/src/subcommands/env.ts @@ -80,12 +80,11 @@ async function env(opts: SecretsOpts) { envSpinner.succeed( "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)); } } From 454bcc5786fc178532a95779e4a5e32afaae5f90 Mon Sep 17 00:00:00 2001 From: Kristopher Rahim Afful-Brown Date: Fri, 3 Nov 2023 11:19:04 +0000 Subject: [PATCH 3/4] added help info for envs --- deployctl.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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: From 8c4f7246ea68b2b21f49d599f6198c0394e4358b Mon Sep 17 00:00:00 2001 From: Kristopher Rahim Afful-Brown Date: Tue, 28 Nov 2023 21:17:07 +0000 Subject: [PATCH 4/4] update the pairs helper to be synchronos --- src/subcommands/env.ts | 9 ++++++++- src/utils/pairs.ts | 21 +++++++++------------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/subcommands/env.ts b/src/subcommands/env.ts index d7ade02f..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, }; 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; }