Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion deployctl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -88,7 +89,7 @@ switch (subcommand) {
case "logs":
await logsSubcommand(args);
break;
case "secrets":
case "env":
await envSubcommand(args);
break;
default:
Expand Down
18 changes: 12 additions & 6 deletions src/subcommands/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,15 @@ export default async function (rawArgs: Record<string, any>): Promise<void> {
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,
};
Expand Down Expand Up @@ -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));
}
}
21 changes: 9 additions & 12 deletions src/utils/pairs.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
export function parsePairs(
args: string[],
): Promise<Record<string, string>> {
return new Promise((res, rej) => {
const out: Record<string, string> = {};

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<string, string> {
const out: Record<string, string> = {};
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;
}