diff options
| -rw-r--r-- | src/config.rs | 49 | ||||
| -rw-r--r-- | src/lib.rs | 3 |
2 files changed, 52 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..66769a9 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,49 @@ +use getopts::Options; + +#[no_mangle] +#[derive(Default)] +struct Args { + reload: bool, + daemon: bool, +} + +#[no_mangle] +#[derive(Default)] +pub struct Config { + args: Args, +} + +fn print_usage(opts: Options) { + let brief = "Usage: dome-key [options]"; + print!("{}", opts.usage(&brief)); +} + +pub fn parse_args(args: &[String]) -> Config { + let mut opts = Options::new(); + + opts.optflag("d", "daemon", "run the daemon in the current shell"); + opts.optflag("r", "reload-mappings", "reload the mappings file"); + opts.optflag("h", "help", "print this help menu"); + + let matches = match opts.parse(args) { + Ok(m) => m, + Err(e) => panic!(e), + }; + + let mut config = Config::default(); + + if matches.opt_present("h") { + print_usage(opts); + return config; + } + + if matches.opt_present("r") { + config.args.reload = true; + } else if matches.opt_present("d") { + config.args.daemon = true; + } else { + print_usage(opts); + } + + config +} @@ -5,6 +5,7 @@ extern crate autopilot; #[macro_use] extern crate combine; +extern crate getopts; extern crate libc; #[macro_use] @@ -13,8 +14,10 @@ extern crate stderrlog; extern crate xdg; mod cocoa_bridge; +mod config; mod parser; use parser::{Action, HeadphoneButton, MapAction, MapGroup, MapKind}; pub use cocoa_bridge::*; +pub use config::{Config, parse_args}; |
