-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.rs
More file actions
66 lines (59 loc) · 2.05 KB
/
cli.rs
File metadata and controls
66 lines (59 loc) · 2.05 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
pub mod cmd;
pub mod opts;
pub mod sink;
use self::cmd::project::Error as ProjectError;
use self::cmd::{CmdError, Context};
use self::opts::{MainOpts, SubCommand};
use serde::Serialize;
use std::fmt;
pub async fn execute_cmd(opts: MainOpts) -> Result<(), CmdError> {
let ctx = Context::new(&opts.common_opts)?;
log::info!("Running command: {:?}", opts.subcmd);
match &opts.subcmd {
SubCommand::Version(input) => input.exec(&ctx).await?,
SubCommand::Update(input) => input.exec(&ctx).await?,
SubCommand::Project(input) => input.exec(ctx).await?,
SubCommand::Clone(input) => input
.exec(ctx)
.await
.map_err(|source| ProjectError::Clone { source })?,
SubCommand::Login(input) => input.exec(&ctx).await?,
#[cfg(feature = "user-doc")]
SubCommand::UserDoc(input) => input.exec(ctx).await?,
SubCommand::Dataset(input) => input.exec(ctx).await?,
};
Ok(())
}
#[derive(Debug, Serialize)]
pub struct BuildInfo {
pub build_date: &'static str,
pub build_version: &'static str,
pub git_commit: &'static str,
pub rustc_host_triple: &'static str,
pub rustc_llvm_version: &'static str,
pub rustc_version: &'static str,
pub cargo_target_triple: &'static str,
}
impl Default for BuildInfo {
fn default() -> Self {
BuildInfo {
build_date: env!("VERGEN_BUILD_TIMESTAMP"),
build_version: env!("CARGO_PKG_VERSION"),
git_commit: env!("VERGEN_GIT_SHA"),
rustc_host_triple: env!("VERGEN_RUSTC_HOST_TRIPLE"),
rustc_llvm_version: env!("VERGEN_RUSTC_LLVM_VERSION"),
rustc_version: env!("VERGEN_RUSTC_SEMVER"),
cargo_target_triple: env!("VERGEN_CARGO_TARGET_TRIPLE"),
}
}
}
impl fmt::Display for BuildInfo {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let cc = &self.git_commit[..8];
write!(
f,
" Built at: {}\n Version: {}\n Sha: {}",
self.build_date, self.build_version, cc
)
}
}