mod api; mod config; #[cfg(feature = "gui")] mod gui; mod token_store; use api::ApiClient; use config::{AppConfig, Command}; use std::env; use std::process::ExitCode; use token_store::keyring_identity; fn main() -> ExitCode { let args: Vec = env::args().collect(); match run(&args) { Ok(()) => ExitCode::SUCCESS, Err(err) => { eprintln!("erreur: {err}"); ExitCode::FAILURE } } } fn run(args: &[String]) -> Result<(), String> { let (config, command) = AppConfig::from_args(args)?; match command { Command::Capabilities => { let client = ApiClient::new(&config.server_url, config.token)?; let body = client.get_capabilities()?; println!("{body}"); } Command::Status => { let client = ApiClient::new(&config.server_url, config.token)?; let body = client.get_system_status()?; println!("{body}"); } Command::Metrics => { let client = ApiClient::new(&config.server_url, config.token)?; let body = client.get_system_metrics()?; println!("{body}"); } Command::Machines => { let client = ApiClient::new(&config.server_url, config.token)?; let body = client.get_machines()?; println!("{body}"); } Command::Gui => run_gui(config)?, Command::Help => print_help(), } Ok(()) } #[cfg(feature = "gui")] fn run_gui(config: AppConfig) -> Result<(), String> { gui::run(config); Ok(()) } #[cfg(not(feature = "gui"))] fn run_gui(_config: AppConfig) -> Result<(), String> { Err( "l'interface graphique n'est pas compilée. Lance: cargo run --features gui -- gui" .to_string(), ) } fn print_help() { let (keyring_service, keyring_account) = keyring_identity(); println!( "system-update-gnome\n\ \n\ Usage:\n\ system-update-gnome --server http://127.0.0.1:8787 capabilities\n\ system-update-gnome --server http://127.0.0.1:8787 status\n\ system-update-gnome --server http://127.0.0.1:8787 metrics\n\ system-update-gnome --server http://127.0.0.1:8787 machines\n\ system-update-gnome --server http://127.0.0.1:8787 gui\n\ \n\ Variables:\n\ SYSTEM_UPDATE_SERVER URL du backend, défaut http://127.0.0.1:8787\n\ SYSTEM_UPDATE_TOKEN Token API optionnel\n\ \n\ Futur trousseau:\n\ service: {keyring_service}\n\ compte: {keyring_account}\n" ); }