Skip to content

Commit

Permalink
fix: config parsing requiring mandatory args on cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Mydayyy committed Nov 26, 2024
1 parent f4f5ff5 commit fed0f87
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
11 changes: 11 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,14 @@ pub fn get_config_args(skip_default_locations: bool) -> Vec<OsString> {
pub fn get_cli_args() -> Vec<OsString> {
std::env::args_os().collect()
}

fn has_flag(flag_name: &str) -> bool {
get_cli_args().contains(&OsString::from(flag_name))
}
pub fn has_debug_flag() -> bool {
has_flag("--debug")
}

pub fn has_skip_default_config_flag() -> bool {
has_flag("--skip-default-config")
}
11 changes: 5 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,18 @@ fn handle_comment(opts: &Opts) -> PbResult<()> {
fn main() -> PbResult<()> {
crate::logger::SimpleLogger::init()?;

let mut env_args = pbcli::config::get_cli_args();
let mut opts: Opts = Opts::parse_from(&env_args);

if opts.debug {
if pbcli::config::has_debug_flag() {
log::set_max_level(log::LevelFilter::Debug);
}

let config_args = pbcli::config::get_config_args(opts.no_default_config);
let config_args = pbcli::config::get_config_args(pbcli::config::has_skip_default_config_flag());
let mut env_args = pbcli::config::get_cli_args();
let mut merged_args: Vec<OsString> = vec![];
merged_args.extend(env_args.drain(0..1));
merged_args.extend(config_args);
merged_args.extend(env_args);
opts.update_from(merged_args);

let opts: Opts = Opts::parse_from(&merged_args);

let url_has_query = opts.get_url().query().is_some();
if url_has_query {
Expand Down

0 comments on commit fed0f87

Please sign in to comment.