Skip to content

Commit

Permalink
Migrate to clap 3, create error macro, solve clippy lints
Browse files Browse the repository at this point in the history
and more
  • Loading branch information
marcospb19 committed Mar 19, 2022
1 parent fc6302d commit d3a9418
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 141 deletions.
185 changes: 156 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ keywords = ["razer", "mouse", "mice", "deathadder", "hardware"]
[dependencies]
libc = "0.2"
nix = "0.8.1"
clap = { version = "2.33.1", features = ["wrap_help"] }
libudev = { git = "https://github.com/9ary/libudev-rs", rev = "cf7dd72" }
clap = { version = "3.1.6", features = ["atty", "derive", "wrap_help"] }

[profile.release]
opt-level = "s"
75 changes: 29 additions & 46 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,48 +1,31 @@
use clap::*;
use clap::Parser;
use std::ffi::OsString;

pub(crate) fn parse_args() -> clap::ArgMatches<'static> {
App::new(crate_name!())
.version(crate_version!())
.about(crate_description!())
.help_message("Display help information.")
.after_help("Please, contribute and leave issues at https://github.com/marcospb19/dawctl")
.version_message("Display version information.")
.settings(&[AppSettings::ColoredHelp])
.arg(
Arg::with_name("dpi")
.long("--dpi")
.short("-d")
.value_name("DPI")
.help("Sensor DPI, multiples of 100. [200-6400]"),
)
.arg(
Arg::with_name("path")
.long("--path")
.short("-p")
.value_name("PATH")
.help("Path to the hidraw node. (example: /dev/hidraw3)"),
)
.arg(
Arg::with_name("brightness")
.long("--light")
.short("-l")
.value_name("BRIGHTNESS_LEVEL")
.help("Brightness level of the wheel and logo. [0-100]"),
)
.arg(
Arg::with_name("frequency")
.long("--frequency")
.short("-f")
.value_name("FREQUENCY")
.help("Sensor frequency in Hz. [500 or 1000]")
.possible_values(&["500", "1000"])
.hide_possible_values(true),
)
.arg(
Arg::with_name("breath")
.long("--breath")
.short("-b")
.help("Lighting breath effect."),
)
.get_matches()
impl Args {
pub fn argparse() -> Self {
Self::parse()
}
}

#[derive(Parser, Debug)]
pub struct Args {
/// Sensor DPI, multiples of 100. [200-6400].
#[clap(short, long, value_name = "DPI")]
pub dpi: Option<u16>,

/// Brightness level of the wheel and logo. [0-100]
#[clap(short = 'l', long = "--light", value_name = "BRIGHTNESS_LEVEL")]
pub brightness: Option<u16>,

/// Sensor frequency in Hz. [500 or 1000]
#[clap(short, long, value_name = "FREQUENCY", possible_values = &["500", "1000"], hide_possible_values = true)]
pub frequency: Option<u16>,

/// Lighting breath effect.
#[clap(short, long)]
pub breath: bool,

/// Path to the hidraw node. (example: /dev/hidraw3).
#[clap(short, long, value_name = "PATH")]
pub path: Option<OsString>,
}
Loading

0 comments on commit d3a9418

Please sign in to comment.