Use proper exit codes when something fails

This commit is contained in:
Daan Boerlage 2022-04-09 23:13:21 +02:00
parent 903582291c
commit 35111a0d80
Signed by: daan
GPG key ID: FCE070E1E4956606
2 changed files with 17 additions and 7 deletions

View file

@ -14,9 +14,11 @@ pub enum Commands {
/// List all lights /// List all lights
List, List,
/// Inspect a light /// Inspect a light
Inspect, Inspect { id: String },
/// Toggle a light /// Toggle a light
Toggle { id: String, state: Option<String> }, Toggle { id: String, state: Option<String> },
/// Get a token
Auth,
} }
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]

View file

@ -5,23 +5,31 @@ mod config;
use crate::args::ToggleState; use crate::args::ToggleState;
use clap::Parser; use clap::Parser;
use eyre::Result; use eyre::{eyre, Result};
#[tokio::main] #[tokio::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
let args = args::Args::parse(); let args = args::Args::parse();
let config = config::resolve().await?; let config = config::resolve().await?;
match &args.command { let res = match &args.command {
args::Commands::Toggle { id, state } => { args::Commands::Toggle { id, state } => {
commands::toggle::exec(config, id, state).await?; commands::toggle::exec(config, id, state).await
} }
args::Commands::List => { args::Commands::List => {
commands::list::exec(config).await?; commands::list::exec(config).await
} }
args::Commands::Inspect => { args::Commands::Inspect { id } => {
panic!("Not implemented"); commands::inspect::exec(config, id).await
} }
args::Commands::Auth => {
Err(eyre!("Not yet implemented"))
}
};
if let Err(e) = res {
println!("⛔️ {}", e.to_string());
std::process::exit(1);
} }
Ok(()) Ok(())