mirror of
https://github.com/orhun/systeroid
synced 2024-07-21 10:25:00 +00:00
feat(docs): support displaying multiple docs with extensible search
This commit is contained in:
parent
fcc3d32fd6
commit
40ec7ba14d
|
@ -127,7 +127,7 @@ impl Parameter {
|
|||
/// Prints the description of the kernel parameter to the given output.
|
||||
pub fn display_documentation<W: Write>(&self, output: &mut W) -> Result<()> {
|
||||
if let Some(documentation) = self.get_documentation() {
|
||||
writeln!(output, "{}", documentation)?;
|
||||
writeln!(output, "{}\n", documentation)?;
|
||||
} else {
|
||||
writeln!(output, "No documentation available")?;
|
||||
}
|
||||
|
|
|
@ -78,11 +78,11 @@ impl<'a> App<'a> {
|
|||
/// Displays the documentation of a parameter.
|
||||
pub fn display_documentation(&mut self, param_name: &str) -> Result<()> {
|
||||
let no_pager = self.sysctl.config.no_pager;
|
||||
if let Some(parameter) = self.sysctl.get_parameter(param_name) {
|
||||
for parameter in self.sysctl.get_parameters(param_name) {
|
||||
let mut fallback_to_default = false;
|
||||
if no_pager {
|
||||
parameter.display_documentation(&mut self.stdout)?;
|
||||
return Ok(());
|
||||
continue;
|
||||
}
|
||||
let pager = env::var("PAGER").unwrap_or_else(|_| String::from("less"));
|
||||
match Command::new(&pager).stdin(Stdio::piped()).spawn() {
|
||||
|
|
|
@ -34,8 +34,8 @@ pub struct Args {
|
|||
pub preload_files: bool,
|
||||
/// Pattern for matching the parameters.
|
||||
pub pattern: Option<Regex>,
|
||||
/// Parameter to explain.
|
||||
pub param_to_explain: Option<String>,
|
||||
/// Whether if the documentation should be shown.
|
||||
pub explain_params: bool,
|
||||
/// Free string fragments.
|
||||
pub values: Vec<String>,
|
||||
}
|
||||
|
@ -61,11 +61,10 @@ impl Args {
|
|||
);
|
||||
opts.optflag("q", "quiet", "do not echo variable set");
|
||||
opts.optflag("d", "", "alias of -h");
|
||||
opts.optopt(
|
||||
opts.optflag(
|
||||
"E",
|
||||
"explain",
|
||||
"provide a detailed explanation for a variable",
|
||||
"<var>",
|
||||
);
|
||||
opts.optopt(
|
||||
"d",
|
||||
|
@ -90,7 +89,7 @@ impl Args {
|
|||
|| matches.opt_present("A")
|
||||
|| matches.opt_present("X")
|
||||
|| !matches.free.is_empty()
|
||||
|| matches.opt_str("explain").is_some()
|
||||
|| matches.opt_present("E")
|
||||
|| preload_files;
|
||||
|
||||
if show_help || env_args.len() == 1 {
|
||||
|
@ -142,7 +141,7 @@ impl Args {
|
|||
pattern: matches
|
||||
.opt_str("r")
|
||||
.map(|v| Regex::new(&v).expect("invalid regex")),
|
||||
param_to_explain: matches.opt_str("E"),
|
||||
explain_params: matches.opt_present("E"),
|
||||
values: matches.free,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -28,18 +28,20 @@ pub fn run(args: Args) -> Result<()> {
|
|||
let mut sysctl = Sysctl::init(config)?;
|
||||
let mut app = App::new(&mut sysctl)?;
|
||||
|
||||
if let Some(param) = args.param_to_explain {
|
||||
app.update_documentation(args.kernel_docs.as_ref())?;
|
||||
app.display_documentation(¶m)?;
|
||||
} else if args.values.is_empty() {
|
||||
if args.values.is_empty() {
|
||||
app.display_parameters(args.pattern)?;
|
||||
} else if args.explain_params {
|
||||
app.update_documentation(args.kernel_docs.as_ref())?;
|
||||
for param in args.values {
|
||||
app.display_documentation(¶m)?;
|
||||
}
|
||||
} else if args.preload_files {
|
||||
for file in args.values {
|
||||
app.preload_values(file)?;
|
||||
}
|
||||
} else {
|
||||
for param_name in args.values {
|
||||
app.process_parameter(param_name, true)?;
|
||||
for param in args.values {
|
||||
app.process_parameter(param, true)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue