Skip to content

Commit 38c1c7b

Browse files
committed
chore: Somewhat cleaner code style in argument handling
Useful for adding more arguments.
1 parent 86327b3 commit 38c1c7b

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/configurator_app.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,20 @@ impl ObjectImpl for ConfiguratorAppInner {
5555

5656
impl ApplicationImpl for ConfiguratorAppInner {
5757
fn handle_local_options(&self, _app: &ConfiguratorApp, opts: &glib::VariantDict) -> i32 {
58-
let board_names = if let Some(opt) = opts.lookup_value("fake-keyboard", None) {
59-
let value: String = opt.get().unwrap();
58+
fn lookup<T: glib::FromVariant>(opts: &glib::VariantDict, key: &str) -> Option<T> {
59+
opts.lookup_value(key, None)?.get()
60+
}
6061

61-
if &value == "all" {
62-
backend::layouts().iter().map(|s| s.to_string()).collect()
63-
} else {
64-
value.split(',').map(str::to_string).collect()
65-
}
66-
} else {
67-
vec![]
62+
let board_names = match lookup::<String>(opts, "fake-keyboard").as_deref() {
63+
Some("all") => backend::layouts().iter().map(|s| s.to_string()).collect(),
64+
Some(value) => value.split(',').map(str::to_string).collect(),
65+
None => vec![],
6866
};
6967

7068
self.phony_board_names.set(board_names);
7169
self.debug_layers.set(opts.contains("debug-layers"));
7270
self.launch_test.set(opts.contains("launch-test"));
71+
7372
-1
7473
}
7574

0 commit comments

Comments
 (0)