From 468341393863e35bec170528ab5a99ee26acb85a Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 12 Dec 2021 22:04:37 +0100 Subject: =?UTF-8?q?bin:=20move=20=E2=80=9Cleds=E2=80=9D=20subcommand=20und?= =?UTF-8?q?er=20=E2=80=9Ckb=E2=80=9D=20namespace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit So instead of $ vtcol leds get that functionality is now available as $ vtcol kb leds get anticipating the keyboad related functions that are about to come. --- src/vtcol.rs | 235 ++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 135 insertions(+), 100 deletions(-) (limited to 'src/vtcol.rs') 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!() )), } -- cgit v1.2.3