Skip to content

Commit b6b3044

Browse files
committed
update!: changed OptCfg::make_cfgs_for to make_opt_cfgs_for
1 parent 3df1071 commit b6b3044

File tree

5 files changed

+35
-34
lines changed

5 files changed

+35
-34
lines changed

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ pub use help::HelpIter;
326326
pub use opt_cfg::validators;
327327

328328
mod parse;
329+
pub use parse::make_opt_cfgs_for;
329330
pub use parse::OptStore;
330331

331332
extern crate cliargs_derive;

src/parse/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod parse;
66
mod parse_with;
77

88
mod parse_for;
9+
pub use parse_for::make_opt_cfgs_for;
910
pub use parse_for::OptStore;
1011

1112
use crate::errors::InvalidOption;

src/parse/parse.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -801,26 +801,27 @@ mod tests_of_parse_until_sub_cmd {
801801
}
802802

803803
#[test]
804-
fn test_if_sub_command_is_like_path() { // for the fix of issue #39
804+
fn test_if_sub_command_is_like_path() {
805+
// for the fix of issue #39
805806
let ui_args = vec![
806807
"/path/to/app".to_string(),
807808
"--foo-bar".to_string(),
808809
"path/to/bar".to_string(),
809810
"--baz".to_string(),
810-
"qux".to_string()
811+
"qux".to_string(),
811812
];
812813
let mut cmd = Cmd::with_strings(ui_args);
813814

814815
if let Some(mut sub_cmd) = cmd.parse_until_sub_cmd().unwrap() {
815-
sub_cmd.parse().unwrap();
816+
sub_cmd.parse().unwrap();
816817

817-
assert_eq!(cmd.name(), "app");
818-
assert_eq!(cmd.args(), &[] as &[&str]);
819-
assert_eq!(cmd.has_opt("foo-bar"), true);
818+
assert_eq!(cmd.name(), "app");
819+
assert_eq!(cmd.args(), &[] as &[&str]);
820+
assert_eq!(cmd.has_opt("foo-bar"), true);
820821

821-
assert_eq!(sub_cmd.name(), "path/to/bar");
822-
assert_eq!(sub_cmd.args(), &["qux"]);
823-
assert_eq!(sub_cmd.has_opt("baz"), true);
822+
assert_eq!(sub_cmd.name(), "path/to/bar");
823+
assert_eq!(sub_cmd.args(), &["qux"]);
824+
assert_eq!(sub_cmd.has_opt("baz"), true);
824825
}
825826
}
826827
}

src/parse/parse_for.rs

+21-23
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,23 @@ pub trait OptStore {
1919
fn set_field_values(&mut self, m: &HashMap<&str, Vec<&str>>) -> Result<(), InvalidOption>;
2020
}
2121

22-
impl OptCfg {
23-
/// Makes a vector of [OptCfg] struct instances from the field definitions and `opt` field
24-
/// attributes of the struct instnace of which type is `T`.
25-
///
26-
/// One [OptCfg] struct instance is made for each field.
27-
/// The field name is set to `store_key`.
28-
/// If the field's data type is `bool`, `has_arg` is set to `false`, otherwise, it is set to
29-
/// `true`.
30-
/// If the field is a vector type, `is_array` is set to `true`; otherwise, it is set to
31-
/// `false`.
32-
///
33-
/// Additionally, `names`, `defaults`, `desc`, and `arg_in_help` are set with extracted from
34-
/// the `opt` attribute attached to the field.
35-
///
36-
/// For `validator`, if the field's data type is numeric, it is set to the `validate_number`
37-
/// function pointer corresponding to the data type.
38-
pub fn make_cfgs_for<T: OptStore>(opt_store: &mut T) -> Vec<OptCfg> {
39-
opt_store.make_opt_cfgs()
40-
}
22+
/// Makes a vector of [OptCfg] struct instances from the field definitions and `opt` field
23+
/// attributes of the struct instnace of which type is `T`.
24+
///
25+
/// One [OptCfg] struct instance is made for each field.
26+
/// The field name is set to `store_key`.
27+
/// If the field's data type is `bool`, `has_arg` is set to `false`, otherwise, it is set to
28+
/// `true`.
29+
/// If the field is a vector type, `is_array` is set to `true`; otherwise, it is set to
30+
/// `false`.
31+
///
32+
/// Additionally, `names`, `defaults`, `desc`, and `arg_in_help` are set with extracted from
33+
/// the `opt` attribute attached to the field.
34+
///
35+
/// For `validator`, if the field's data type is numeric, it is set to the `validate_number`
36+
/// function pointer corresponding to the data type.
37+
pub fn make_opt_cfgs_for<T: OptStore>(opt_store: &mut T) -> Vec<OptCfg> {
38+
opt_store.make_opt_cfgs()
4139
}
4240

4341
impl<'b> Cmd<'_> {
@@ -180,7 +178,7 @@ impl<'b> Cmd<'_> {
180178
}
181179

182180
#[cfg(test)]
183-
mod tests_of_make_cfgs_for {
181+
mod tests_of_make_opt_cfgs_for {
184182
use super::*;
185183
use crate as cliargs;
186184
extern crate cliargs_derive;
@@ -304,7 +302,7 @@ mod tests_of_make_cfgs_for {
304302
#[test]
305303
fn test_make_opt_cfgs_for_opt_store() {
306304
let mut store = NoAttrOptions::with_defaults();
307-
let cfgs = cliargs::OptCfg::make_cfgs_for(&mut store);
305+
let cfgs = cliargs::make_opt_cfgs_for(&mut store);
308306
assert_eq!(cfgs.len(), 40);
309307

310308
let cfg = &cfgs[0];
@@ -1084,7 +1082,7 @@ mod tests_of_make_cfgs_for {
10841082
#[test]
10851083
fn test_make_opt_cfgs_for_store() {
10861084
let mut store = WithAttrOptions::with_defaults();
1087-
let cfgs = cliargs::OptCfg::make_cfgs_for(&mut store);
1085+
let cfgs = cliargs::make_opt_cfgs_for(&mut store);
10881086
assert_eq!(cfgs.len(), 40);
10891087

10901088
let cfg = &cfgs[0];
@@ -1501,7 +1499,7 @@ mod tests_of_make_cfgs_for {
15011499
empty_str: Vec<String>,
15021500
}
15031501
let mut store = MyOptions::with_defaults();
1504-
let cfgs = cliargs::OptCfg::make_cfgs_for(&mut store);
1502+
let cfgs = cliargs::make_opt_cfgs_for(&mut store);
15051503
assert_eq!(cfgs.len(), 4);
15061504
assert_eq!(cfgs[0].store_key, "empty".to_string());
15071505
assert_eq!(cfgs[0].defaults, Some(Vec::<String>::new()));

tests/parse_for_test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ mod tests_of_parse_for {
99
}
1010

1111
#[test]
12-
fn make_cfgs_for_my_options() {
12+
fn make_opt_cfgs_for_my_options() {
1313
let mut my_options = MyOptions::with_defaults();
1414
assert_eq!(my_options.foo_bar, false);
1515

16-
let cfgs = cliargs::OptCfg::make_cfgs_for(&mut my_options);
16+
let cfgs = cliargs::make_opt_cfgs_for(&mut my_options);
1717
assert_eq!(cfgs.len(), 1);
1818

1919
let cfg = &cfgs[0];

0 commit comments

Comments
 (0)