mirror of
https://github.com/k0kubun/xremap
synced 2024-11-02 03:40:25 +00:00
Shorten main function
This commit is contained in:
parent
ae7d2deff4
commit
d76ab68d7c
@ -62,7 +62,10 @@ impl<'de> Deserialize<'de> for Action {
|
||||
None => return serde_error::<Self::Value, M>("missing action"),
|
||||
};
|
||||
if let Some(key) = map.next_key::<String>()? {
|
||||
return serde_error::<Self::Value, M>(&format!("only one action key is expected but also got: {}", key));
|
||||
return serde_error::<Self::Value, M>(&format!(
|
||||
"only one action key is expected but also got: {}",
|
||||
key
|
||||
));
|
||||
}
|
||||
Ok(action)
|
||||
}
|
||||
|
27
src/main.rs
27
src/main.rs
@ -2,13 +2,14 @@ use evdev::EventType;
|
||||
use std::env;
|
||||
use std::error::Error;
|
||||
use std::process::exit;
|
||||
use crate::config::Config;
|
||||
|
||||
mod config;
|
||||
mod input;
|
||||
mod output;
|
||||
mod transform;
|
||||
|
||||
fn event_loop() -> Result<(), Box<dyn Error>> {
|
||||
fn event_loop(_config: &Config) -> Result<(), Box<dyn Error>> {
|
||||
let mut input_device =
|
||||
input::select_device().map_err(|e| format!("Failed to open an input device: {}", e))?;
|
||||
let mut output_device = output::build_device(&input_device)
|
||||
@ -32,28 +33,22 @@ fn event_loop() -> Result<(), Box<dyn Error>> {
|
||||
}
|
||||
}
|
||||
|
||||
fn abort(message: &str) -> ! {
|
||||
println!("{}", message);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let filename = match env::args().nth(1) {
|
||||
Some(filename) => filename,
|
||||
None => {
|
||||
println!("Usage: xremap <file>");
|
||||
exit(1);
|
||||
}
|
||||
None => abort("Usage: xremap <file>"),
|
||||
};
|
||||
let config = match config::load_config(&filename) {
|
||||
Ok(config) => config,
|
||||
Err(e) => {
|
||||
println!("Failed to load config '{}': {}", filename, e);
|
||||
exit(1);
|
||||
}
|
||||
Err(e) => abort(&format!("Failed to load config '{}': {}", filename, e)),
|
||||
};
|
||||
println!("{:#?}", config);
|
||||
|
||||
match event_loop() {
|
||||
Ok(()) => {}
|
||||
Err(e) => {
|
||||
println!("Error: {}", e);
|
||||
exit(1);
|
||||
}
|
||||
if let Err(e) = event_loop(&config) {
|
||||
abort(&format!("Error: {}", e));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user