diff options
-rw-r--r-- | src/vtcol.rs | 235 |
1 files changed, 135 insertions, 100 deletions
diff --git a/src/vtcol.rs b/src/vtcol.rs index 89cc162..b24937b 100644 --- a/src/vtcol.rs +++ b/src/vtcol.rs @@ -458,75 +458,92 @@ impl<'a> Job ), ) .subcommand( - SubCommand::with_name("leds") - .about("operations regarding keyboard LEDs") + SubCommand::with_name("kb") + .about("keyboard controls") .subcommand( - SubCommand::with_name("get") - .about("get LED state") - .arg( - Arg::with_name("u8") - .short("8") - .long("u8") - .help("output raw state as integer") - .takes_value(false), - ), - ) - .subcommand( - SubCommand::with_name("set") - .about("set LED state") - .arg( - Arg::with_name("u8") - .short("8") - .long("u8") - .help("provide desired state as integer") - .takes_value(true) - .required_unless_one(&[ - "revert", "caps", "num", "scroll", - ]) - .conflicts_with_all(&[ - "revert", "caps", "num", "scroll", - ]) - .value_name("STATE"), + SubCommand::with_name("leds") + .about("operations regarding keyboard LEDs") + .subcommand( + SubCommand::with_name("get") + .about("get LED state") + .arg( + Arg::with_name("u8") + .short("8") + .long("u8") + .help("output raw state as integer") + .takes_value(false), + ), ) - .arg( - Arg::with_name("caps") - .short("c") - .long("caps") - .help("[de]activate Caps Lock LED") - .takes_value(true) - .possible_values(&["on", "off"]) - .conflicts_with_all(&["revert", "u8"]) - .value_name("STATE"), - ) - .arg( - Arg::with_name("num") - .short("n") - .long("num") - .help("[de]activate Num Lock LED") - .takes_value(true) - .possible_values(&["on", "off"]) - .conflicts_with_all(&["revert", "u8"]) - .value_name("STATE"), - ) - .arg( - Arg::with_name("scroll") - .short("s") - .long("scroll") - .help("[de]activate Scroll Lock LED") - .takes_value(true) - .possible_values(&["on", "off"]) - .conflicts_with_all(&["revert", "u8"]) - .value_name("STATE"), - ) - .arg( - Arg::with_name("revert") - .short("r") - .long("revert") - .help("revert LED state to normal") - .takes_value(false) - .conflicts_with_all(&[ - "u8", "caps", "num", "scroll", - ]), + .subcommand( + SubCommand::with_name("set") + .about("set LED state") + .arg( + Arg::with_name("u8") + .short("8") + .long("u8") + .help( + "provide desired state as \ + integer", + ) + .takes_value(true) + .required_unless_one(&[ + "revert", "caps", "num", + "scroll", + ]) + .conflicts_with_all(&[ + "revert", "caps", "num", + "scroll", + ]) + .value_name("STATE"), + ) + .arg( + Arg::with_name("caps") + .short("c") + .long("caps") + .help("[de]activate Caps Lock LED") + .takes_value(true) + .possible_values(&["on", "off"]) + .conflicts_with_all(&[ + "revert", "u8", + ]) + .value_name("STATE"), + ) + .arg( + Arg::with_name("num") + .short("n") + .long("num") + .help("[de]activate Num Lock LED") + .takes_value(true) + .possible_values(&["on", "off"]) + .conflicts_with_all(&[ + "revert", "u8", + ]) + .value_name("STATE"), + ) + .arg( + Arg::with_name("scroll") + .short("s") + .long("scroll") + .help( + "[de]activate Scroll Lock LED", + ) + .takes_value(true) + .possible_values(&["on", "off"]) + .conflicts_with_all(&[ + "revert", "u8", + ]) + .value_name("STATE"), + ) + .arg( + Arg::with_name("revert") + .short("r") + .long("revert") + .help("revert LED state to normal") + .takes_value(false) + .conflicts_with_all(&[ + "u8", "caps", "num", "scroll", + ]), + ), ), ), ); @@ -658,45 +675,63 @@ impl<'a> Job )), }, - ("leds", Some(subm)) => + ("kb", Some(subm)) => match subm.subcommand() { - ("get", Some(subm)) => { - let raw = subm.is_present("u8"); - Ok(Self(con, Subcmd::Leds(LedJob::Get(raw)))) - }, - ("set", Some(subm)) => { - if subm.is_present("revert") { - return Ok(Self(con, Subcmd::Leds(LedJob::Revert))); - } - if let Some(st) = subm.value_of("u8") { - let st: u8 = st.parse()?; - let st = KbLedState::try_from(st)?; - return Ok(Self( - con, - Subcmd::Leds(LedJob::Set(st)), - )); - } - let cap = subm.value_of("caps").map(|a| a == "on"); - let num = subm.value_of("num").map(|a| a == "on"); - let scr = subm.value_of("scroll").map(|a| a == "on"); - Ok(Self( - con, - Subcmd::Leds(LedJob::SetIndividual(cap, num, scr)), - )) - }, - (junk, _) => + ("leds", Some(subm)) => + match subm.subcommand() { + ("get", Some(subm)) => { + let raw = subm.is_present("u8"); + Ok(Self(con, Subcmd::Leds(LedJob::Get(raw)))) + }, + ("set", Some(subm)) => { + if subm.is_present("revert") { + return Ok(Self( + con, + Subcmd::Leds(LedJob::Revert), + )); + } + if let Some(st) = subm.value_of("u8") { + let st: u8 = st.parse()?; + let st = KbLedState::try_from(st)?; + return Ok(Self( + con, + Subcmd::Leds(LedJob::Set(st)), + )); + } + let cap = + subm.value_of("caps").map(|a| a == "on"); + let num = + subm.value_of("num").map(|a| a == "on"); + let scr = + subm.value_of("scroll").map(|a| a == "on"); + Ok(Self( + con, + Subcmd::Leds(LedJob::SetIndividual( + cap, num, scr, + )), + )) + }, + (junk, _) => + Err(anyhow!( + "invalid sub-subcommand to leds: [{}]; \ + try ``{} leds --help``", + junk, + clap::crate_name!() + )), + }, + + (leds_junk, _) => Err(anyhow!( - "invalid sub-subcommand to leds: [{}]; try ``{} \ - leds --help``", - junk, + "invalid subcommand to kb leds [{}]; try ``{} \ + --help``", + leds_junk, clap::crate_name!() )), }, - - (junk, _) => + (kb_junk, _) => Err(anyhow!( - "invalid subcommand [{}]; try ``{} --help``", - junk, + "invalid subcommand to kb [{}]; try ``{} --help``", + kb_junk, clap::crate_name!() )), } |