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

Add an assertion for positional args defining long or short #2177

Merged
merged 1 commit into from Oct 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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