summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs47
1 files changed, 26 insertions, 21 deletions
diff --git a/src/main.rs b/src/main.rs
index e71ff25..c5caadb 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -15,37 +15,42 @@ mod remapper;
about = "Remap libinput evdev keyboard inputs",
author = "Wez Furlong"
)]
-struct Opt {
+enum Opt {
/// Rather than running the remapper, list currently available devices.
/// This is helpful to check their names when setting up the initial
/// configuration
- #[structopt(name = "list-devices", long)]
- list_devices: bool,
-
- /// Specify the configuration file to be loaded
- #[structopt(name = "config-file", long)]
- config_file: PathBuf,
+ ListDevices,
+
+ /// Load a remapper config and run the remapper.
+ /// This usually requires running as root to obtain exclusive access
+ /// to the input devices.
+ Remap {
+ /// Specify the configuration file to be loaded
+ #[structopt(name = "CONFIG-FILE")]
+ config_file: PathBuf,
+ },
}
fn main() -> Result<()> {
pretty_env_logger::init();
let opt = Opt::from_args();
- if opt.list_devices {
- return deviceinfo::list_devices();
- }
-
- let mapping_config = MappingConfig::from_file(&opt.config_file).context(format!(
- "loading --config-file={}",
- opt.config_file.display()
- ))?;
+ match opt {
+ Opt::ListDevices => return deviceinfo::list_devices(),
+ Opt::Remap { config_file } => {
+ let mapping_config = MappingConfig::from_file(&config_file).context(format!(
+ "loading MappingConfig from {}",
+ config_file.display()
+ ))?;
- log::error!("Short delay: release any keys now!");
- std::thread::sleep(Duration::new(2, 0));
+ log::error!("Short delay: release any keys now!");
+ std::thread::sleep(Duration::new(2, 0));
- let device_info = deviceinfo::DeviceInfo::with_name(&mapping_config.device_name)?;
+ let device_info = deviceinfo::DeviceInfo::with_name(&mapping_config.device_name)?;
- let mut mapper = InputMapper::create_mapper(device_info.path, mapping_config.mappings)?;
- mapper.run_mapper()?;
- Ok(())
+ let mut mapper = InputMapper::create_mapper(device_info.path, mapping_config.mappings)?;
+ mapper.run_mapper()?;
+ Ok(())
+ }
+ }
}