mirror of
https://github.com/orhun/systeroid
synced 2024-07-21 10:25:00 +00:00
feat(sysctl): add -a
flag for printing the parameters
This commit is contained in:
parent
da927e010f
commit
da334a9732
|
@ -2,6 +2,7 @@ use crate::error::Result;
|
|||
use crate::parsers::parse_kernel_docs;
|
||||
use rayon::prelude::*;
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
use std::result::Result as StdResult;
|
||||
use sysctl::{CtlFlags, CtlIter, Sysctl as SysctlImpl};
|
||||
|
@ -143,4 +144,12 @@ impl Sysctl {
|
|||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Prints the available kernel parameters to the given output.
|
||||
pub fn print_all<W: Write>(&self, output: &mut W) -> Result<()> {
|
||||
for parameter in &self.parameters {
|
||||
writeln!(output, "{} = {}", parameter.name, parameter.value)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ impl Args {
|
|||
.map_err(|e| eprintln!("error: {}", e))
|
||||
.ok()?;
|
||||
|
||||
if matches.opt_present("h") {
|
||||
if matches.opt_present("h") || !matches.opt_present("a") {
|
||||
let usage = opts.usage_with_format(|opts| {
|
||||
HELP_MESSAGE
|
||||
.replace("{bin}", env!("CARGO_PKG_NAME"))
|
||||
|
|
|
@ -6,26 +6,21 @@
|
|||
pub mod args;
|
||||
|
||||
use crate::args::Args;
|
||||
use std::io;
|
||||
use systeroid_core::error::Result;
|
||||
use systeroid_core::sysctl::Sysctl;
|
||||
|
||||
/// Runs `systeroid`.
|
||||
pub fn run(args: Args) -> Result<()> {
|
||||
let mut stdout = io::stdout();
|
||||
let mut sysctl = Sysctl::init()?;
|
||||
|
||||
if let Some(kernel_docs) = args.kernel_docs {
|
||||
sysctl.update_docs(&kernel_docs)?;
|
||||
}
|
||||
|
||||
for param in sysctl.parameters {
|
||||
println!(
|
||||
"{}\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n{}\n(from: {:?})\n",
|
||||
param.name,
|
||||
param
|
||||
.description
|
||||
.unwrap_or_else(|| String::from("no documentation")),
|
||||
param.document.map(|d| d.path).unwrap_or_default(),
|
||||
);
|
||||
if args.all {
|
||||
sysctl.print_all(&mut stdout)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in a new issue