Skip to content

Commit 212217a

Browse files
committed
feat(cli): add --output json/yaml to sandbox get, status, and sandbox create
Add structured output support (JSON and YAML) to sandbox lifecycle commands: sandbox get, status, and sandbox create. Introduce ProgressOutput enum to cleanly separate interactive, plain, and silent display modes during sandbox provisioning. Signed-off-by: Roland Huß <[email protected]>
1 parent 59f7839 commit 212217a

6 files changed

Lines changed: 622 additions & 108 deletions

File tree

‎crates/openshell-cli/src/main.rs‎

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,11 @@ enum Commands {
582582

583583
/// Show gateway status and information.
584584
#[command(help_template = LEAF_HELP_TEMPLATE, next_help_heading = "FLAGS")]
585-
Status,
585+
Status {
586+
/// Output format.
587+
#[arg(short = 'o', long = "output", value_enum, default_value_t = OutputFormat::Table)]
588+
output: OutputFormat,
589+
},
586590

587591
/// Manage inference configuration.
588592
#[command(after_help = INFERENCE_EXAMPLES, help_template = SUBCOMMAND_HELP_TEMPLATE)]
@@ -1434,6 +1438,10 @@ enum SandboxCommands {
14341438
#[arg(long, value_parser = ["manual", "auto"], default_value = "manual")]
14351439
approval_mode: String,
14361440

1441+
/// Output format.
1442+
#[arg(short = 'o', long = "output", value_enum, default_value_t = OutputFormat::Table, conflicts_with_all = ["editor", "command", "no_keep"])]
1443+
output: OutputFormat,
1444+
14371445
/// Command to run after "--" (defaults to an interactive shell).
14381446
#[arg(last = true, allow_hyphen_values = true)]
14391447
command: Vec<String>,
@@ -1447,8 +1455,12 @@ enum SandboxCommands {
14471455
name: Option<String>,
14481456

14491457
/// Print only the active policy YAML (same policy as the default view; stdout only).
1450-
#[arg(long)]
1458+
#[arg(long, conflicts_with = "output")]
14511459
policy_only: bool,
1460+
1461+
/// Output format.
1462+
#[arg(short = 'o', long = "output", value_enum, default_value_t = OutputFormat::Table)]
1463+
output: OutputFormat,
14521464
},
14531465

14541466
/// List sandboxes.
@@ -2270,11 +2282,17 @@ async fn main() -> Result<()> {
22702282
// -----------------------------------------------------------
22712283
// Top-level status
22722284
// -----------------------------------------------------------
2273-
Some(Commands::Status) => {
2285+
Some(Commands::Status { output }) => {
22742286
if let Ok(ctx) = resolve_gateway(&cli.gateway, &cli.gateway_endpoint) {
22752287
let mut tls = tls.with_gateway_name(&ctx.name);
22762288
let auth_error = apply_auth_with_status(&mut tls, &ctx.name);
2277-
run::gateway_status(&ctx.name, &ctx.endpoint, &tls, auth_error.as_deref()).await?;
2289+
run::gateway_status(&ctx.name, &ctx.endpoint, output.as_str(), &tls, auth_error.as_deref()).await?;
2290+
} else if openshell_cli::output::print_output_single(
2291+
output.as_str(),
2292+
&(),
2293+
|()| serde_json::json!({"status": "not_configured"}),
2294+
)? {
2295+
// Structured output handled.
22782296
} else {
22792297
println!("{}", "Gateway Status".cyan().bold());
22802298
println!();
@@ -2885,6 +2903,7 @@ async fn main() -> Result<()> {
28852903
labels,
28862904
envs,
28872905
approval_mode,
2906+
output,
28882907
command,
28892908
} => {
28902909
// Resolve --tty / --no-tty into an Option<bool> override.
@@ -2971,6 +2990,7 @@ async fn main() -> Result<()> {
29712990
labels: labels_map,
29722991
environment: env_map,
29732992
approval_mode: &approval_mode,
2993+
output: output.as_str(),
29742994
},
29752995
&cli.workspace,
29762996
&tls,
@@ -3030,10 +3050,21 @@ async fn main() -> Result<()> {
30303050
| SandboxCommands::Download { .. } => {
30313051
unreachable!()
30323052
}
3033-
SandboxCommands::Get { name, policy_only } => {
3053+
SandboxCommands::Get {
3054+
name,
3055+
policy_only,
3056+
output,
3057+
} => {
30343058
let name = resolve_sandbox_name(name, &ctx.name, &cli.workspace)?;
3035-
run::sandbox_get(endpoint, &name, policy_only, &cli.workspace, &tls)
3036-
.await?;
3059+
run::sandbox_get(
3060+
endpoint,
3061+
&name,
3062+
policy_only,
3063+
output.as_str(),
3064+
&cli.workspace,
3065+
&tls,
3066+
)
3067+
.await?;
30373068
}
30383069
SandboxCommands::List {
30393070
limit,
@@ -3883,7 +3914,7 @@ mod tests {
38833914
.expect("global gateway flag should parse with subcommands");
38843915

38853916
assert_eq!(cli.gateway.as_deref(), Some("demo"));
3886-
assert!(matches!(cli.command, Some(Commands::Status)));
3917+
assert!(matches!(cli.command, Some(Commands::Status { .. })));
38873918
}
38883919

38893920
#[test]

0 commit comments

Comments
 (0)