Skip to content

Commit

Permalink
fix(logs): support project name in positional argument (#177)
Browse files Browse the repository at this point in the history
Fixes #176
  • Loading branch information
magurotuna authored Sep 12, 2023
1 parent fe510d9 commit 02c3c4b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/subcommands/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ generated, and query persisted logs where the logs generated in the past are fet
To show the live logs of a project's latest deployment:
deployctl logs --project=helloworld
deployctl logs helloworld
To show the live logs of a particular deployment:
deployctl logs --project=helloworld --deployment=1234567890ab
Expand Down Expand Up @@ -206,12 +207,19 @@ export function parseArgsForLogSubcommand(args: Args): LogSubcommandArgs {
regions = args.regions.split(",");
}

let project: string | null = null;
if (args.project !== undefined) {
project = args.project;
} else if (typeof args._[0] === "string") {
project = args._[0];
}

return {
help: !!args.help,
prod: !!args.prod,
token: args.token ? String(args.token) : null,
deployment: args.deployment ? String(args.deployment) : null,
project: args.project ? String(args.project) : null,
project,
since,
until,
grep: args.grep,
Expand Down
26 changes: 25 additions & 1 deletion src/subcommands/logs_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { parseArgs } from "../args.ts";

Deno.test("parseArgsForLogSubcommand", async (t) => {
const parseHelper = (args: string[]) =>
parseArgsForLogSubcommand(parseArgs(["logs", ...args]));
// NOTE: We omit `logs` subcommand from the arguments passed to `parseArgs()`
// in order to match the actual behavior; the first positional argument is
// removed using `args._.shift()` in `deployctl.ts`.
parseArgsForLogSubcommand(parseArgs(args));

await t.step("specify help", () => {
const got = parseHelper(["--help"]);
Expand Down Expand Up @@ -83,4 +86,25 @@ Deno.test("parseArgsForLogSubcommand", async (t) => {
limit: 42,
});
});

await t.step("specify project name in a positional argument", () => {
const got = parseHelper([
"--prod",
"--token=abc",
"project_name",
]);
assertEquals(got, {
help: false,
prod: true,
token: "abc",
deployment: null,
project: "project_name",
since: null,
until: null,
grep: [],
levels: null,
regions: null,
limit: 100,
});
});
});

0 comments on commit 02c3c4b

Please sign in to comment.