mirror of
https://github.com/floci-io/floci-cli.git
synced 2026-11-22 21:50:47 -05:00
fix: updating with latest floci changes
This commit is contained in:
16 files changed
+378
-116
No files matched your search
@@ -0,0 +1,83 @@
|
||||
package io.floci.cli.commands;
|
||||
|
||||
import io.floci.cli.GlobalOptions;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import io.floci.cli.output.OutputFormat;
|
||||
import io.floci.cli.output.Printer;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "env",
|
||||
description = "Print AWS environment variables to connect to Floci",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class EnvCommand implements Callable<Integer> {
|
||||
|
||||
@Mixin
|
||||
GlobalOptions global;
|
||||
|
||||
@Option(names = {"--host"},
|
||||
description = "Hostname for the AWS endpoint URL (default: localhost.floci.io)",
|
||||
defaultValue = "${FLOCI_HOST:-localhost.floci.io}",
|
||||
paramLabel = "<host>")
|
||||
String host;
|
||||
|
||||
@Option(names = {"--region"},
|
||||
description = "AWS region (default: us-east-1)",
|
||||
defaultValue = "${AWS_DEFAULT_REGION:-us-east-1}",
|
||||
paramLabel = "<region>")
|
||||
String region;
|
||||
|
||||
@Option(names = {"--shell"},
|
||||
description = "Shell format: bash, fish, powershell (default: bash)",
|
||||
defaultValue = "bash",
|
||||
paramLabel = "bash|fish|powershell")
|
||||
String shell;
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
Printer printer = global.printer();
|
||||
int port = extractPort(global.endpoint);
|
||||
String endpointUrl = "http://" + host + ":" + port;
|
||||
|
||||
Map<String, String> vars = new LinkedHashMap<>();
|
||||
vars.put("AWS_ENDPOINT_URL", endpointUrl);
|
||||
vars.put("AWS_ACCESS_KEY_ID", "test");
|
||||
vars.put("AWS_SECRET_ACCESS_KEY", "test");
|
||||
vars.put("AWS_DEFAULT_REGION", region);
|
||||
|
||||
if (printer.format() != OutputFormat.text) {
|
||||
printer.structured(vars);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (Map.Entry<String, String> entry : vars.entrySet()) {
|
||||
printer.println(formatExport(entry.getKey(), entry.getValue()));
|
||||
}
|
||||
printer.println("");
|
||||
printer.println(Ansi.gray("# Run: eval $(floci env)"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
private String formatExport(String key, String value) {
|
||||
return switch (shell.toLowerCase()) {
|
||||
case "fish" -> "set -x " + key + " \"" + value + "\"";
|
||||
case "powershell", "ps1" -> "$env:" + key + " = \"" + value + "\"";
|
||||
default -> "export " + key + "=" + value;
|
||||
};
|
||||
}
|
||||
|
||||
private int extractPort(String endpoint) {
|
||||
try {
|
||||
int port = URI.create(endpoint).getPort();
|
||||
return port == -1 ? 4566 : port;
|
||||
} catch (Exception e) {
|
||||
return 4566;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user