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} ;
25use crate :: prelude:: * ;
36use crate :: system:: SystemInfo ;
7+ use clap:: { Args , Subcommand } ;
8+ use console:: style;
49use 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