-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathversion.rs
More file actions
47 lines (38 loc) · 1.14 KB
/
version.rs
File metadata and controls
47 lines (38 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use std::sync::Arc;
use clap::{Args, Subcommand};
use snafu::{ResultExt, Snafu};
use stackable_cockpit::xfer;
use tracing::instrument;
use crate::{cli::Cli, release_check};
#[derive(Debug, Args)]
pub struct VersionArguments {
#[command(subcommand)]
subcommand: VersionCommand,
}
#[derive(Debug, Subcommand)]
pub enum VersionCommand {
/// Check if there is a new version available.
Check,
}
#[derive(Debug, Snafu)]
pub enum CmdError {
#[snafu(display("failed to retrieve latest release"))]
RetrieveLatestRelease { source: crate::release_check::Error },
}
impl VersionArguments {
pub async fn run(&self, client: Arc<xfer::Client>) -> Result<String, CmdError> {
match &self.subcommand {
VersionCommand::Check => check_cmd(client).await,
}
}
}
#[instrument(skip_all)]
async fn check_cmd(client: Arc<xfer::Client>) -> Result<String, CmdError> {
let output = release_check::version_notice_output(client, true, false)
.await
.context(RetrieveLatestReleaseSnafu)?
.unwrap_or_default();
let mut result = Cli::result();
result.with_output(output);
Ok(result.render())
}