refactor(app): use consistent naming for getter functions

This commit is contained in:
Orhun Parmaksız 2021-12-18 14:12:07 +03:00
parent 86b7390ecb
commit c803fe4476
No known key found for this signature in database
GPG key ID: F83424824B3E4B90
3 changed files with 8 additions and 8 deletions

View file

@ -65,7 +65,7 @@ impl Sysctl {
.filter(|param| {
param.name == query.replace('/', ".")
|| param.section.to_string() == query
|| param.absolute_name() == Some(&query.replace('/', "."))
|| param.get_absolute_name() == Some(&query.replace('/', "."))
})
.collect::<Vec<&Parameter>>();
if parameters.is_empty() {
@ -107,7 +107,7 @@ impl Sysctl {
{
if let Some(paragraph) =
document.paragraphs.par_iter().find_first(|paragraph| {
match param.absolute_name() {
match param.get_absolute_name() {
Some(absolute_name) => {
absolute_name.len() > 2
&& paragraph.title.contains(absolute_name)

View file

@ -45,12 +45,12 @@ 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> {
pub fn get_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 {
pub fn get_colored_name(&self, config: &Config) -> String {
let section_color = *(config
.section_colors
.get(&self.section)
@ -109,7 +109,7 @@ impl Parameter {
pub fn display_value<Output: Write>(&self, config: &Config, output: &mut Output) -> Result<()> {
match config.display_type {
DisplayType::Name => {
writeln!(output, "{}", self.colored_name(config))?;
writeln!(output, "{}", self.get_colored_name(config))?;
}
DisplayType::Value => {
writeln!(output, "{}", self.value.bold())?;
@ -121,7 +121,7 @@ impl Parameter {
writeln!(
output,
"{} {} {}",
self.colored_name(config),
self.get_colored_name(config),
"=".color(config.default_color),
self.value.bold(),
)?;

View file

@ -76,7 +76,7 @@ impl<'a, Output: Write> App<'a, Output> {
return pattern.is_match(&parameter.name);
}
if !display_deprecated {
if let Some(param_name) = parameter.absolute_name() {
if let Some(param_name) = parameter.get_absolute_name() {
return !DEPRECATED_PARAMS.contains(&param_name);
}
}
@ -163,7 +163,7 @@ impl<'a, Output: Write> App<'a, Output> {
if let Some(new_value) = new_value {
let config = self.sysctl.config.clone();
if let Some(param) = self.sysctl.get_parameter(&parameter) {
if DEPRECATED_PARAMS.contains(&param.absolute_name().unwrap_or_default()) {
if DEPRECATED_PARAMS.contains(&param.get_absolute_name().unwrap_or_default()) {
eprintln!(
"{}: {} is deprecated, value not set",
env!("CARGO_PKG_NAME"),