upgrade to edition 2021, clippy fixes, error fixed

This commit is contained in:
crapStone 2021-10-23 22:57:56 +02:00
parent 6def9f298c
commit b540284764
No known key found for this signature in database
GPG key ID: 0E1380C01B1D51B8
5 changed files with 18 additions and 15 deletions

6
Cargo.lock generated
View file

@ -60,7 +60,7 @@ dependencies = [
[[package]] [[package]]
name = "lamp" name = "lamp"
version = "0.1.0" version = "0.2.0"
dependencies = [ dependencies = [
"clap", "clap",
"exitcode", "exitcode",
@ -68,9 +68,9 @@ dependencies = [
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.103" version = "0.2.105"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6" checksum = "869d572136620d55835903746bcb5cdc54cb2851fd0aeec53220b4bb65ef3013"
[[package]] [[package]]
name = "strsim" name = "strsim"

View file

@ -1,8 +1,8 @@
[package] [package]
name = "lamp" name = "lamp"
version = "0.1.0" version = "0.2.0"
authors = ["crapStone <wewr.mc@gmail.com>"] authors = ["crapStone <crapstone01@gmail.com>"]
edition = "2018" edition = "2021"
build = "build.rs" build = "build.rs"

View file

@ -5,6 +5,7 @@ pub fn build_cli() -> App<'static, 'static> {
.version(env!("CARGO_PKG_VERSION")) .version(env!("CARGO_PKG_VERSION"))
.author("crapStone <crapstone01@gmail.com>") .author("crapStone <crapstone01@gmail.com>")
.about("Utility to interact with backlight") .about("Utility to interact with backlight")
.global_setting(clap::AppSettings::ArgRequiredElseHelp)
.arg( .arg(
Arg::with_name("set") Arg::with_name("set")
.short("s") .short("s")
@ -47,7 +48,10 @@ pub fn build_cli() -> App<'static, 'static> {
.long("full") .long("full")
.help("Sets brightness to highest value"), .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(
Arg::with_name("list") Arg::with_name("list")
.short("l") .short("l")

View file

@ -4,8 +4,6 @@ use std::io::prelude::*;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process::exit; use std::process::exit;
use exitcode;
const SYS_PATHS: [&str; 2] = ["/sys/class/backlight", "/sys/class/leds"]; const SYS_PATHS: [&str; 2] = ["/sys/class/backlight", "/sys/class/leds"];
pub trait Controller { pub trait Controller {
@ -34,7 +32,7 @@ pub struct RawController {
impl RawController { impl RawController {
pub fn new(path: Box<PathBuf>) -> Self { pub fn new(path: Box<PathBuf>) -> Self {
Self { path: path } Self { path }
} }
} }
@ -185,7 +183,7 @@ pub fn get_controllers() -> (String, HashMap<String, Box<PathBuf>>) {
let mut default = None; let mut default = None;
for path in SYS_PATHS.iter() { for path in SYS_PATHS {
if Path::new(path).exists() { if Path::new(path).exists() {
for name in Path::new(path).read_dir().unwrap() { for name in Path::new(path).read_dir().unwrap() {
let name = name.unwrap().path(); let name = name.unwrap().path();

View file

@ -3,12 +3,13 @@ mod controllers;
use std::process::exit; use std::process::exit;
use exitcode;
use controllers::{Controller, LinController, LogController, RawController}; use controllers::{Controller, LinController, LogController, RawController};
use crate::cli::build_cli;
fn main() { fn main() {
let matches = cli::parse_args(); let app = build_cli();
let matches = app.get_matches();
let (default_ctrl, ctrls) = controllers::get_controllers(); let (default_ctrl, ctrls) = controllers::get_controllers();
@ -41,7 +42,7 @@ fn main() {
} else if matches.is_present("ful") { } else if matches.is_present("ful") {
controller.set_brightness(controller.get_max_brightness()); controller.set_brightness(controller.get_max_brightness());
} else { } else {
panic!("{}", ERROR_MSG); build_cli().print_long_help().unwrap();
} }
exit(exitcode::OK); exit(exitcode::OK);