Skip to content

Commit 85aa49a

Browse files
authored
update!: changed paremeter type of OptCfg::with (#36)
1 parent 7ed95d1 commit 85aa49a

File tree

7 files changed

+181
-203
lines changed

7 files changed

+181
-203
lines changed

src/help/mod.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ mod tests_of_help {
817817
use crate::OptCfgParam::*;
818818

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

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

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

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

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

946946
help.add_opts_with_margins(
947-
&[OptCfg::with(&[
947+
&[OptCfg::with([
948948
names(&["foo-bar"]),
949949
desc(
950950
&("a".repeat(cols - 11 - 5 - 4) + " " + &"b".repeat(cols - 11 - 5 - 4) + "ccc"),
@@ -983,7 +983,7 @@ mod tests_of_help {
983983

984984
let mut help = Help::new();
985985
help.add_opts_with_indent(
986-
&[OptCfg::with(&[
986+
&[OptCfg::with([
987987
names(&["foo-bar"]),
988988
desc(&("a".repeat(cols - 12) + " " + &"b".repeat(cols - 12) + "ccc")),
989989
])],
@@ -1016,7 +1016,7 @@ mod tests_of_help {
10161016

10171017
let mut help = Help::new();
10181018
help.add_opts_with_indent(
1019-
&[OptCfg::with(&[
1019+
&[OptCfg::with([
10201020
names(&["foo-bar"]),
10211021
desc(&("a".repeat(cols))),
10221022
])],
@@ -1046,13 +1046,13 @@ mod tests_of_help {
10461046

10471047
let mut help = Help::new();
10481048
help.add_opts(&[
1049-
OptCfg::with(&[
1049+
OptCfg::with([
10501050
names(&["foo-bar", "f"]),
10511051
has_arg(true),
10521052
desc(&("a".repeat(cols - 22) + " " + &"b".repeat(cols - 22) + "ccc")),
10531053
arg_in_help("<text>"),
10541054
]),
1055-
OptCfg::with(&[
1055+
OptCfg::with([
10561056
names(&["baz", "b"]),
10571057
desc(&("d".repeat(cols - 22) + " " + &"e".repeat(cols - 22) + "fff")),
10581058
]),
@@ -1094,8 +1094,8 @@ mod tests_of_help {
10941094

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

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

11141114
let mut help = Help::new();
11151115
help.add_opts(&[
1116-
OptCfg::with(&[store_key("foo"), desc("description")]),
1117-
OptCfg::with(&[store_key("*"), desc("any option")]),
1116+
OptCfg::with([store_key("foo"), desc("description")]),
1117+
OptCfg::with([store_key("*"), desc("any option")]),
11181118
]);
11191119

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

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

11391139
let mut iter = help.iter();
@@ -1154,8 +1154,8 @@ mod tests_of_help {
11541154
let mut help = Help::new();
11551155
help.add_opts_with_indent(
11561156
&[
1157-
OptCfg::with(&[names(&["foo-bar"]), desc("description")]),
1158-
OptCfg::with(&[names(&["baz"]), desc("description")]),
1157+
OptCfg::with([names(&["foo-bar"]), desc("description")]),
1158+
OptCfg::with([names(&["baz"]), desc("description")]),
11591159
],
11601160
cols + 1,
11611161
);
@@ -1178,8 +1178,8 @@ mod tests_of_help {
11781178
let mut help = Help::new();
11791179
help.add_opts_with_margins(
11801180
&[
1181-
OptCfg::with(&[names(&["foo-bar"]), desc("description")]),
1182-
OptCfg::with(&[names(&["baz"]), desc("description")]),
1181+
OptCfg::with([names(&["foo-bar"]), desc("description")]),
1182+
OptCfg::with([names(&["baz"]), desc("description")]),
11831183
],
11841184
cols - 1,
11851185
1,
@@ -1200,8 +1200,8 @@ mod tests_of_help {
12001200

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

12071207
let mut iter = help.iter();

src/help/opts.rs

+16-19
Original file line numberDiff line numberDiff line change
@@ -203,52 +203,52 @@ mod tests_of_make_opt_title {
203203

204204
#[test]
205205
fn test_when_cfg_has_only_one_long_name() {
206-
let cfg = OptCfg::with(&[names(&["foo-bar"])]);
206+
let cfg = OptCfg::with([names(&["foo-bar"])]);
207207
let (indent, title) = make_opt_title(&cfg);
208208
assert_eq!(indent, 0);
209209
assert_eq!(title, "--foo-bar");
210210
}
211211

212212
#[test]
213213
fn test_when_cfg_has_only_one_short_name() {
214-
let cfg = OptCfg::with(&[names(&["f"])]);
214+
let cfg = OptCfg::with([names(&["f"])]);
215215
let (indent, title) = make_opt_title(&cfg);
216216
assert_eq!(indent, 0);
217217
assert_eq!(title, "-f");
218218
}
219219

220220
#[test]
221221
fn test_when_cfg_has_multiple_names() {
222-
let cfg = OptCfg::with(&[names(&["f", "b", "foo-bar"])]);
222+
let cfg = OptCfg::with([names(&["f", "b", "foo-bar"])]);
223223
let (indent, title) = make_opt_title(&cfg);
224224
assert_eq!(indent, 0);
225225
assert_eq!(title, "-f, -b, --foo-bar");
226226
}
227227

228228
#[test]
229229
fn test_when_cfg_has_no_name_but_store_key() {
230-
let cfg = OptCfg::with(&[store_key("Foo_Bar")]);
230+
let cfg = OptCfg::with([store_key("Foo_Bar")]);
231231
let (indent, title) = make_opt_title(&cfg);
232232
assert_eq!(indent, 0);
233233
assert_eq!(title, "--Foo_Bar");
234234
}
235235

236236
#[test]
237237
fn test_when_cfg_names_contain_emtpy_name() {
238-
let cfg = OptCfg::with(&[names(&["", "f"])]);
238+
let cfg = OptCfg::with([names(&["", "f"])]);
239239
let (indent, title) = make_opt_title(&cfg);
240240
assert_eq!(indent, 4);
241241
assert_eq!(title, "-f");
242242

243-
let cfg = OptCfg::with(&[names(&["", "f", "", "b", ""])]);
243+
let cfg = OptCfg::with([names(&["", "f", "", "b", ""])]);
244244
let (indent, title) = make_opt_title(&cfg);
245245
assert_eq!(indent, 4);
246246
assert_eq!(title, "-f, -b");
247247
}
248248

249249
#[test]
250250
fn test_when_cfg_names_are_all_empty_and_has_store_key() {
251-
let cfg = OptCfg::with(&[store_key("FooBar"), names(&["", ""])]);
251+
let cfg = OptCfg::with([store_key("FooBar"), names(&["", ""])]);
252252
let (indent, title) = make_opt_title(&cfg);
253253
assert_eq!(indent, 8);
254254
assert_eq!(title, "--FooBar");
@@ -262,7 +262,7 @@ mod tests_of_create_opts_help {
262262

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

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

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

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

312312
#[test]
313313
fn test_when_cfg_has_only_one_short_name() {
314-
let cfgs = vec![OptCfg::with(&[names(&["f"])])];
314+
let cfgs = vec![OptCfg::with([names(&["f"])])];
315315

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

326326
#[test]
327327
fn test_when_cfg_has_only_one_short_name_and_desc() {
328-
let cfgs = vec![OptCfg::with(&[
329-
names(&["f"]),
330-
desc("The description of f."),
331-
])];
328+
let cfgs = vec![OptCfg::with([names(&["f"]), desc("The description of f.")])];
332329

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

343340
#[test]
344341
fn test_when_cfg_has_only_one_short_name_and_desc_and_arg_in_help() {
345-
let cfgs = vec![OptCfg::with(&[
342+
let cfgs = vec![OptCfg::with([
346343
names(&["f"]),
347344
desc("The description of f."),
348345
arg_in_help("<n>"),
@@ -360,7 +357,7 @@ mod tests_of_create_opts_help {
360357

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

379376
#[test]
380377
fn test_when_indent_is_positive_and_shorter_than_title() {
381-
let cfgs = vec![OptCfg::with(&[
378+
let cfgs = vec![OptCfg::with([
382379
names(&["foo-bar"]),
383380
desc("The description of foo-bar."),
384381
arg_in_help("<num>"),
@@ -411,7 +408,7 @@ mod tests_of_create_opts_help {
411408

412409
#[test]
413410
fn test_when_names_contains_empty_strings() {
414-
let cfgs = vec![OptCfg::with(&[
411+
let cfgs = vec![OptCfg::with([
415412
names(&["", "", "f", "", "foo-bar", ""]),
416413
desc("The description of foo-bar."),
417414
arg_in_help("<num>"),

src/lib.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
//! If you want to prioritize the output of short option name first in the help
132132
//! text, like `-f, --foo-bar`, but use the long option name as the key in the
133133
//! option map, write `store_key` and `names` fields as follows:
134-
//! `OptCfg::with(&[store_key("foo-bar"), names(&["f", "foo-bar"])])`.
134+
//! `OptCfg::with([store_key("foo-bar"), names(&["f", "foo-bar"])])`.
135135
//!
136136
//! `has_arg` field indicates the option requires one or more values.
137137
//! `is_array` field indicates the option can have multiple values.
@@ -167,7 +167,7 @@
167167
//! arg_in_help: "<num>".to_string(),
168168
//! validator: validate_number::<u64>,
169169
//! },
170-
//! OptCfg::with(&[
170+
//! OptCfg::with([
171171
//! names(&["baz", "z"]),
172172
//! has_arg(true),
173173
//! defaults(&["1"]),
@@ -900,8 +900,8 @@ mod tests_of_cmd {
900900
}
901901

902902
let cfgs = vec![
903-
OptCfg::with(&[names(&["foo"])]),
904-
OptCfg::with(&[names(&["bar"]), has_arg(true), is_array(true)]),
903+
OptCfg::with([names(&["foo"])]),
904+
OptCfg::with([names(&["bar"]), has_arg(true), is_array(true)]),
905905
];
906906

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

930930
let mut cmd = Cmd::with_strings([
@@ -982,8 +982,8 @@ mod tests_of_cmd {
982982
fn should_move_by_mem_replace() {
983983
fn move_cmd() -> Cmd<'static> {
984984
let cfgs = vec![
985-
OptCfg::with(&[names(&["foo"])]),
986-
OptCfg::with(&[names(&["bar"]), has_arg(true), is_array(true)]),
985+
OptCfg::with([names(&["foo"])]),
986+
OptCfg::with([names(&["bar"]), has_arg(true), is_array(true)]),
987987
];
988988

989989
let mut cmd = Cmd::with_strings([
@@ -1044,8 +1044,8 @@ mod tests_of_cmd {
10441044
fn should_move_by_mem_swap() {
10451045
fn move_cmd() -> Cmd<'static> {
10461046
let cfgs = vec![
1047-
OptCfg::with(&[names(&["foo"])]),
1048-
OptCfg::with(&[names(&["bar"]), has_arg(true), is_array(true)]),
1047+
OptCfg::with([names(&["foo"])]),
1048+
OptCfg::with([names(&["bar"]), has_arg(true), is_array(true)]),
10491049
];
10501050

10511051
let mut cmd = Cmd::with_strings([

0 commit comments

Comments
 (0)