mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-01-19 00:57:53 +00:00
Add cli option to select device to control (#6)
Co-authored-by: crapStone <crapstone01@gmail.com> Reviewed-on: https://codeberg.org/crapStone/lamp/pulls/6
This commit is contained in:
parent
6f84078759
commit
620ba2bbe8
3 changed files with 31 additions and 9 deletions
|
@ -9,12 +9,13 @@ In contrast to acpilight lamp is not backwards compatible with xbacklight.
|
|||
It is intended to be used as a standalone replacement for new scripts.
|
||||
|
||||
```none
|
||||
-c, --controller <DEVICE> Select device to control
|
||||
-d, --decrease <PERCENT> Decreases brightness
|
||||
-f, --full Sets brightness to highest value
|
||||
-g, --get Prints current brightness value
|
||||
-h, --help Print help information
|
||||
-i, --increase <PERCENT> Increases brightness
|
||||
-l, --list Lists all available brightness and led controllers
|
||||
-l, --list Lists all devices with controllable brightness and led values
|
||||
-s, --set <VALUE> Sets brightness to given value
|
||||
-t, --type <controller_type> choose controller type [default: lin] [possible values: raw,
|
||||
lin, log]
|
||||
|
|
22
src/cli.rs
22
src/cli.rs
|
@ -15,25 +15,25 @@ pub fn build_cli() -> App<'static> {
|
|||
Arg::with_name("set")
|
||||
.short('s')
|
||||
.long("set")
|
||||
.value_name("VALUE")
|
||||
.help("Sets brightness to given value")
|
||||
.takes_value(true),
|
||||
.takes_value(true)
|
||||
.value_name("VALUE"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("inc")
|
||||
.short('i')
|
||||
.long("increase")
|
||||
.value_name("PERCENT")
|
||||
.help("Increases brightness")
|
||||
.takes_value(true),
|
||||
.takes_value(true)
|
||||
.value_name("PERCENT"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("dec")
|
||||
.short('d')
|
||||
.long("decrease")
|
||||
.value_name("PERCENT")
|
||||
.help("Decreases brightness")
|
||||
.takes_value(true),
|
||||
.takes_value(true)
|
||||
.value_name("PERCENT"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("get")
|
||||
|
@ -57,9 +57,17 @@ pub fn build_cli() -> App<'static> {
|
|||
Arg::with_name("list")
|
||||
.short('l')
|
||||
.long("list")
|
||||
.help("Lists all available brightness and led controllers")
|
||||
.help("Lists all devices with controllable brightness and led values")
|
||||
.exclusive(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("controller")
|
||||
.short('c')
|
||||
.long("controller")
|
||||
.help("Select device to control")
|
||||
.value_name("DEVICE")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("ctrl_type")
|
||||
.short('t')
|
||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -18,7 +18,20 @@ fn main() {
|
|||
|
||||
let (default_ctrl, ctrls) = controllers::get_controllers();
|
||||
|
||||
let p = ctrls.get(&default_ctrl).unwrap().to_owned();
|
||||
let p = match matches.value_of("controller") {
|
||||
Some(ctrl) => {
|
||||
let p = ctrls.get(ctrl);
|
||||
if p == None {
|
||||
eprintln!("no device with name '{ctrl}' found");
|
||||
eprintln!("use --list to ge a list of all available devices");
|
||||
exit(exitcode::DATAERR);
|
||||
}
|
||||
|
||||
p.unwrap().to_owned()
|
||||
}
|
||||
None => ctrls.get(&default_ctrl).unwrap().to_owned(),
|
||||
};
|
||||
|
||||
let controller: Box<dyn Controller> = match matches.value_of("ctrl_type") {
|
||||
Some("raw") => Box::new(RawController::new(p)),
|
||||
Some("lin") => Box::new(LinController::new(p)),
|
||||
|
|
Loading…
Reference in a new issue