Skip to main content

ytcli/cli/
link.rs

1//! The vocabulary of links between issues.
2//!
3//! Read-only, and a group of its own rather than a verb under `issue`: a link
4//! type is organisation-wide and about a relationship *between* issues, not a
5//! value one issue's field takes — which is what `dict` is for, and why these
6//! do not fit it. `issue link` is the write and shares no token with this.
7
8use 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    /// List the kinds of link, and what a write takes for each.
17    #[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}