Skip to content

Commit

Permalink
Merge pull request #78 from solidiquis/bug/config-level-option
Browse files Browse the repository at this point in the history
fix issue where level wasn't being read from config
  • Loading branch information
solidiquis authored Mar 15, 2023
2 parents 0683e7b + 650e86d commit 62a6331
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/render/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::{
order::SortType,
};
use clap::{
parser::ValueSource, ArgMatches, CommandFactory, Error as ClapError, FromArgMatches, Parser,
parser::ValueSource, ArgMatches, CommandFactory, Error as ClapError, FromArgMatches, Id, Parser,
};
use ignore::overrides::{Override, OverrideBuilder};
use std::{
Expand Down Expand Up @@ -154,22 +154,28 @@ impl Context {
}
};

for id in user_args.ids() {
let id_str = id.as_str();
let mut ids = user_args.ids().map(Id::as_str).collect::<Vec<&str>>();

ids.extend(config_args.ids().map(Id::as_str).collect::<Vec<&str>>());

ids = crate::utils::uniq(ids);

for id in ids {
// Don't look at me... my shame..
if id_str == "Context" {
if id == "Context" {
continue;
}

if let Some(user_arg) = user_args.value_source(id_str) {
if let Some(user_arg) = user_args.value_source(id) {
match user_arg {
// prioritize the user arg if user provided a command line argument
ValueSource::CommandLine => pick_args_from(id_str, &user_args),
ValueSource::CommandLine => pick_args_from(id, &user_args),

// otherwise prioritize argument from the config
_ => pick_args_from(id_str, &config_args),
_ => pick_args_from(id, &config_args),
}
} else {
pick_args_from(id, &config_args)
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{borrow::ToOwned, cmp::Eq, collections::HashSet, hash::Hash};

#[macro_export]
/// Ruby-like way to crate a hashmap.
macro_rules! hash {
( $( $k:expr => $v:expr ),* ) => {
{
Expand All @@ -8,3 +11,17 @@ macro_rules! hash {
}
};
}

/// Ensure every item in a `Vec` is unique.
pub fn uniq<T: Eq + Hash + ToOwned>(items: Vec<T>) -> Vec<T>
where
T: Eq + Hash + ToOwned,
<T as ToOwned>::Owned: Hash + Eq,
{
let mut set = HashSet::new();

items
.into_iter()
.filter(|item| set.insert(item.to_owned()))
.collect::<Vec<T>>()
}

0 comments on commit 62a6331

Please sign in to comment.