mirror of
https://github.com/orhun/systeroid
synced 2024-07-21 10:25:00 +00:00
feat(sysctl): support displaying only the given parameters
This commit is contained in:
parent
9d3910f6b3
commit
e4507feb5c
|
@ -176,8 +176,17 @@ impl Sysctl {
|
|||
}
|
||||
|
||||
/// Prints the available kernel parameters to the given output.
|
||||
pub fn print_all<W: Write>(&self, output: &mut W, colored: bool) -> Result<()> {
|
||||
for parameter in &self.parameters {
|
||||
pub fn display<W: Write>(
|
||||
&self,
|
||||
output: &mut W,
|
||||
names: Vec<String>,
|
||||
colored: bool,
|
||||
) -> Result<()> {
|
||||
for parameter in self
|
||||
.parameters
|
||||
.iter()
|
||||
.filter(|param| names.is_empty() || names.iter().any(|name| param.name == *name))
|
||||
{
|
||||
if colored {
|
||||
writeln!(
|
||||
output,
|
||||
|
|
|
@ -21,6 +21,8 @@ pub struct Args {
|
|||
pub display_all: bool,
|
||||
/// Disable colored output.
|
||||
pub no_color: bool,
|
||||
/// Parameter names.
|
||||
pub param_names: Vec<String>,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
|
@ -45,8 +47,10 @@ impl Args {
|
|||
.map_err(|e| eprintln!("error: {}", e))
|
||||
.ok()?;
|
||||
|
||||
let display_all =
|
||||
matches.opt_present("a") || matches.opt_present("A") || matches.opt_present("X");
|
||||
let display_all = matches.opt_present("a")
|
||||
|| matches.opt_present("A")
|
||||
|| matches.opt_present("X")
|
||||
|| !matches.free.is_empty();
|
||||
|
||||
if matches.opt_present("h") || !display_all {
|
||||
let usage = opts.usage_with_format(|opts| {
|
||||
|
@ -64,6 +68,7 @@ impl Args {
|
|||
kernel_docs: matches.opt_str("d").map(PathBuf::from),
|
||||
display_all,
|
||||
no_color: matches.opt_present("no-color"),
|
||||
param_names: matches.free,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ pub fn run(args: Args) -> Result<()> {
|
|||
}
|
||||
|
||||
if args.display_all {
|
||||
sysctl.print_all(&mut stdout, !args.no_color)?;
|
||||
sysctl.display(&mut stdout, args.param_names, !args.no_color)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in a new issue