From 35111a0d808b89877808ca2d3b9fd93dc72d4ec7 Mon Sep 17 00:00:00 2001 From: Daan Boerlage Date: Sat, 9 Apr 2022 23:13:21 +0200 Subject: [PATCH] Use proper exit codes when something fails --- src/args.rs | 4 +++- src/main.rs | 20 ++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/args.rs b/src/args.rs index e89311d..180fa30 100644 --- a/src/args.rs +++ b/src/args.rs @@ -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 }, + /// Get a token + Auth, } #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] diff --git a/src/main.rs b/src/main.rs index cad87b3..4e793b9 100644 --- a/src/main.rs +++ b/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(())