mirror of
https://github.com/floci-io/floci-cli.git
synced 2026-11-22 21:50:47 -05:00
chore: first commit
This commit is contained in:
69 files changed
+3697
No files matched your search
@@ -0,0 +1,61 @@
|
||||
package io.floci.cli.commands;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.docker.DockerException;
|
||||
import io.floci.cli.output.Printer;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "logs",
|
||||
description = "Fetch logs from the Floci container",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class LogsCommand implements Callable<Integer> {
|
||||
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
|
||||
@Option(names = {"--follow", "-f"}, description = "Follow log output")
|
||||
boolean follow;
|
||||
|
||||
@Option(names = {"--tail"}, description = "Number of lines from the end (0 = all)", defaultValue = "100", paramLabel = "<n>")
|
||||
int tail;
|
||||
|
||||
@Option(names = {"--since"}, description = "Show logs since duration (e.g. 5m, 1h) or timestamp", paramLabel = "<duration>")
|
||||
String since;
|
||||
|
||||
@Option(names = {"--service"}, description = "Filter to a specific service (not yet supported; requires server-side filtering)", paramLabel = "<name>")
|
||||
String service;
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
Printer printer = global.printer();
|
||||
DockerClient docker = new DockerClient();
|
||||
|
||||
try {
|
||||
var info = docker.inspectContainer(global.container);
|
||||
if (info.isEmpty()) {
|
||||
printer.error("Container '" + global.container + "' not found.\nRun 'floci start' to launch one.");
|
||||
return 1;
|
||||
}
|
||||
} catch (DockerException e) {
|
||||
printer.error("Failed to inspect container: " + e.getMessage());
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (service != null) {
|
||||
printer.warn("--service filtering is not yet supported. Showing all container logs.");
|
||||
}
|
||||
|
||||
try {
|
||||
docker.streamLogs(global.container, follow, tail, since);
|
||||
return 0;
|
||||
} catch (DockerException e) {
|
||||
printer.error("Failed to fetch logs: " + e.getMessage());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user