Skip to content

Commit

Permalink
fix: update the CLI (#93)
Browse files Browse the repository at this point in the history
Add the check action, to ask the clafrica to only verify the
configuration file.
  • Loading branch information
pythonbrad committed Oct 2, 2023
1 parent 79a741c commit 4a7e139
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 12 deletions.
126 changes: 124 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions clafrica/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ authors = ["Brady Fomegne <fomegnemeudje@outlook.com>"]

[dependencies]
clafrica-lib = { version = "0.3.0", path = "../clafrica-lib" }
clap = { version = "4.4.6", features = ["derive"] }
enigo = "0.1.2"
rdev = "0.5.2"
rhai = "1.15.1"
Expand Down
31 changes: 21 additions & 10 deletions clafrica/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
use clafrica::{api, prelude::Config, run};
use std::{env, path::Path, process};
use clap::Parser;
use std::process;

/// Clafrica CLI
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Args {
/// Path to the configuration file
config_file: std::path::PathBuf,

/// Only verify if the configuration file is valid
#[arg(long, action)]
check: bool,
}

fn main() {
let args = Args::parse();
let frontend = api::Console::default();

let filename = env::args().nth(1).unwrap_or_else(|| {
eprintln!("Configuration file required");
process::exit(1);
});

let conf = Config::from_file(Path::new(&filename)).unwrap_or_else(|err| {
let conf = Config::from_file(&args.config_file).unwrap_or_else(|err| {
eprintln!("Problem parsing config file: {err}");
process::exit(1);
});

if let Err(e) = run(conf, frontend) {
eprintln!("Application error: {e}");
process::exit(1);
if !args.check {
run(conf, frontend).unwrap_or_else(|e| {
eprintln!("Application error: {e}");
process::exit(1);
});
}
}

0 comments on commit 4a7e139

Please sign in to comment.