mirror of
https://github.com/floci-io/floci-cli.git
synced 2026-12-03 10:17:49 -05:00
chore: first commit
This commit is contained in:
69 files changed
+3697
No files matched your search
@@ -0,0 +1,26 @@
|
||||
package io.floci.cli.commands.snapshot;
|
||||
|
||||
import picocli.CommandLine;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
@Command(
|
||||
name = "snapshot",
|
||||
description = "Manage Floci state snapshots",
|
||||
mixinStandardHelpOptions = true,
|
||||
subcommands = {
|
||||
SnapshotSaveCommand.class,
|
||||
SnapshotLoadCommand.class,
|
||||
SnapshotListCommand.class,
|
||||
SnapshotDeleteCommand.class,
|
||||
SnapshotExportCommand.class,
|
||||
SnapshotImportCommand.class,
|
||||
HelpCommand.class
|
||||
}
|
||||
)
|
||||
public class SnapshotCommand implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
new CommandLine(this).usage(System.out);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package io.floci.cli.commands.snapshot;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.http.FlociException;
|
||||
import io.floci.cli.http.FlociHttpClient;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import io.floci.cli.output.Printer;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "delete",
|
||||
description = "Delete a snapshot",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class SnapshotDeleteCommand implements Callable<Integer> {
|
||||
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
|
||||
@Parameters(index = "0", description = "Snapshot name", paramLabel = "<name>")
|
||||
String name;
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
Printer printer = global.printer();
|
||||
FlociHttpClient client = new FlociHttpClient(global.endpoint);
|
||||
try {
|
||||
client.deleteSnapshot(name);
|
||||
printer.println(Ansi.green("Snapshot deleted:") + " " + name);
|
||||
return 0;
|
||||
} catch (FlociException e) {
|
||||
printer.error("Failed to delete snapshot: " + e.getMessage());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package io.floci.cli.commands.snapshot;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.output.Printer;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "export",
|
||||
description = "Export a snapshot to a tarball file",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class SnapshotExportCommand implements Callable<Integer> {
|
||||
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
|
||||
@Parameters(index = "0", description = "Snapshot name", paramLabel = "<name>")
|
||||
String name;
|
||||
|
||||
@Option(names = {"--file", "-f"}, description = "Destination file path", required = true, paramLabel = "<path>")
|
||||
String outputFile;
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
Printer printer = global.printer();
|
||||
// TODO: implement GET /_floci/snapshots/<name>/export streaming to file
|
||||
printer.error("snapshot export requires floci-server >= 1.6.0\n" +
|
||||
"See TODO.md for the required server-side API contract.");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package io.floci.cli.commands.snapshot;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.output.Printer;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "import",
|
||||
description = "Import a snapshot from a tarball file",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class SnapshotImportCommand implements Callable<Integer> {
|
||||
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
|
||||
@Option(names = {"--file", "-f"}, description = "Source tarball path", required = true, paramLabel = "<path>")
|
||||
String inputFile;
|
||||
|
||||
@Option(names = {"--name"}, description = "Name for the imported snapshot", paramLabel = "<name>")
|
||||
String name;
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
Printer printer = global.printer();
|
||||
// TODO: implement POST /_floci/snapshots/import with multipart upload
|
||||
printer.error("snapshot import requires floci-server >= 1.6.0\n" +
|
||||
"See TODO.md for the required server-side API contract.");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package io.floci.cli.commands.snapshot;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.http.FlociException;
|
||||
import io.floci.cli.http.FlociHttpClient;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import io.floci.cli.output.OutputFormat;
|
||||
import io.floci.cli.output.Printer;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "list",
|
||||
description = "List available snapshots",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class SnapshotListCommand implements Callable<Integer> {
|
||||
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
Printer printer = global.printer();
|
||||
FlociHttpClient client = new FlociHttpClient(global.endpoint);
|
||||
try {
|
||||
var node = client.listSnapshots();
|
||||
if (printer.format() != OutputFormat.text) {
|
||||
printer.structured(node);
|
||||
return 0;
|
||||
}
|
||||
if (node.isArray() && node.size() == 0) {
|
||||
printer.println(Ansi.gray("No snapshots found."));
|
||||
return 0;
|
||||
}
|
||||
printer.println(Ansi.bold("Snapshots:"));
|
||||
node.forEach(s -> printer.println(" " + s.asText()));
|
||||
return 0;
|
||||
} catch (FlociException e) {
|
||||
if (e.getMessage().contains("404") || e.getMessage().contains("501")) {
|
||||
printer.error("Snapshot API not available on this server version.\n" +
|
||||
"See TODO.md for the required server-side API contract.");
|
||||
} else {
|
||||
printer.error("Failed to list snapshots: " + e.getMessage());
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package io.floci.cli.commands.snapshot;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.http.FlociException;
|
||||
import io.floci.cli.http.FlociHttpClient;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import io.floci.cli.output.Printer;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "load",
|
||||
description = "Restore a saved snapshot",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class SnapshotLoadCommand implements Callable<Integer> {
|
||||
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
|
||||
@Parameters(index = "0", description = "Snapshot name", paramLabel = "<name>")
|
||||
String name;
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
Printer printer = global.printer();
|
||||
FlociHttpClient client = new FlociHttpClient(global.endpoint);
|
||||
try {
|
||||
client.loadSnapshot(name);
|
||||
printer.println(Ansi.green("Snapshot loaded:") + " " + name);
|
||||
return 0;
|
||||
} catch (FlociException e) {
|
||||
if (e.getMessage().contains("404") || e.getMessage().contains("501")) {
|
||||
printer.error("Snapshot API not available on this server version.\n" +
|
||||
"See TODO.md for the required server-side API contract.");
|
||||
} else {
|
||||
printer.error("Failed to load snapshot: " + e.getMessage());
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package io.floci.cli.commands.snapshot;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.http.FlociException;
|
||||
import io.floci.cli.http.FlociHttpClient;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import io.floci.cli.output.Printer;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "save",
|
||||
description = "Save the current Floci state as a named snapshot",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class SnapshotSaveCommand implements Callable<Integer> {
|
||||
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
|
||||
@Parameters(index = "0", description = "Snapshot name", paramLabel = "<name>")
|
||||
String name;
|
||||
|
||||
@Option(names = {"--message", "-m"}, description = "Optional description", paramLabel = "<text>")
|
||||
String message;
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
Printer printer = global.printer();
|
||||
FlociHttpClient client = new FlociHttpClient(global.endpoint);
|
||||
try {
|
||||
client.postSnapshot(name);
|
||||
printer.println(Ansi.green("Snapshot saved:") + " " + name);
|
||||
return 0;
|
||||
} catch (FlociException e) {
|
||||
if (e.getMessage().contains("404") || e.getMessage().contains("501")) {
|
||||
printer.error("Snapshot API not available on this server version.\n" +
|
||||
"See TODO.md for the required server-side API contract.");
|
||||
} else {
|
||||
printer.error("Failed to save snapshot: " + e.getMessage());
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user