use clap::Subcommand;
use crate::cli::{Session, emit, report};
use crate::exit::ExitCode;
use crate::render::{Format, dict as render, machine};
#[derive(Debug, Subcommand)]
pub enum LinkCommand {
#[command(long_about = crate::cli::help::md(crate::cli::help::LINK_TYPES))]
Types,
}
pub async fn run(command: &LinkCommand, session: &Session) -> ExitCode {
let client = match session.client() {
Ok(client) => client,
Err(code) => return code,
};
let LinkCommand::Types = command;
match client.link_types().await {
Ok(types) => {
let rendered = match session.render.format {
Format::Text => Ok(render::link_types(&types, &session.render)),
Format::JsonRaw => machine(&types, Format::Json),
other => machine(&types, other),
};
match rendered {
Ok(text) => {
emit(&text);
ExitCode::Success
}
Err(error) => report(&error, ExitCode::Failure),
}
}
Err(error) => {
let code = error.exit_code();
report(&error, code)
}
}
}