-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathsetup.rs
More file actions
111 lines (105 loc) · 3.59 KB
/
setup.rs
File metadata and controls
111 lines (105 loc) · 3.59 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
use crate::executor::{ExecutorSupport, ToolInstallStatus, get_all_executors};
use crate::prelude::*;
use crate::system::SystemInfo;
use clap::{Args, Subcommand};
use console::style;
use std::path::Path;
use super::status::{check_mark, cross_mark, warn_mark};
#[derive(Debug, Default, Args)]
pub struct SetupArgs {
#[command(subcommand)]
command: Option<SetupCommands>,
}
#[derive(Debug, Subcommand)]
enum SetupCommands {
/// Show the installation status of CodSpeed tools
Status,
}
pub async fn run(args: SetupArgs, setup_cache_dir: Option<&Path>) -> Result<()> {
match args.command {
None => setup(setup_cache_dir).await,
Some(SetupCommands::Status) => status(),
}
}
async fn setup(setup_cache_dir: Option<&Path>) -> Result<()> {
let system_info = SystemInfo::new()?;
let executors = get_all_executors();
start_group!("Setting up the environment for all executors");
for executor in executors {
match executor.support_level(&system_info) {
ExecutorSupport::Unsupported => {
info!(
"Skipping setup for the {} executor: not supported on {}",
executor.name(),
system_info.os
);
}
ExecutorSupport::RequiresManualInstallation => {
info!(
"Skipping automatic setup for the {} executor on {}; install required tooling manually.",
executor.name(),
system_info.os
);
}
ExecutorSupport::FullySupported => {
info!(
"Setting up the environment for the executor: {}",
executor.name()
);
executor.setup(&system_info, setup_cache_dir).await?;
}
}
}
info!("Environment setup completed");
end_group!();
Ok(())
}
pub fn status() -> Result<()> {
let system_info = SystemInfo::new()?;
info!("{}", style("Tools").bold());
for executor in get_all_executors() {
// Don't probe for tooling that can't be used on this OS anyway.
if executor.support_level(&system_info) == ExecutorSupport::Unsupported {
continue;
}
match executor.tool_status() {
Some(tool_status) => match &tool_status.status {
ToolInstallStatus::Installed { version } => {
info!(
" {} {} executor: {} ({})",
check_mark(),
executor.name(),
tool_status.tool_name,
version
);
}
ToolInstallStatus::IncorrectVersion { version, message } => {
info!(
" {} {} executor: {} ({}, {})",
warn_mark(),
executor.name(),
tool_status.tool_name,
version,
message
);
}
ToolInstallStatus::NotInstalled => {
info!(
" {} {} executor: {} (not installed)",
cross_mark(),
executor.name(),
tool_status.tool_name
);
}
},
None => {
info!(
" {} {} executor: No tool to install",
check_mark(),
executor.name()
);
}
}
}
Ok(())
}