use crate::client::CellosClient;
use crate::exit::CtlResult;
use crate::model::{Cell, Formation, List};
use crate::output::{self, OutputFormat};
pub async fn formations(client: &CellosClient, fmt: OutputFormat) -> CtlResult<()> {
let list: List<Formation> = client.get_json("/v1/formations").await?;
output::render_formations(&list.items, fmt);
Ok(())
}
pub async fn cells(
client: &CellosClient,
formation: Option<&str>,
fmt: OutputFormat,
) -> CtlResult<()> {
let path = match formation {
Some(f) => format!("/v1/cells?formation={}", urlencode(f)),
None => "/v1/cells".to_string(),
};
let list: List<Cell> = client.get_json(&path).await?;
output::render_cells(&list.items, fmt);
Ok(())
}
fn urlencode(s: &str) -> String {
url::form_urlencoded::byte_serialize(s.as_bytes()).collect()
}