Use proper exit codes when something fails
This commit is contained in:
parent
903582291c
commit
35111a0d80
2 changed files with 17 additions and 7 deletions
|
@ -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)]
|
||||
|
|
20
src/main.rs
20
src/main.rs
|
@ -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(())
|
||||
|
|
Loading…
Reference in a new issue