@@ -1338,10 +1338,6 @@ fn flag_arm(cli: &Cli, i: usize, field: &Field) -> TokenStream { |
1338 | 1338 | } |
1339 | 1339 | } |
1340 | 1340 |
|
1341 | | -/// Whether another occurrence is a command-line mistake rather than another value. |
1342 | | -/// |
1343 | | -/// Counts and collections repeat by definition, and `var` explicitly opts a value-taking flag |
1344 | | -/// into repetition. Every other flag matches clap's default of one occurrence. |
1345 | 1341 | /// Whether a repeat of this flag is only a duplicate *within one command*. |
1346 | 1342 | /// |
1347 | 1343 | /// A `global` flag is in scope for every descendant, and clap lets it be given again on a |
@@ -1365,6 +1361,26 @@ fn reset_per_level(cli: &Cli) -> TokenStream { |
1365 | 1361 | quote!(#(#resets)*) |
1366 | 1362 | } |
1367 | 1363 |
|
| 1364 | +/// Whether another occurrence is a command-line mistake rather than another value. |
| 1365 | +/// |
| 1366 | +/// Counts and collections repeat by definition, and `var` explicitly opts a value-taking flag |
| 1367 | +/// into repetition. Every other flag matches clap's default of one occurrence. |
| 1368 | +/// |
| 1369 | +/// **This is stricter than the grammar, deliberately.** The corpus specifies the opposite for a |
| 1370 | +/// *spec-driven* parse — `long-repeated-keeps-the-last` says "a repeat is a correction, typically |
| 1371 | +/// a wrapper appending to a command line it did not write" — and usage-argv's parser and |
| 1372 | +/// usage-lib both honour that. The rule lives here, in the derive's post-binding layer, and |
| 1373 | +/// nowhere else: `Error::DuplicateFlag` is constructed at one call site, in this file. |
| 1374 | +/// |
| 1375 | +/// Kept, because the two cases are not the same case. A spec parsed at run time may well be |
| 1376 | +/// describing someone else's command line, which is the wrapper the corpus has in mind. A |
| 1377 | +/// derived CLI is an authored, fixed surface, where `--jobs 1 --jobs 2` is far likelier to be a |
| 1378 | +/// mistake than an amendment — and it is what clap does, so an adopter replacing clap sees no |
| 1379 | +/// change. Dropping it would make a derived binary quietly accept a line clap rejects today, |
| 1380 | +/// which is the direction that costs an adopter rather than the one that helps. |
| 1381 | +/// |
| 1382 | +/// Recorded because it looks like an inconsistency and is not one. `differential.rs` in the gate |
| 1383 | +/// carries the same note from the other end. |
1368 | 1384 | fn rejects_duplicate(field: &Field) -> bool { |
1369 | 1385 | matches!(field.kind, Kind::Flag { .. }) |
1370 | 1386 | && !matches!(field.shape, Shape::Count | Shape::Many) |
|