Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow log-level parameter to affect log from reading config #1789

Merged
merged 5 commits into from
Oct 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,19 @@ fn configure_args(config: &mut Config, matches: &ArgMatches) -> Result<()> {
config.set_headers(headers);
}

if let Some(level_str) = matches.get_one::<String>("log_level") {
match level_str.parse() {
Ok(level) => {
config.set_log_level(level);
}
Ok(())
}

pub fn get_log_level(matches: &ArgMatches) -> Result<Option<LevelFilter>> {
match matches.get_one::<String>("log_level") {
Some(log_level) => match log_level.parse() {
Ok(log_level) => Ok(Some(log_level)),
Err(_) => {
bail!("Unknown log level: {}", level_str);
bail!("Unknown log level: {}", log_level);
}
}
},
None => Ok(None),
}

Ok(())
}

fn app() -> Command {
Expand Down Expand Up @@ -242,13 +243,21 @@ pub fn execute() -> Result<()> {
return Ok(());
}

let mut config = Config::from_cli_config()?;
let mut cmd = app();
cmd = add_commands(cmd);
let matches = cmd.get_matches();
let log_level = get_log_level(&matches)?;
if let Some(log_level) = log_level {
set_max_level(log_level);
}
let mut config = Config::from_cli_config()?;
configure_args(&mut config, &matches)?;
set_quiet_mode(matches.get_flag("quiet"));

if let Some(log_level) = log_level {
config.set_log_level(log_level);
}

// bind the config to the process and fetch an immutable reference to it
config.bind_to_process();
if Config::current().get_filename().exists() {
Expand Down
Loading