fix!: Allow adding new enum variants

Without being a breaking change.

This seems minor enough that we can break this during the release
candidates.  For `ValueHint`, the completion scripts are 99% of who
should be `match`ing it.  `AppSettings` as undocumented variants that
people shouldn't use.

BREAKING CHANGE: `clap::{ValueHint, ErrorKind, AppSettings,
ArgSettings}` are now `non_exhaustive`.
This commit is contained in:
Ed Page 2021-12-13 12:07:52 -06:00
parent be223df828
commit 98a1c2e6c9
5 changed files with 7 additions and 0 deletions

View file

@ -396,6 +396,9 @@ fn value_completion(arg: &Arg) -> Option<String> {
ValueHint::Hostname => "_hosts", ValueHint::Hostname => "_hosts",
ValueHint::Url => "_urls", ValueHint::Url => "_urls",
ValueHint::EmailAddress => "_email_addresses", ValueHint::EmailAddress => "_email_addresses",
_ => {
return None;
}
} }
.to_string(), .to_string(),
) )

View file

@ -23,6 +23,7 @@ impl Default for AppFlags {
/// ///
/// [`App`]: crate::App /// [`App`]: crate::App
#[derive(Debug, PartialEq, Copy, Clone)] #[derive(Debug, PartialEq, Copy, Clone)]
#[non_exhaustive]
pub enum AppSettings { pub enum AppSettings {
/// Try not to fail on parse errors, like missing option values. /// Try not to fail on parse errors, like missing option values.
/// ///

View file

@ -25,6 +25,7 @@ impl Default for ArgFlags {
/// [`Arg::unset_setting`]: crate::Arg::unset_setting() /// [`Arg::unset_setting`]: crate::Arg::unset_setting()
/// [`Arg::is_set`]: crate::Arg::is_set() /// [`Arg::is_set`]: crate::Arg::is_set()
#[derive(Debug, PartialEq, Copy, Clone)] #[derive(Debug, PartialEq, Copy, Clone)]
#[non_exhaustive]
pub enum ArgSettings { pub enum ArgSettings {
/// Specifies that an arg must be used /// Specifies that an arg must be used
Required, Required,

View file

@ -25,6 +25,7 @@ use std::str::FromStr;
/// [^1]: fish completions currently only support named arguments (e.g. -o or --opt), not /// [^1]: fish completions currently only support named arguments (e.g. -o or --opt), not
/// positional arguments. /// positional arguments.
#[derive(Debug, PartialEq, Copy, Clone)] #[derive(Debug, PartialEq, Copy, Clone)]
#[non_exhaustive]
pub enum ValueHint { pub enum ValueHint {
/// Default value if hint is not specified. Follows shell default behavior, which is usually /// Default value if hint is not specified. Follows shell default behavior, which is usually
/// auto-completing filenames. /// auto-completing filenames.

View file

@ -24,6 +24,7 @@ pub type Result<T> = StdResult<T, Error>;
/// Command line argument parser kind of error /// Command line argument parser kind of error
#[derive(Debug, Copy, Clone, PartialEq)] #[derive(Debug, Copy, Clone, PartialEq)]
#[non_exhaustive]
pub enum ErrorKind { pub enum ErrorKind {
/// Occurs when an [`Arg`] has a set of possible values, /// Occurs when an [`Arg`] has a set of possible values,
/// and the user provides a value which isn't in that set. /// and the user provides a value which isn't in that set.