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,
/// Inspect a light
Inspect,
Inspect { id: String },
/// Toggle a light
Toggle { id: String, state: Option<String> },
/// Get a token
Auth,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]

View file

@ -5,23 +5,31 @@ mod config;
use crate::args::ToggleState;
use clap::Parser;
use eyre::Result;
use eyre::{eyre, Result};
#[tokio::main]
async fn main() -> Result<()> {
let args = args::Args::parse();
let config = config::resolve().await?;
match &args.command {
let res = match &args.command {
args::Commands::Toggle { id, state } => {
commands::toggle::exec(config, id, state).await?;
commands::toggle::exec(config, id, state).await
}
args::Commands::List => {
commands::list::exec(config).await?;
commands::list::exec(config).await
}
args::Commands::Inspect => {
panic!("Not implemented");
args::Commands::Inspect { id } => {
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(())