1use clap::Subcommand;
9
10use crate::cli::{Session, emit, report};
11use crate::exit::ExitCode;
12use crate::render::{Format, dict as render, machine};
13
14#[derive(Debug, Subcommand)]
15pub enum LinkCommand {
16 #[command(long_about = crate::cli::help::md(crate::cli::help::LINK_TYPES))]
18 Types,
19}
20
21pub async fn run(command: &LinkCommand, session: &Session) -> ExitCode {
22 let client = match session.client() {
23 Ok(client) => client,
24 Err(code) => return code,
25 };
26
27 let LinkCommand::Types = command;
28 match client.link_types().await {
29 Ok(types) => {
30 let rendered = match session.render.format {
31 Format::Text => Ok(render::link_types(&types, &session.render)),
32 Format::JsonRaw => machine(&types, Format::Json),
33 other => machine(&types, other),
34 };
35 match rendered {
36 Ok(text) => {
37 emit(&text);
38 ExitCode::Success
39 }
40 Err(error) => report(&error, ExitCode::Failure),
41 }
42 }
43 Err(error) => {
44 let code = error.exit_code();
45 report(&error, code)
46 }
47 }
48}