From b5402847642ae1e970b8cfdf92f7ef19437e67e9 Mon Sep 17 00:00:00 2001 From: crapStone Date: Sat, 23 Oct 2021 22:57:56 +0200 Subject: [PATCH] upgrade to edition 2021, clippy fixes, error fixed --- Cargo.lock | 6 +++--- Cargo.toml | 6 +++--- src/cli.rs | 6 +++++- src/controllers.rs | 6 ++---- src/main.rs | 9 +++++---- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4b11455..6c0fe92 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -60,7 +60,7 @@ dependencies = [ [[package]] name = "lamp" -version = "0.1.0" +version = "0.2.0" dependencies = [ "clap", "exitcode", @@ -68,9 +68,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.103" +version = "0.2.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6" +checksum = "869d572136620d55835903746bcb5cdc54cb2851fd0aeec53220b4bb65ef3013" [[package]] name = "strsim" diff --git a/Cargo.toml b/Cargo.toml index 033bf70..503b0ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "lamp" -version = "0.1.0" -authors = ["crapStone "] -edition = "2018" +version = "0.2.0" +authors = ["crapStone "] +edition = "2021" build = "build.rs" diff --git a/src/cli.rs b/src/cli.rs index 44e3c0f..a64ceca 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -5,6 +5,7 @@ pub fn build_cli() -> App<'static, 'static> { .version(env!("CARGO_PKG_VERSION")) .author("crapStone ") .about("Utility to interact with backlight") + .global_setting(clap::AppSettings::ArgRequiredElseHelp) .arg( Arg::with_name("set") .short("s") @@ -47,7 +48,10 @@ pub fn build_cli() -> App<'static, 'static> { .long("full") .help("Sets brightness to highest value"), ) - .group(ArgGroup::with_name("brightness_control").args(&["set", "inc", "dec", "get", "zer", "ful"])) + .group( + ArgGroup::with_name("brightness_control") + .args(&["set", "inc", "dec", "get", "zer", "ful"]), + ) .arg( Arg::with_name("list") .short("l") diff --git a/src/controllers.rs b/src/controllers.rs index 79e8342..8626c21 100644 --- a/src/controllers.rs +++ b/src/controllers.rs @@ -4,8 +4,6 @@ use std::io::prelude::*; use std::path::{Path, PathBuf}; use std::process::exit; -use exitcode; - const SYS_PATHS: [&str; 2] = ["/sys/class/backlight", "/sys/class/leds"]; pub trait Controller { @@ -34,7 +32,7 @@ pub struct RawController { impl RawController { pub fn new(path: Box) -> Self { - Self { path: path } + Self { path } } } @@ -185,7 +183,7 @@ pub fn get_controllers() -> (String, HashMap>) { let mut default = None; - for path in SYS_PATHS.iter() { + for path in SYS_PATHS { if Path::new(path).exists() { for name in Path::new(path).read_dir().unwrap() { let name = name.unwrap().path(); diff --git a/src/main.rs b/src/main.rs index 929e190..8059fbc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,12 +3,13 @@ mod controllers; use std::process::exit; -use exitcode; - use controllers::{Controller, LinController, LogController, RawController}; +use crate::cli::build_cli; + fn main() { - let matches = cli::parse_args(); + let app = build_cli(); + let matches = app.get_matches(); let (default_ctrl, ctrls) = controllers::get_controllers(); @@ -41,7 +42,7 @@ fn main() { } else if matches.is_present("ful") { controller.set_brightness(controller.get_max_brightness()); } else { - panic!("{}", ERROR_MSG); + build_cli().print_long_help().unwrap(); } exit(exitcode::OK);