From 98a1c2e6c9e579ff5b094f995ffe6f5deac73708 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 13 Dec 2021 12:07:52 -0600 Subject: [PATCH] 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`. --- clap_generate/src/generators/shells/zsh.rs | 3 +++ src/build/app/settings.rs | 1 + src/build/arg/settings.rs | 1 + src/build/arg/value_hint.rs | 1 + src/parse/errors.rs | 1 + 5 files changed, 7 insertions(+) diff --git a/clap_generate/src/generators/shells/zsh.rs b/clap_generate/src/generators/shells/zsh.rs index db62ab08..c2f9fb45 100644 --- a/clap_generate/src/generators/shells/zsh.rs +++ b/clap_generate/src/generators/shells/zsh.rs @@ -396,6 +396,9 @@ fn value_completion(arg: &Arg) -> Option { ValueHint::Hostname => "_hosts", ValueHint::Url => "_urls", ValueHint::EmailAddress => "_email_addresses", + _ => { + return None; + } } .to_string(), ) diff --git a/src/build/app/settings.rs b/src/build/app/settings.rs index d9ae9fb1..f166795e 100644 --- a/src/build/app/settings.rs +++ b/src/build/app/settings.rs @@ -23,6 +23,7 @@ impl Default for AppFlags { /// /// [`App`]: crate::App #[derive(Debug, PartialEq, Copy, Clone)] +#[non_exhaustive] pub enum AppSettings { /// Try not to fail on parse errors, like missing option values. /// diff --git a/src/build/arg/settings.rs b/src/build/arg/settings.rs index f6d45859..d44ce378 100644 --- a/src/build/arg/settings.rs +++ b/src/build/arg/settings.rs @@ -25,6 +25,7 @@ impl Default for ArgFlags { /// [`Arg::unset_setting`]: crate::Arg::unset_setting() /// [`Arg::is_set`]: crate::Arg::is_set() #[derive(Debug, PartialEq, Copy, Clone)] +#[non_exhaustive] pub enum ArgSettings { /// Specifies that an arg must be used Required, diff --git a/src/build/arg/value_hint.rs b/src/build/arg/value_hint.rs index 5a3bf40d..45109d2d 100644 --- a/src/build/arg/value_hint.rs +++ b/src/build/arg/value_hint.rs @@ -25,6 +25,7 @@ use std::str::FromStr; /// [^1]: fish completions currently only support named arguments (e.g. -o or --opt), not /// positional arguments. #[derive(Debug, PartialEq, Copy, Clone)] +#[non_exhaustive] pub enum ValueHint { /// Default value if hint is not specified. Follows shell default behavior, which is usually /// auto-completing filenames. diff --git a/src/parse/errors.rs b/src/parse/errors.rs index e5b607be..e2e3c0b4 100644 --- a/src/parse/errors.rs +++ b/src/parse/errors.rs @@ -24,6 +24,7 @@ pub type Result = StdResult; /// Command line argument parser kind of error #[derive(Debug, Copy, Clone, PartialEq)] +#[non_exhaustive] pub enum ErrorKind { /// Occurs when an [`Arg`] has a set of possible values, /// and the user provides a value which isn't in that set.