Skip to content

Commit

Permalink
refactor(config): rename update_conf function to update_config
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Jul 11, 2023
1 parent f60e817 commit 81f3e9a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl CliArgs {
}

/// Update the configuration based on the command-line arguments (the command-line arguments will override the configuration).
pub fn update_conf(&self, config: &mut Config) {
pub fn update_config(&self, config: &mut Config) {
config.check_help = !self.no_help;
config.check_version = !self.no_version;
if let Some(CliCommands::Plz {
Expand Down Expand Up @@ -118,7 +118,7 @@ mod tests {
}),
..Default::default()
};
args.update_conf(&mut config);
args.update_config(&mut config);
assert!(config.check_help);
assert_eq!(Some(String::from("bat")), config.pager_command);
}
Expand Down
44 changes: 22 additions & 22 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,28 @@ pub struct Config {
pub cheat_sh_url: String,
}

impl Default for Config {
fn default() -> Self {
Config {
check_version: true,
check_help: true,
check_args: Some(vec![
VersionArg::variants()
.iter()
.map(|s| s.as_str().to_string())
.collect(),
HelpArg::variants()
.iter()
.map(|s| s.as_str().to_string())
.collect(),
]),
man_command: "man".to_string(),
pager_command: Some("less -R".to_string()),
cheat_sh_url: DEFAULT_CHEAT_SHEET_PROVIDER.to_string(),
}
}
}

impl Config {
/// Checks the possible locations for the configuration file.
///
Expand Down Expand Up @@ -89,28 +111,6 @@ impl Config {
}
}

impl Default for Config {
fn default() -> Self {
Config {
check_version: true,
check_help: true,
check_args: Some(vec![
VersionArg::variants()
.iter()
.map(|s| s.as_str().to_string())
.collect(),
HelpArg::variants()
.iter()
.map(|s| s.as_str().to_string())
.collect(),
]),
man_command: "man".to_string(),
pager_command: Some("less -R".to_string()),
cheat_sh_url: DEFAULT_CHEAT_SHEET_PROVIDER.to_string(),
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
1 change: 0 additions & 1 deletion src/helper/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ pub fn get_args_help<Output: Write>(
if cmd.trim().is_empty() {
return Ok(());
}

if let Some(ref args) = config.check_args {
if args.is_empty() {
return Ok(());
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn run<Output: Write>(cli_args: CliArgs, output: &mut Output) -> Result<()>
}
config
};
cli_args.update_conf(&mut config);
cli_args.update_config(&mut config);
if let Some(ref cmd) = cli_args.cmd {
get_args_help(cmd, &config, cli_args.verbose, output)?;
} else if let Some(CliCommands::Plz { ref cmd, .. }) = cli_args.subcommand {
Expand Down

0 comments on commit 81f3e9a

Please sign in to comment.