diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 38 | ||||
-rw-r--r-- | src/mapping.rs | 6 |
2 files changed, 36 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs index 1018aca..5828a37 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,6 +32,14 @@ enum Opt { /// Number of seconds for user to release keys on startup #[arg(short, long, default_value = "2")] delay: f64, + + /// Override the device name specified by the config file + #[arg(long)] + device_name: Option<String>, + + /// Override the phys device specified by the config file + #[arg(long)] + phys: Option<String>, }, } @@ -67,19 +75,37 @@ fn main() -> Result<()> { match opt { Opt::ListDevices => deviceinfo::list_devices(), Opt::ListKeys => list_keys(), - Opt::Remap { config_file, delay } => { - let mapping_config = MappingConfig::from_file(&config_file).context(format!( + Opt::Remap { + config_file, + delay, + device_name, + phys, + } => { + let mut mapping_config = MappingConfig::from_file(&config_file).context(format!( "loading MappingConfig from {}", config_file.display() ))?; + if let Some(device) = device_name { + mapping_config.device_name = Some(device); + } + if let Some(phys) = phys { + mapping_config.phys = Some(phys); + } + + let device_name = mapping_config.device_name.as_deref().ok_or_else(|| { + anyhow::anyhow!( + "device_name is missing; \ + specify it either in the config file or via the --device-name \ + command line option" + ) + })?; + log::warn!("Short delay: release any keys now!"); std::thread::sleep(Duration::from_secs_f64(delay)); - let device_info = deviceinfo::DeviceInfo::with_name( - &mapping_config.device_name, - mapping_config.phys.as_deref(), - )?; + let device_info = + deviceinfo::DeviceInfo::with_name(device_name, mapping_config.phys.as_deref())?; let mut mapper = InputMapper::create_mapper(device_info.path, mapping_config.mappings)?; mapper.run_mapper() diff --git a/src/mapping.rs b/src/mapping.rs index 6ffc274..0574273 100644 --- a/src/mapping.rs +++ b/src/mapping.rs @@ -7,7 +7,7 @@ use thiserror::Error; #[derive(Debug, Clone)] pub struct MappingConfig { - pub device_name: String, + pub device_name: Option<String>, pub phys: Option<String>, pub mappings: Vec<Mapping>, } @@ -114,7 +114,9 @@ impl Into<Mapping> for RemapConfig { #[derive(Debug, Deserialize)] struct ConfigFile { - device_name: String, + #[serde(default)] + device_name: Option<String>, + #[serde(default)] phys: Option<String>, |