From c7dcef1cd1f9ea67d383ece38979684568e8a330 Mon Sep 17 00:00:00 2001 From: George Kaklamanos Date: Fri, 30 Jun 2023 17:40:12 +0300 Subject: [PATCH] Add cli options and move structs in separate file --- labadoor/src/cli.rs | 39 +++++++++++++++++++++++++++++++++++++++ labadoor/src/main.rs | 30 ++++++------------------------ 2 files changed, 45 insertions(+), 24 deletions(-) create mode 100644 labadoor/src/cli.rs diff --git a/labadoor/src/cli.rs b/labadoor/src/cli.rs new file mode 100644 index 0000000..d654aae --- /dev/null +++ b/labadoor/src/cli.rs @@ -0,0 +1,39 @@ +use clap::Parser; + +#[derive(Parser, Debug)] +pub struct Cli { + #[command(subcommand)] + pub command: Command, +} + +#[derive(Parser, Debug)] +pub enum Command { + #[cfg(feature = "telegram")] + Telegram(Telegram), + #[cfg(feature = "matrix")] + Matrix(Matrix), + #[cfg(feature = "csv")] + CSV, + #[cfg(feature = "gpio")] + GPIO, +} + +#[cfg(feature = "telegram")] +#[derive(Parser, Debug)] +pub struct Telegram { + #[clap(short, long)] + pub token: Option, +} + +#[cfg(feature = "matrix")] +#[derive(Parser, Debug)] +pub struct Matrix { + #[clap(short, long)] + pub username: Option, + #[clap(short, long)] + pub password: Option, +} + +pub fn parse() -> Cli { + Cli::parse() +} diff --git a/labadoor/src/main.rs b/labadoor/src/main.rs index dcb43e0..d4389ee 100644 --- a/labadoor/src/main.rs +++ b/labadoor/src/main.rs @@ -1,40 +1,22 @@ -use clap::Parser; - -#[derive(Parser, Debug)] -struct Cli { - #[command(subcommand)] - command: Command, -} - -#[derive(Parser, Debug)] -enum Command { - #[cfg(feature = "telegram")] - Telegram, - #[cfg(feature = "matrix")] - Matrix, - #[cfg(feature = "csv")] - CSV, - #[cfg(feature = "gpio")] - GPIO, -} +mod cli; fn main() { - let cli = Cli::parse(); + let cli = cli::parse(); match &cli.command { #[cfg(feature = "telegram")] - Command::Telegram => { + cli::Command::Telegram(_) => { labadoor_telegram::main(); } #[cfg(feature = "matrix")] - Command::Matrix => { + cli::Command::Matrix(_) => { labadoor_matrix::main(); } #[cfg(feature = "csv")] - Command::CSV => { + cli::Command::CSV => { labadoor_csv::main(); } #[cfg(feature = "gpio")] - Command::GPIO => { + cli::Command::GPIO => { labadoor_gpio::main(); } }