Skip to content

Commit 5f28484

Browse files
committed
feat(cli): add rollups logs command
1 parent 6a68e5f commit 5f28484

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

.changeset/evil-colts-rule.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cartesi/cli": major
3+
---
4+
5+
add rollups logs command

apps/cli/src/commands/rollups.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Command } from "@commander-js/extra-typings";
22
import { createDeployCommand } from "./rollups/deploy.js";
3+
import { createLogsCommand } from "./rollups/logs.js";
34
import { createStartCommand } from "./rollups/start.js";
45
import { createStatusCommand } from "./rollups/status.js";
56
import { createStopCommand } from "./rollups/stop.js";
@@ -14,6 +15,7 @@ export const createRollupsCommand = () => {
1415
.action(async (_options, program) => {
1516
program.help();
1617
});
18+
command.addCommand(createLogsCommand());
1719
command.addCommand(createStartCommand());
1820
command.addCommand(createStatusCommand());
1921
command.addCommand(createStopCommand());
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { Command } from "@commander-js/extra-typings";
2+
import { execa } from "execa";
3+
import { RollupsCommandOpts } from "../rollups.js";
4+
5+
export const createLogsCommand = () => {
6+
return new Command<[], {}, RollupsCommandOpts>("logs")
7+
.description("Show logs of a local rollups node environment.")
8+
.option("-f, --follow", "Follow log output")
9+
.option("--no-color", "Produce monochrome output")
10+
.option("--no-log-prefix", "Don't print prefix in logs")
11+
.option(
12+
"--since <string>",
13+
"Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)",
14+
)
15+
.option(
16+
"-n, --tail <string>",
17+
"Number of lines to show from the end of the logs",
18+
"all",
19+
)
20+
.option("-t, --timestamps", "Show timestamps")
21+
.option(
22+
"--until <string>",
23+
"Show logs before a timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)",
24+
)
25+
.configureHelp({ showGlobalOptions: true })
26+
.action(
27+
async (
28+
{ follow, color, logPrefix, since, tail, timestamps, until },
29+
command,
30+
) => {
31+
const { projectName } = command.optsWithGlobals();
32+
const logOptions: string[] = [];
33+
if (follow) logOptions.push("--follow");
34+
if (color === false) logOptions.push("--no-color");
35+
if (logPrefix === false) logOptions.push("--no-log-prefix");
36+
if (since) logOptions.push("--since", since);
37+
if (tail) logOptions.push("--tail", tail);
38+
if (timestamps) logOptions.push("--timestamps");
39+
await execa(
40+
"docker",
41+
[
42+
"compose",
43+
"-p",
44+
projectName,
45+
"logs",
46+
...logOptions,
47+
"rollups-node",
48+
],
49+
{ stdio: "inherit" },
50+
);
51+
},
52+
);
53+
};

0 commit comments

Comments
 (0)