Skip to content
Merged
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
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,
});
});
});