mirror of
https://github.com/orhun/systeroid
synced 2024-07-21 10:25:00 +00:00
feat(args): add --deprecated
flag for including deprecated variables
This commit is contained in:
parent
24154ef31f
commit
aa78731b3f
|
@ -65,10 +65,7 @@ impl Sysctl {
|
|||
.filter(|param| {
|
||||
param.name == query.replace("/", ".")
|
||||
|| param.section.to_string() == query
|
||||
|| match param.name.split('.').collect::<Vec<&str>>().last() {
|
||||
Some(absolute_name) => absolute_name == &query.replace("/", "."),
|
||||
_ => false,
|
||||
}
|
||||
|| param.absolute_name() == Some(&query.replace("/", "."))
|
||||
})
|
||||
.collect::<Vec<&Parameter>>();
|
||||
if parameters.is_empty() {
|
||||
|
@ -110,7 +107,7 @@ impl Sysctl {
|
|||
{
|
||||
if let Some(paragraph) =
|
||||
document.paragraphs.par_iter().find_first(|paragraph| {
|
||||
match param.name.split('.').collect::<Vec<&str>>().last() {
|
||||
match param.absolute_name() {
|
||||
Some(absolute_name) => {
|
||||
absolute_name.len() > 2
|
||||
&& paragraph.title.contains(absolute_name)
|
||||
|
|
|
@ -12,3 +12,7 @@ pub mod parameter;
|
|||
|
||||
/// Default location to preload values.
|
||||
pub const DEFAULT_PRELOAD: &str = "/etc/sysctl.conf";
|
||||
|
||||
/// Deprecated variables to skip while listing.
|
||||
/// <https://bugzilla.redhat.com/show_bug.cgi?id=152435>
|
||||
pub const DEPRECATED_VARIABLES: &[&str] = &["base_reachable_time", "retrans_time"];
|
||||
|
|
|
@ -44,6 +44,11 @@ impl<'a> TryFrom<&'a Ctl> for Parameter {
|
|||
}
|
||||
|
||||
impl Parameter {
|
||||
/// Returns the absolute name of the parameter, without the sections.
|
||||
pub fn absolute_name(&self) -> Option<&str> {
|
||||
self.name.split('.').collect::<Vec<&str>>().last().copied()
|
||||
}
|
||||
|
||||
/// Returns the parameter name with corresponding section colors.
|
||||
pub fn colored_name(&self, config: &Config) -> String {
|
||||
let fields = self.name.split('.').collect::<Vec<&str>>();
|
||||
|
|
|
@ -7,6 +7,7 @@ use systeroid_core::error::Result;
|
|||
use systeroid_core::parsers::KERNEL_DOCS_PATH;
|
||||
use systeroid_core::regex::Regex;
|
||||
use systeroid_core::sysctl::controller::Sysctl;
|
||||
use systeroid_core::sysctl::DEPRECATED_VARIABLES;
|
||||
use systeroid_parser::reader;
|
||||
|
||||
/// Label for caching the kernel parameters.
|
||||
|
@ -34,16 +35,24 @@ impl<'a> App<'a> {
|
|||
}
|
||||
|
||||
/// Displays all of the available kernel parameters.
|
||||
pub fn display_parameters(&mut self, pattern: Option<Regex>) -> Result<()> {
|
||||
pub fn display_parameters(
|
||||
&mut self,
|
||||
pattern: Option<Regex>,
|
||||
display_deprecated: bool,
|
||||
) -> Result<()> {
|
||||
self.sysctl
|
||||
.parameters
|
||||
.iter()
|
||||
.filter(|parameter| {
|
||||
if let Some(pattern) = &pattern {
|
||||
pattern.is_match(¶meter.name)
|
||||
} else {
|
||||
true
|
||||
return pattern.is_match(¶meter.name);
|
||||
}
|
||||
if !display_deprecated {
|
||||
if let Some(param_name) = parameter.absolute_name() {
|
||||
return !DEPRECATED_VARIABLES.contains(¶m_name);
|
||||
}
|
||||
}
|
||||
true
|
||||
})
|
||||
.try_for_each(|parameter| {
|
||||
parameter.display_value(&self.sysctl.config, &mut self.stdout)
|
||||
|
|
|
@ -26,13 +26,15 @@ pub struct Args {
|
|||
pub kernel_docs: Option<PathBuf>,
|
||||
/// Display type of the variables.
|
||||
pub display_type: DisplayType,
|
||||
/// Whether if the deprecated variables should be included while listing.
|
||||
pub display_deprecated: bool,
|
||||
/// Whether if the unknown variable errors should be ignored.
|
||||
pub ignore_errors: bool,
|
||||
/// Do not pipe output into a pager.
|
||||
pub no_pager: bool,
|
||||
/// Whether if files are given to preload values.
|
||||
pub preload_files: bool,
|
||||
/// Pattern for matching the parameters.
|
||||
/// Pattern for matching the variables.
|
||||
pub pattern: Option<Regex>,
|
||||
/// Whether if the documentation should be shown.
|
||||
pub explain_params: bool,
|
||||
|
@ -47,6 +49,11 @@ impl Args {
|
|||
opts.optflag("a", "all", "display all variables");
|
||||
opts.optflag("A", "", "alias of -a");
|
||||
opts.optflag("X", "", "alias of -a");
|
||||
opts.optflag(
|
||||
"D",
|
||||
"deprecated",
|
||||
"include deprecated variables while listing",
|
||||
);
|
||||
opts.optflag("e", "ignore", "ignore unknown variable errors");
|
||||
opts.optflag("N", "names", "print only variable names");
|
||||
opts.optflag("n", "values", "print only variable values");
|
||||
|
@ -136,6 +143,7 @@ impl Args {
|
|||
quiet: matches.opt_present("q"),
|
||||
kernel_docs: matches.opt_str("d").map(PathBuf::from),
|
||||
display_type,
|
||||
display_deprecated: matches.opt_present("D"),
|
||||
ignore_errors: matches.opt_present("e"),
|
||||
no_pager: matches.opt_present("P"),
|
||||
preload_files,
|
||||
|
|
|
@ -29,7 +29,7 @@ pub fn run(args: Args) -> Result<()> {
|
|||
let mut app = App::new(&mut sysctl)?;
|
||||
|
||||
if args.values.is_empty() {
|
||||
app.display_parameters(args.pattern)?;
|
||||
app.display_parameters(args.pattern, args.display_deprecated)?;
|
||||
} else if args.explain_params {
|
||||
app.update_documentation(args.kernel_docs.as_ref())?;
|
||||
for param in args.values {
|
||||
|
|
Loading…
Reference in a new issue