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

update!: changed parameter type of OptCfg::with #36

Merged
merged 1 commit into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
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
42 changes: 21 additions & 21 deletions src/help/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ mod tests_of_help {
use crate::OptCfgParam::*;

let mut help = Help::new();
help.add_opts(&[OptCfg::with(&[
help.add_opts(&[OptCfg::with([
names(&["foo-bar"]),
desc("This is a description of option."),
])]);
Expand All @@ -841,7 +841,7 @@ mod tests_of_help {
let cols = linebreak::term_cols();

let mut help = Help::new();
help.add_opts(&[OptCfg::with(&[
help.add_opts(&[OptCfg::with([
names(&["foo-bar"]),
desc(&("a".repeat(cols - 11) + " bcdef")),
])]);
Expand Down Expand Up @@ -869,7 +869,7 @@ mod tests_of_help {

let mut help = Help::with_margins(4, 2);

help.add_opts(&[OptCfg::with(&[
help.add_opts(&[OptCfg::with([
names(&["foo-bar"]),
desc(&("a".repeat(cols - 11 - 4 - 2) + " " + &"b".repeat(cols - 11 - 4 - 2) + "ccc")),
])]);
Expand Down Expand Up @@ -904,7 +904,7 @@ mod tests_of_help {
let mut help = Help::new();

help.add_opts_with_margins(
&[OptCfg::with(&[
&[OptCfg::with([
names(&["foo-bar"]),
desc(
&("a".repeat(cols - 11 - 5 - 4) + " " + &"b".repeat(cols - 11 - 5 - 4) + "ccc"),
Expand Down Expand Up @@ -944,7 +944,7 @@ mod tests_of_help {
let mut help = Help::with_margins(4, 2);

help.add_opts_with_margins(
&[OptCfg::with(&[
&[OptCfg::with([
names(&["foo-bar"]),
desc(
&("a".repeat(cols - 11 - 5 - 4) + " " + &"b".repeat(cols - 11 - 5 - 4) + "ccc"),
Expand Down Expand Up @@ -983,7 +983,7 @@ mod tests_of_help {

let mut help = Help::new();
help.add_opts_with_indent(
&[OptCfg::with(&[
&[OptCfg::with([
names(&["foo-bar"]),
desc(&("a".repeat(cols - 12) + " " + &"b".repeat(cols - 12) + "ccc")),
])],
Expand Down Expand Up @@ -1016,7 +1016,7 @@ mod tests_of_help {

let mut help = Help::new();
help.add_opts_with_indent(
&[OptCfg::with(&[
&[OptCfg::with([
names(&["foo-bar"]),
desc(&("a".repeat(cols))),
])],
Expand Down Expand Up @@ -1046,13 +1046,13 @@ mod tests_of_help {

let mut help = Help::new();
help.add_opts(&[
OptCfg::with(&[
OptCfg::with([
names(&["foo-bar", "f"]),
has_arg(true),
desc(&("a".repeat(cols - 22) + " " + &"b".repeat(cols - 22) + "ccc")),
arg_in_help("<text>"),
]),
OptCfg::with(&[
OptCfg::with([
names(&["baz", "b"]),
desc(&("d".repeat(cols - 22) + " " + &"e".repeat(cols - 22) + "fff")),
]),
Expand Down Expand Up @@ -1094,8 +1094,8 @@ mod tests_of_help {

let mut help = Help::new();
help.add_opts(&[
OptCfg::with(&[names(&["foo-bar"]), desc("description")]),
OptCfg::with(&[names(&["*"]), desc("any option")]),
OptCfg::with([names(&["foo-bar"]), desc("description")]),
OptCfg::with([names(&["*"]), desc("any option")]),
]);

let mut iter = help.iter();
Expand All @@ -1113,8 +1113,8 @@ mod tests_of_help {

let mut help = Help::new();
help.add_opts(&[
OptCfg::with(&[store_key("foo"), desc("description")]),
OptCfg::with(&[store_key("*"), desc("any option")]),
OptCfg::with([store_key("foo"), desc("description")]),
OptCfg::with([store_key("*"), desc("any option")]),
]);

let mut iter = help.iter();
Expand All @@ -1132,8 +1132,8 @@ mod tests_of_help {

let mut help = Help::new();
help.add_opts(&[
OptCfg::with(&[names(&["foo-bar"]), desc("description")]),
OptCfg::with(&[names(&["*"]), desc("any option")]),
OptCfg::with([names(&["foo-bar"]), desc("description")]),
OptCfg::with([names(&["*"]), desc("any option")]),
]);

let mut iter = help.iter();
Expand All @@ -1154,8 +1154,8 @@ mod tests_of_help {
let mut help = Help::new();
help.add_opts_with_indent(
&[
OptCfg::with(&[names(&["foo-bar"]), desc("description")]),
OptCfg::with(&[names(&["baz"]), desc("description")]),
OptCfg::with([names(&["foo-bar"]), desc("description")]),
OptCfg::with([names(&["baz"]), desc("description")]),
],
cols + 1,
);
Expand All @@ -1178,8 +1178,8 @@ mod tests_of_help {
let mut help = Help::new();
help.add_opts_with_margins(
&[
OptCfg::with(&[names(&["foo-bar"]), desc("description")]),
OptCfg::with(&[names(&["baz"]), desc("description")]),
OptCfg::with([names(&["foo-bar"]), desc("description")]),
OptCfg::with([names(&["baz"]), desc("description")]),
],
cols - 1,
1,
Expand All @@ -1200,8 +1200,8 @@ mod tests_of_help {

let mut help = Help::new();
help.add_opts(&[
OptCfg::with(&[names(&["", "f", "foo-bar", "", ""]), desc("description")]),
OptCfg::with(&[names(&["b", "", "z", "baz"]), desc("description")]),
OptCfg::with([names(&["", "f", "foo-bar", "", ""]), desc("description")]),
OptCfg::with([names(&["b", "", "z", "baz"]), desc("description")]),
]);

let mut iter = help.iter();
Expand Down
35 changes: 16 additions & 19 deletions src/help/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,52 +203,52 @@ mod tests_of_make_opt_title {

#[test]
fn test_when_cfg_has_only_one_long_name() {
let cfg = OptCfg::with(&[names(&["foo-bar"])]);
let cfg = OptCfg::with([names(&["foo-bar"])]);
let (indent, title) = make_opt_title(&cfg);
assert_eq!(indent, 0);
assert_eq!(title, "--foo-bar");
}

#[test]
fn test_when_cfg_has_only_one_short_name() {
let cfg = OptCfg::with(&[names(&["f"])]);
let cfg = OptCfg::with([names(&["f"])]);
let (indent, title) = make_opt_title(&cfg);
assert_eq!(indent, 0);
assert_eq!(title, "-f");
}

#[test]
fn test_when_cfg_has_multiple_names() {
let cfg = OptCfg::with(&[names(&["f", "b", "foo-bar"])]);
let cfg = OptCfg::with([names(&["f", "b", "foo-bar"])]);
let (indent, title) = make_opt_title(&cfg);
assert_eq!(indent, 0);
assert_eq!(title, "-f, -b, --foo-bar");
}

#[test]
fn test_when_cfg_has_no_name_but_store_key() {
let cfg = OptCfg::with(&[store_key("Foo_Bar")]);
let cfg = OptCfg::with([store_key("Foo_Bar")]);
let (indent, title) = make_opt_title(&cfg);
assert_eq!(indent, 0);
assert_eq!(title, "--Foo_Bar");
}

#[test]
fn test_when_cfg_names_contain_emtpy_name() {
let cfg = OptCfg::with(&[names(&["", "f"])]);
let cfg = OptCfg::with([names(&["", "f"])]);
let (indent, title) = make_opt_title(&cfg);
assert_eq!(indent, 4);
assert_eq!(title, "-f");

let cfg = OptCfg::with(&[names(&["", "f", "", "b", ""])]);
let cfg = OptCfg::with([names(&["", "f", "", "b", ""])]);
let (indent, title) = make_opt_title(&cfg);
assert_eq!(indent, 4);
assert_eq!(title, "-f, -b");
}

#[test]
fn test_when_cfg_names_are_all_empty_and_has_store_key() {
let cfg = OptCfg::with(&[store_key("FooBar"), names(&["", ""])]);
let cfg = OptCfg::with([store_key("FooBar"), names(&["", ""])]);
let (indent, title) = make_opt_title(&cfg);
assert_eq!(indent, 8);
assert_eq!(title, "--FooBar");
Expand All @@ -262,7 +262,7 @@ mod tests_of_create_opts_help {

#[test]
fn test_when_cfg_has_only_one_long_name() {
let cfgs = vec![OptCfg::with(&[names(&["foo-bar"])])];
let cfgs = vec![OptCfg::with([names(&["foo-bar"])])];

let mut indent = 0;
let vec = create_opts_help(&cfgs, &mut indent);
Expand All @@ -276,7 +276,7 @@ mod tests_of_create_opts_help {

#[test]
fn test_when_cfg_has_only_one_long_name_and_desc() {
let cfgs = vec![OptCfg::with(&[
let cfgs = vec![OptCfg::with([
names(&["foo-bar"]),
desc("The description of foo-bar."),
])];
Expand All @@ -293,7 +293,7 @@ mod tests_of_create_opts_help {

#[test]
fn test_when_cfg_has_only_one_long_name_and_desc_and_arg_in_help() {
let cfgs = vec![OptCfg::with(&[
let cfgs = vec![OptCfg::with([
names(&["foo-bar"]),
desc("The description of foo-bar."),
arg_in_help("<num>"),
Expand All @@ -311,7 +311,7 @@ mod tests_of_create_opts_help {

#[test]
fn test_when_cfg_has_only_one_short_name() {
let cfgs = vec![OptCfg::with(&[names(&["f"])])];
let cfgs = vec![OptCfg::with([names(&["f"])])];

let mut indent = 0;
let vec = create_opts_help(&cfgs, &mut indent);
Expand All @@ -325,10 +325,7 @@ mod tests_of_create_opts_help {

#[test]
fn test_when_cfg_has_only_one_short_name_and_desc() {
let cfgs = vec![OptCfg::with(&[
names(&["f"]),
desc("The description of f."),
])];
let cfgs = vec![OptCfg::with([names(&["f"]), desc("The description of f.")])];

let mut indent = 0;
let vec = create_opts_help(&cfgs, &mut indent);
Expand All @@ -342,7 +339,7 @@ mod tests_of_create_opts_help {

#[test]
fn test_when_cfg_has_only_one_short_name_and_desc_and_arg_in_help() {
let cfgs = vec![OptCfg::with(&[
let cfgs = vec![OptCfg::with([
names(&["f"]),
desc("The description of f."),
arg_in_help("<n>"),
Expand All @@ -360,7 +357,7 @@ mod tests_of_create_opts_help {

#[test]
fn test_when_indent_is_positive_and_longer_than_title() {
let cfgs = vec![OptCfg::with(&[
let cfgs = vec![OptCfg::with([
names(&["foo-bar"]),
desc("The description of foo-bar."),
arg_in_help("<num>"),
Expand All @@ -378,7 +375,7 @@ mod tests_of_create_opts_help {

#[test]
fn test_when_indent_is_positive_and_shorter_than_title() {
let cfgs = vec![OptCfg::with(&[
let cfgs = vec![OptCfg::with([
names(&["foo-bar"]),
desc("The description of foo-bar."),
arg_in_help("<num>"),
Expand Down Expand Up @@ -411,7 +408,7 @@ mod tests_of_create_opts_help {

#[test]
fn test_when_names_contains_empty_strings() {
let cfgs = vec![OptCfg::with(&[
let cfgs = vec![OptCfg::with([
names(&["", "", "f", "", "foo-bar", ""]),
desc("The description of foo-bar."),
arg_in_help("<num>"),
Expand Down
20 changes: 10 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
//! If you want to prioritize the output of short option name first in the help
//! text, like `-f, --foo-bar`, but use the long option name as the key in the
//! option map, write `store_key` and `names` fields as follows:
//! `OptCfg::with(&[store_key("foo-bar"), names(&["f", "foo-bar"])])`.
//! `OptCfg::with([store_key("foo-bar"), names(&["f", "foo-bar"])])`.
//!
//! `has_arg` field indicates the option requires one or more values.
//! `is_array` field indicates the option can have multiple values.
Expand Down Expand Up @@ -167,7 +167,7 @@
//! arg_in_help: "<num>".to_string(),
//! validator: validate_number::<u64>,
//! },
//! OptCfg::with(&[
//! OptCfg::with([
//! names(&["baz", "z"]),
//! has_arg(true),
//! defaults(&["1"]),
Expand Down Expand Up @@ -900,8 +900,8 @@ mod tests_of_cmd {
}

let cfgs = vec![
OptCfg::with(&[names(&["foo"])]),
OptCfg::with(&[names(&["bar"]), has_arg(true), is_array(true)]),
OptCfg::with([names(&["foo"])]),
OptCfg::with([names(&["bar"]), has_arg(true), is_array(true)]),
];

let mut cmd = Cmd::with_strings([
Expand All @@ -923,8 +923,8 @@ mod tests_of_cmd {
fn should_move_by_returning() {
fn move_cmd() -> Cmd<'static> {
let cfgs = vec![
OptCfg::with(&[names(&["foo"])]),
OptCfg::with(&[names(&["bar"]), has_arg(true), is_array(true)]),
OptCfg::with([names(&["foo"])]),
OptCfg::with([names(&["bar"]), has_arg(true), is_array(true)]),
];

let mut cmd = Cmd::with_strings([
Expand Down Expand Up @@ -982,8 +982,8 @@ mod tests_of_cmd {
fn should_move_by_mem_replace() {
fn move_cmd() -> Cmd<'static> {
let cfgs = vec![
OptCfg::with(&[names(&["foo"])]),
OptCfg::with(&[names(&["bar"]), has_arg(true), is_array(true)]),
OptCfg::with([names(&["foo"])]),
OptCfg::with([names(&["bar"]), has_arg(true), is_array(true)]),
];

let mut cmd = Cmd::with_strings([
Expand Down Expand Up @@ -1044,8 +1044,8 @@ mod tests_of_cmd {
fn should_move_by_mem_swap() {
fn move_cmd() -> Cmd<'static> {
let cfgs = vec![
OptCfg::with(&[names(&["foo"])]),
OptCfg::with(&[names(&["bar"]), has_arg(true), is_array(true)]),
OptCfg::with([names(&["foo"])]),
OptCfg::with([names(&["bar"]), has_arg(true), is_array(true)]),
];

let mut cmd = Cmd::with_strings([
Expand Down
Loading