Skip to content

Commit 86c3be8

Browse files
committed
imp(Usage Strings): displays a [--] when it may be helpful
1 parent 1160bd8 commit 86c3be8

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/app.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,14 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
12621262
&& !self.opts.is_empty() && self.opts.values().any(|a| !a.required) {
12631263
usage.push_str(" [OPTIONS]");
12641264
}
1265+
// places a '--' in the usage string if there are args and options
1266+
// supporting multiple values
1267+
if !self.positionals_idx.is_empty()
1268+
&& self.opts.values().any(|a| a.multiple )
1269+
&& !self.opts.values().any(|a| a.required)
1270+
&& self.subcommands.is_empty() {
1271+
usage.push_str(" [--]")
1272+
}
12651273
if !self.positionals_idx.is_empty() && self.positionals_idx.values()
12661274
.any(|a| !a.required) {
12671275
usage.push_str(" [ARGS]");
@@ -1322,16 +1330,6 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
13221330
longest_opt = ol;
13231331
}
13241332
}
1325-
// if longest_opt == 0 {
1326-
// for ol in self.opts
1327-
// .values()
1328-
// .filter(|ref o| o.short.is_some())
1329-
// // 3='...'
1330-
// // 4='- <>'
1331-
// .map(|ref a| a.to_string().len() + if a.long.is_some() { 4 } else { 0 }) {
1332-
// if ol > longest_opt {longest_opt = ol;}
1333-
// }
1334-
// }
13351333
let mut longest_pos = 0;
13361334
for pl in self.positionals_idx
13371335
.values()

0 commit comments

Comments
 (0)