mirror of
https://github.com/orhun/systeroid
synced 2024-10-15 11:52:19 +00:00
feat(args): add aliases for the display flag
This commit is contained in:
parent
783320c276
commit
9d3910f6b3
|
@ -18,7 +18,7 @@ pub struct Args {
|
||||||
/// Path of the Linux kernel documentation.
|
/// Path of the Linux kernel documentation.
|
||||||
pub kernel_docs: Option<PathBuf>,
|
pub kernel_docs: Option<PathBuf>,
|
||||||
/// Display all of the kernel parameters.
|
/// Display all of the kernel parameters.
|
||||||
pub all: bool,
|
pub display_all: bool,
|
||||||
/// Disable colored output.
|
/// Disable colored output.
|
||||||
pub no_color: bool,
|
pub no_color: bool,
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,8 @@ impl Args {
|
||||||
opts.optflag("h", "help", "display this help and exit");
|
opts.optflag("h", "help", "display this help and exit");
|
||||||
opts.optflag("V", "version", "output version information and exit");
|
opts.optflag("V", "version", "output version information and exit");
|
||||||
opts.optflag("a", "all", "display all variables");
|
opts.optflag("a", "all", "display all variables");
|
||||||
|
opts.optflag("A", "", "alias of -a");
|
||||||
|
opts.optflag("X", "", "alias of -a");
|
||||||
opts.optflag("", "no-color", "disable colored output");
|
opts.optflag("", "no-color", "disable colored output");
|
||||||
opts.optopt(
|
opts.optopt(
|
||||||
"d",
|
"d",
|
||||||
|
@ -43,7 +45,10 @@ impl Args {
|
||||||
.map_err(|e| eprintln!("error: {}", e))
|
.map_err(|e| eprintln!("error: {}", e))
|
||||||
.ok()?;
|
.ok()?;
|
||||||
|
|
||||||
if matches.opt_present("h") || !matches.opt_present("a") {
|
let display_all =
|
||||||
|
matches.opt_present("a") || matches.opt_present("A") || matches.opt_present("X");
|
||||||
|
|
||||||
|
if matches.opt_present("h") || !display_all {
|
||||||
let usage = opts.usage_with_format(|opts| {
|
let usage = opts.usage_with_format(|opts| {
|
||||||
HELP_MESSAGE
|
HELP_MESSAGE
|
||||||
.replace("{bin}", env!("CARGO_PKG_NAME"))
|
.replace("{bin}", env!("CARGO_PKG_NAME"))
|
||||||
|
@ -57,7 +62,7 @@ impl Args {
|
||||||
} else {
|
} else {
|
||||||
Some(Args {
|
Some(Args {
|
||||||
kernel_docs: matches.opt_str("d").map(PathBuf::from),
|
kernel_docs: matches.opt_str("d").map(PathBuf::from),
|
||||||
all: matches.opt_present("a"),
|
display_all,
|
||||||
no_color: matches.opt_present("no-color"),
|
no_color: matches.opt_present("no-color"),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ pub fn run(args: Args) -> Result<()> {
|
||||||
sysctl.update_docs(&kernel_docs)?;
|
sysctl.update_docs(&kernel_docs)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.all {
|
if args.display_all {
|
||||||
sysctl.print_all(&mut stdout, !args.no_color)?;
|
sysctl.print_all(&mut stdout, !args.no_color)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue