Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 65 additions & 8 deletions crates/openshell-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,11 @@ enum Commands {

/// Show gateway status and information.
#[command(help_template = LEAF_HELP_TEMPLATE, next_help_heading = "FLAGS")]
Status,
Status {
/// Output format.
#[arg(short = 'o', long = "output", value_enum, default_value_t = OutputFormat::Table)]
output: OutputFormat,
},

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

/// Output format.
#[arg(short = 'o', long = "output", value_enum, default_value_t = OutputFormat::Table, conflicts_with_all = ["editor", "command", "no_keep", "forward"])]
output: OutputFormat,

/// Command to run after "--" (defaults to an interactive shell).
#[arg(last = true, allow_hyphen_values = true)]
command: Vec<String>,
Expand All @@ -1447,8 +1455,12 @@ enum SandboxCommands {
name: Option<String>,

/// Print only the active policy YAML (same policy as the default view; stdout only).
#[arg(long)]
#[arg(long, conflicts_with = "output")]
policy_only: bool,

/// Output format.
#[arg(short = 'o', long = "output", value_enum, default_value_t = OutputFormat::Table)]
output: OutputFormat,
},

/// List sandboxes.
Expand Down Expand Up @@ -2270,11 +2282,24 @@ async fn main() -> Result<()> {
// -----------------------------------------------------------
// Top-level status
// -----------------------------------------------------------
Some(Commands::Status) => {
Some(Commands::Status { output }) => {
if let Ok(ctx) = resolve_gateway(&cli.gateway, &cli.gateway_endpoint) {
let mut tls = tls.with_gateway_name(&ctx.name);
let auth_error = apply_auth_with_status(&mut tls, &ctx.name);
run::gateway_status(&ctx.name, &ctx.endpoint, &tls, auth_error.as_deref()).await?;
run::gateway_status(
&ctx.name,
&ctx.endpoint,
output.as_str(),
&tls,
auth_error.as_deref(),
)
.await?;
} else if openshell_cli::output::print_output_single(
output.as_str(),
&(),
|()| serde_json::json!({"status": "not_configured"}),
)? {
// Structured output handled.
} else {
println!("{}", "Gateway Status".cyan().bold());
println!();
Expand Down Expand Up @@ -2885,6 +2910,7 @@ async fn main() -> Result<()> {
labels,
envs,
approval_mode,
output,
command,
} => {
// Resolve --tty / --no-tty into an Option<bool> override.
Expand Down Expand Up @@ -2971,6 +2997,7 @@ async fn main() -> Result<()> {
labels: labels_map,
environment: env_map,
approval_mode: &approval_mode,
output: output.as_str(),
},
&cli.workspace,
&tls,
Expand Down Expand Up @@ -3030,10 +3057,21 @@ async fn main() -> Result<()> {
| SandboxCommands::Download { .. } => {
unreachable!()
}
SandboxCommands::Get { name, policy_only } => {
SandboxCommands::Get {
name,
policy_only,
output,
} => {
let name = resolve_sandbox_name(name, &ctx.name, &cli.workspace)?;
run::sandbox_get(endpoint, &name, policy_only, &cli.workspace, &tls)
.await?;
run::sandbox_get(
endpoint,
&name,
policy_only,
output.as_str(),
&cli.workspace,
&tls,
)
.await?;
}
SandboxCommands::List {
limit,
Expand Down Expand Up @@ -3883,7 +3921,7 @@ mod tests {
.expect("global gateway flag should parse with subcommands");

assert_eq!(cli.gateway.as_deref(), Some("demo"));
assert!(matches!(cli.command, Some(Commands::Status)));
assert!(matches!(cli.command, Some(Commands::Status { .. })));
}

#[test]
Expand Down Expand Up @@ -5025,6 +5063,25 @@ mod tests {
);
}

#[test]
fn sandbox_create_output_conflicts_with_side_effect_args() {
for (label, extra_args) in [
("--editor", &["--editor", "code"][..]),
("trailing command", &["--", "claude"][..]),
("--no-keep", &["--no-keep"][..]),
("--forward", &["--forward", "8080"][..]),
] {
let args = ["openshell", "sandbox", "create", "--output", "json"]
.into_iter()
.chain(extra_args.iter().copied());
let result = Cli::try_parse_from(args);
assert!(
result.is_err(),
"structured output should conflict with {label}"
);
}
}

#[test]
fn sandbox_create_resource_flags_parse() {
let cli = Cli::try_parse_from([
Expand Down
Loading
Loading