Add cli options and move structs in separate file

This commit is contained in:
George Kaklamanos 2023-06-30 17:40:12 +03:00
parent 1eef68f859
commit c7dcef1cd1
2 changed files with 45 additions and 24 deletions

39
labadoor/src/cli.rs Normal file
View file

@ -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<String>,
}
#[cfg(feature = "matrix")]
#[derive(Parser, Debug)]
pub struct Matrix {
#[clap(short, long)]
pub username: Option<String>,
#[clap(short, long)]
pub password: Option<String>,
}
pub fn parse() -> Cli {
Cli::parse()
}

View file

@ -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();
}
}