feat(app): support KERNEL_DOCS variable for specifying the documentation path

This commit is contained in:
Orhun Parmaksız 2022-03-18 02:16:10 +03:00
parent cc76d35916
commit f2145cb9ca
No known key found for this signature in database
GPG key ID: F83424824B3E4B90
3 changed files with 14 additions and 3 deletions

View file

@ -29,3 +29,6 @@ pub const SYSTEM_PRELOAD: &[&str] = &[
/// Deprecated parameters to skip while listing.
/// <https://bugzilla.redhat.com/show_bug.cgi?id=152435>
pub const DEPRECATED_PARAMS: &[&str] = &["base_reachable_time", "retrans_time"];
/// Environment variable for setting the path of the Linux kernel documentation.
pub const KERNEL_DOCS_ENV: &str = "KERNEL_DOCS";

View file

@ -1,7 +1,9 @@
use crate::style::Colors;
use getopts::Options;
use std::env;
use std::path::PathBuf;
use systeroid_core::sysctl::section::Section;
use systeroid_core::sysctl::KERNEL_DOCS_ENV;
/// Help message for the arguments.
const HELP_MESSAGE: &str = r#"
@ -91,7 +93,10 @@ impl Args {
.map_err(|e| eprintln!("error: `{}`", e))
.ok()?
.unwrap_or(250),
kernel_docs: matches.opt_str("D").map(PathBuf::from),
kernel_docs: matches
.opt_str("D")
.or_else(|| env::var(KERNEL_DOCS_ENV).ok())
.map(PathBuf::from),
section: matches.opt_str("s").map(Section::from),
search_query: matches.opt_str("q"),
colors: Colors::new(

View file

@ -4,7 +4,7 @@ use std::env;
use std::path::PathBuf;
use systeroid_core::parseit::regex::Regex;
use systeroid_core::sysctl::display::DisplayType;
use systeroid_core::sysctl::DEFAULT_PRELOAD;
use systeroid_core::sysctl::{DEFAULT_PRELOAD, KERNEL_DOCS_ENV};
/// Help message for the arguments.
const HELP_MESSAGE: &str = r#"
@ -179,7 +179,10 @@ impl Args {
verbose: matches.opt_present("v"),
quiet: matches.opt_present("q"),
write: matches.opt_present("w"),
kernel_docs: matches.opt_str("D").map(PathBuf::from),
kernel_docs: matches
.opt_str("D")
.or_else(|| env::var(KERNEL_DOCS_ENV).ok())
.map(PathBuf::from),
display_type,
display_deprecated: matches.opt_present("deprecated"),
ignore_errors: matches.opt_present("e"),