diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/cocoa_bridge.rs | 10 | ||||
| -rw-r--r-- | src/config.rs | 13 | ||||
| -rw-r--r-- | src/lib.rs | 1 |
3 files changed, 19 insertions, 5 deletions
diff --git a/src/cocoa_bridge.rs b/src/cocoa_bridge.rs index 37654ea..ba7b432 100644 --- a/src/cocoa_bridge.rs +++ b/src/cocoa_bridge.rs @@ -302,6 +302,7 @@ fn run_action(map_action: &MapAction) { pub extern "C" fn c_parse_args( args: *const *const c_char, length: size_t, + config_ptr: *mut Config ) -> *mut Config { let args = unsafe { assert!(!args.is_null()); @@ -320,9 +321,14 @@ pub extern "C" fn c_parse_args( .collect::<Vec<String>>() }; - let config = config::parse_args(&args); + let config = unsafe { + assert!(!config_ptr.is_null()); - Box::into_raw(Box::new(config)) + &mut *config_ptr + }; + let config = config::parse_args(&args, config); + + config_ptr } #[no_mangle] diff --git a/src/config.rs b/src/config.rs index 22f37b6..9962ba0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,4 +1,5 @@ use getopts::Options; +use toml; type Milliseconds = u16; @@ -11,6 +12,7 @@ struct Args { #[repr(C)] #[derive(Deserialize)] +#[serde(default)] pub struct Config { #[serde(skip)] args: Args, @@ -31,7 +33,7 @@ fn print_usage(opts: Options) { print!("{}", opts.usage(&brief)); } -pub fn parse_args(args: &[String]) -> Config { +pub fn parse_args<'a>(args: &[String], config: &'a mut Config) -> &'a mut Config { let mut opts = Options::new(); opts.optflag("d", "daemon", "run the daemon in the current shell"); @@ -43,8 +45,6 @@ pub fn parse_args(args: &[String]) -> Config { Err(e) => panic!(e), }; - let mut config = Config::default(); - if matches.opt_present("h") { print_usage(opts); return config; @@ -60,3 +60,10 @@ pub fn parse_args(args: &[String]) -> Config { config } + +// TODO: Get config file from .config/dome-key/config.toml +pub fn read_config_file() -> Config { + let config = toml::from_str("").unwrap(); + + config +} @@ -19,6 +19,7 @@ extern crate objc; #[macro_use] extern crate serde_derive; extern crate stderrlog; +extern crate toml; extern crate xdg; mod autopilot_internal; |
