|
| 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