codeberg_cli/actions/api/
version.rs

1use crate::{
2    actions::GeneralArgs,
3    render::json::JsonToStdout,
4    types::{context::BergContext, output::OutputMode},
5};
6
7use clap::Parser;
8
9/// Display short summary of the authenticated user account
10#[derive(Parser, Debug)]
11pub struct ApiVersionArgs {}
12
13impl ApiVersionArgs {
14    pub async fn run(self, general_args: GeneralArgs) -> anyhow::Result<()> {
15        let ctx = BergContext::new(self, general_args).await?;
16        let version = ctx.client.get_version().await?;
17
18        match general_args.output_mode {
19            OutputMode::Pretty => match version.version {
20                Some(version) => println!("Version: {version}"),
21                None => println!("No version detected"),
22            },
23            OutputMode::Json => version.print_json()?,
24        }
25
26        Ok(())
27    }
28}