-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion.rs
More file actions
81 lines (74 loc) · 2.35 KB
/
version.rs
File metadata and controls
81 lines (74 loc) · 2.35 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use super::Context;
use crate::cli::BuildInfo;
use crate::cli::sink::Error as SinkError;
use crate::cli::sink::Sink;
use crate::httpclient::Error as HttpError;
use crate::httpclient::data::VersionInfo;
use clap::Parser;
use serde::Serialize;
use snafu::{ResultExt, Snafu};
use std::fmt;
/// Prints version about server and client.
///
/// Queries the server for its version information and prints more
/// version details about this client.
#[derive(Parser, Debug, PartialEq)]
pub struct Input {
/// Only show the client version and don't request server side
/// version information.
#[arg(long, default_value_t = false)]
pub client_only: bool,
}
#[derive(Debug, Snafu)]
pub enum Error {
#[snafu(display("An http error occurred: {}", source))]
HttpClient { source: HttpError },
#[snafu(display("Error writing data: {}", source))]
WriteResult { source: SinkError },
}
impl Input {
pub async fn exec(&self, ctx: &Context) -> Result<(), Error> {
if self.client_only {
let vinfo = BuildInfo::default();
ctx.write_result(&vinfo).await.context(WriteResultSnafu)?;
} else {
let result = ctx
.client
.version(
ctx.opts.verbosity.log_level().unwrap_or(log::Level::Warn) > log::Level::Info,
)
.await
.context(HttpClientSnafu)?;
let urlstr = ctx.renku_url().as_str();
let vinfo = Versions::create(result, urlstr);
ctx.write_result(&vinfo).await.context(WriteResultSnafu)?;
}
Ok(())
}
}
#[derive(Debug, Serialize)]
pub struct Versions<'a> {
pub client: BuildInfo,
pub server: VersionInfo,
pub renku_url: &'a str,
}
impl Versions<'_> {
pub fn create(server: VersionInfo, renku_url: &str) -> Versions<'_> {
Versions {
client: BuildInfo::default(),
server,
renku_url,
}
}
}
impl fmt::Display for Versions<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let hc = &self.server.search.head_commit[..8];
write!(
f,
"Client:\n{}\n\nRenku @ {}\n Data Services: {}\n Search Services: {} ({})",
self.client, self.renku_url, self.server.data.version, self.server.search.version, hc
)
}
}
impl Sink for Versions<'_> {}