Skip to content

Commit fc2d61e

Browse files
feat: add codspeed setup status cli command
1 parent 8f28259 commit fc2d61e

2 files changed

Lines changed: 112 additions & 5 deletions

File tree

src/cli/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ enum Commands {
8484
/// Manage the CLI authentication state
8585
Auth(auth::AuthArgs),
8686
/// Pre-install the codspeed executors
87-
Setup,
87+
Setup(setup::SetupArgs),
8888
/// Set the codspeed mode for the rest of the shell session
8989
Use(use_mode::UseArgs),
9090
/// Show the codspeed mode previously set in this shell session with `codspeed use`
@@ -137,7 +137,7 @@ pub async fn run() -> Result<()> {
137137
.await?
138138
}
139139
Commands::Auth(args) => auth::run(args, &api_client, cli.config_name.as_deref()).await?,
140-
Commands::Setup => setup::setup(setup_cache_dir).await?,
140+
Commands::Setup(args) => setup::run(args, &api_client, setup_cache_dir).await?,
141141
Commands::Use(args) => use_mode::run(args)?,
142142
Commands::Show => show::run()?,
143143
}
@@ -154,7 +154,7 @@ impl Cli {
154154
config_name: None,
155155
config: None,
156156
setup_cache_dir: None,
157-
command: Commands::Setup,
157+
command: Commands::Setup(setup::SetupArgs::default()),
158158
}
159159
}
160160
}

src/cli/setup.rs

Lines changed: 109 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,37 @@
1-
use crate::executor::get_all_executors;
1+
use crate::VERSION;
2+
use crate::api_client::CodSpeedAPIClient;
3+
use crate::config::CodSpeedConfig;
4+
use crate::executor::{ToolInstallStatus, get_all_executors};
25
use crate::prelude::*;
36
use crate::system::SystemInfo;
7+
use clap::{Args, Subcommand};
8+
use console::style;
49
use std::path::Path;
510

6-
pub async fn setup(setup_cache_dir: Option<&Path>) -> Result<()> {
11+
#[derive(Debug, Default, Args)]
12+
pub struct SetupArgs {
13+
#[command(subcommand)]
14+
command: Option<SetupCommands>,
15+
}
16+
17+
#[derive(Debug, Subcommand)]
18+
enum SetupCommands {
19+
/// Show the status of the CodSpeed setup (authentication, installed tools, system info)
20+
Status,
21+
}
22+
23+
pub async fn run(
24+
args: SetupArgs,
25+
api_client: &CodSpeedAPIClient,
26+
setup_cache_dir: Option<&Path>,
27+
) -> Result<()> {
28+
match args.command {
29+
None => setup(setup_cache_dir).await,
30+
Some(SetupCommands::Status) => status(api_client).await,
31+
}
32+
}
33+
34+
async fn setup(setup_cache_dir: Option<&Path>) -> Result<()> {
735
let system_info = SystemInfo::new()?;
836
let executors = get_all_executors();
937
start_group!("Setting up the environment for all executors");
@@ -18,3 +46,82 @@ pub async fn setup(setup_cache_dir: Option<&Path>) -> Result<()> {
1846
end_group!();
1947
Ok(())
2048
}
49+
50+
fn check_mark() -> console::StyledObject<&'static str> {
51+
style("✓").green()
52+
}
53+
54+
fn cross_mark() -> console::StyledObject<&'static str> {
55+
style("✗").red()
56+
}
57+
58+
fn warn_mark() -> console::StyledObject<&'static str> {
59+
style("!").yellow()
60+
}
61+
62+
async fn status(api_client: &CodSpeedAPIClient) -> Result<()> {
63+
// Authentication
64+
info!("{}", style("Authentication").bold());
65+
let config = CodSpeedConfig::load_with_override(None, None)?;
66+
if config.auth.token.is_some() {
67+
if api_client.is_token_valid().await {
68+
info!(" {} Logged in", check_mark());
69+
} else {
70+
info!(
71+
" {} Token expired (run {} to re-authenticate)",
72+
cross_mark(),
73+
style("codspeed auth login").cyan()
74+
);
75+
}
76+
} else {
77+
info!(
78+
" {} Not logged in (run {} to authenticate)",
79+
cross_mark(),
80+
style("codspeed auth login").cyan()
81+
);
82+
}
83+
info!("");
84+
85+
// Installed tools
86+
info!("{}", style("Tools").bold());
87+
for executor in get_all_executors() {
88+
let tool_status = executor.tool_status();
89+
match &tool_status.status {
90+
ToolInstallStatus::Installed { version } => {
91+
info!(" {} {} ({})", check_mark(), tool_status.tool_name, version);
92+
}
93+
ToolInstallStatus::IncorrectVersion { version, message } => {
94+
info!(
95+
" {} {} ({}, {})",
96+
warn_mark(),
97+
tool_status.tool_name,
98+
version,
99+
message
100+
);
101+
}
102+
ToolInstallStatus::NotInstalled => {
103+
info!(
104+
" {} {} (not installed)",
105+
cross_mark(),
106+
tool_status.tool_name
107+
);
108+
}
109+
}
110+
}
111+
info!("");
112+
113+
// System info
114+
info!("{}", style("System").bold());
115+
info!(" codspeed {VERSION}");
116+
let system_info = SystemInfo::new()?;
117+
info!(
118+
" {} {} ({})",
119+
system_info.os, system_info.os_version, system_info.arch
120+
);
121+
info!(
122+
" {} ({}C / {}GB)",
123+
system_info.cpu_brand, system_info.cpu_cores, system_info.total_memory_gb
124+
);
125+
126+
Ok(())
127+
}

0 commit comments

Comments
 (0)