Skip to content

Commit

Permalink
remove lint warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Coenen <[email protected]>
  • Loading branch information
bnjjj committed Dec 13, 2023
1 parent 604175c commit d95304b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
11 changes: 10 additions & 1 deletion twelf/examples/expand.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::collections::HashMap;

use twelf::reexports::serde::{Deserialize, Serialize};
use twelf::{config, Layer};

#[config]
Expand All @@ -13,6 +12,16 @@ pub struct Settings {
pub profiles: HashMap<String, HashMap<String, String>>,
}

fn main() {
let config = Settings::with_layers(&[
Layer::Toml("./examples/config.toml".into()),
Layer::Env(Some(String::from("TERRAPHIM_"))),
])
.unwrap();

println!("config - {:?}", config);
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
16 changes: 7 additions & 9 deletions twelf/tests/clap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use std::collections::HashMap;

use clap_rs as clap;
use clap::{CommandFactory, Parser};
use clap_rs as clap;
use config_derive::config;
use twelf::Layer;

Expand All @@ -28,7 +28,7 @@ fn clap_with_array_and_hashmap() {
.unwrap()
.contains("My custom documentation on elements-snake in clap"));

let matches = app.get_matches_from(&[
let matches = app.get_matches_from([
"test",
"--arrays=first,second",
"--elements-snake=coucou=toi,hello=you",
Expand All @@ -52,7 +52,7 @@ fn clap_with_array_and_hashmap() {
#[test]
fn clap_derive_array() {
#[config]
#[derive(Parser,Debug, Default)]
#[derive(Parser, Debug, Default)]
#[clap(author, version, about, long_about = None)]
struct Conf {
#[clap(long, default_value_t = 55)]
Expand All @@ -62,17 +62,15 @@ fn clap_derive_array() {
arrays: Vec<String>,
}

let matches = Conf::command().get_matches_from(&[
let matches = Conf::command().get_matches_from([
"test",
"--arrays=asdf",
"--some-val=14",
"--arrays=qwer,zxc"
"--arrays=qwer,zxc",
]);

let prio = vec![
Layer::Clap(matches),
];
let prio = vec![Layer::Clap(matches)];
let config = Conf::with_layers(&prio).unwrap();

assert_eq!(config.arrays, vec!["asdf","qwer","zxc"]);
assert_eq!(config.arrays, vec!["asdf", "qwer", "zxc"]);
}
12 changes: 4 additions & 8 deletions twelf/tests/mixed.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![cfg(all(feature = "toml", feature = "json"))]

#![allow(dead_code)]

use std::collections::HashMap;
Expand Down Expand Up @@ -237,19 +236,16 @@ fn mixed_clap_defaults() {
array_def: Vec<String>,
}

let matches = Conf::command().get_matches_from(&["test", "--array-def=asdf,qwer"]);
let matches = Conf::command().get_matches_from(["test", "--array-def=asdf,qwer"]);

std::env::set_var("STRING_DEF", "coucou toi");

let prio = vec![
Layer::Env(None),
Layer::Clap(matches),
];
let prio = vec![Layer::Env(None), Layer::Clap(matches)];
let config = Conf::with_layers(&prio).unwrap();

let vec = vec!["asdf", "qwer"];

assert_eq!(config.string_def, "coucou toi"); // Env Layer
assert_eq!(config.some_num, 55); // Clap default
assert_eq!(config.array_def, vec); // Clap CLI
assert_eq!(config.some_num, 55); // Clap default
assert_eq!(config.array_def, vec); // Clap CLI
}

0 comments on commit d95304b

Please sign in to comment.