Skip to content

Commit

Permalink
Merge #2177
Browse files Browse the repository at this point in the history
2177: Add an assertion for positional args defining long or short r=pksunkara a=CastilloDel



Co-authored-by: CastilloDel <delcastillodelarosadaniel@gmail.com>
  • Loading branch information
bors[bot] and CastilloDel committed Oct 18, 2020
2 parents 1519ec8 + acd3293 commit 01027e4
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/build/arg/mod.rs
Expand Up @@ -1519,9 +1519,12 @@ impl<'help> Arg<'help> {
/// **NOTE:** The index refers to position according to **other positional argument**. It does
/// not define position in the argument list as a whole.
///
/// **NOTE:** If no [`Arg::short`], or [`Arg::long`] have been defined, you can optionally
/// leave off the `index` method, and the index will be assigned in order of evaluation.
/// Utilizing the `index` method allows for setting indexes out of order
/// **NOTE:** This is only meant to be used for positional arguments and shouldn't to be used
/// with [`Arg::short`] or [`Arg::long`]. If they are defined, they will be ignored.
///
/// **NOTE:** You can optionally leave off the `index` method, and the index will be
/// assigned in order of evaluation. Utilizing the `index` method allows for setting
/// indexes out of order
///
/// **NOTE:** When utilized with [`Arg::multiple(true)`], only the **last** positional argument
/// may be defined as multiple (i.e. with the highest index)
Expand Down Expand Up @@ -4368,6 +4371,14 @@ impl Arg<'_> {
)
}
}

if self.index.is_some() {
assert!(
self.short.is_none() && self.long.is_none(),
"Argument '{}' is a positional argument and can't have short or long name versions",
self.name
);
}
}
}

Expand Down

0 comments on commit 01027e4

Please sign in to comment.