Skip to main content

codeberg_cli/actions/api/
version.rs

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