use std::process::ExitCode;
use clap::Args;
use super::render::{render, TeamTopology, TopologyPayload};
use crate::client;
use crate::config::ResolvedContext;
use crate::error::CliError;
use crate::output::OutputFormat;
#[derive(Args)]
#[command(after_help = "\
Examples:
aasm topology team team-abc123
aasm topology team team-abc123 --output json
aasm topology team team-abc123 --status active
aasm topology team team-abc123 --show-budget")]
pub struct TeamArgs {
pub team_id: String,
#[arg(long)]
pub status: Option<String>,
#[arg(long)]
pub show_budget: bool,
}
pub fn run(args: TeamArgs, ctx: &ResolvedContext, output: OutputFormat) -> ExitCode {
let mut path = format!("/api/v1/topology/team/{}", args.team_id);
let mut params: Vec<String> = vec![];
if let Some(ref s) = args.status {
params.push(format!("status={s}"));
}
if args.show_budget {
params.push("show_budget=true".to_string());
}
if !params.is_empty() {
path = format!("{path}?{}", params.join("&"));
}
let rt = tokio::runtime::Runtime::new().expect("failed to create tokio runtime");
let team: TeamTopology = match rt.block_on(client::get_json(ctx, &path)) {
Ok(v) => v,
Err(CliError::Api(ref e)) if e.status() == Some(reqwest::StatusCode::NOT_FOUND) => {
eprintln!("error: team {} not found", args.team_id);
return ExitCode::from(4u8);
}
Err(e) => {
eprintln!("error: {e}");
return ExitCode::FAILURE;
}
};
render(TopologyPayload::Team(&team), output);
ExitCode::SUCCESS
}