fix!: Limit Setting FromStrs to YAML

These exist pretty much just for YAML (#3087).  If anyone else is
building on these, it has a limited shelf-life anyways because of #2717.

BREAKING CHANGE: `FromStr` for settings requires the `yaml` feature.
This commit is contained in:
Ed Page 2021-12-09 09:03:54 -06:00
parent 3dec7df14f
commit f16bdcc821
3 changed files with 14 additions and 6 deletions

View file

@ -1,5 +1,7 @@
// Std
use std::{ops::BitOr, str::FromStr};
use std::ops::BitOr;
#[cfg(feature = "yaml")]
use std::str::FromStr;
// Third party
use bitflags::bitflags;
@ -1158,11 +1160,12 @@ impl_settings! { AppSettings, AppFlags,
#[cfg(test)]
mod test {
use super::AppSettings;
#[allow(clippy::cognitive_complexity)]
#[test]
#[cfg(feature = "yaml")]
fn app_settings_fromstr() {
use super::AppSettings;
assert_eq!(
"disablehelpflag".parse::<AppSettings>().unwrap(),
AppSettings::DisableHelpFlag

View file

@ -1,5 +1,7 @@
// Std
use std::{ops::BitOr, str::FromStr};
use std::ops::BitOr;
#[cfg(feature = "yaml")]
use std::str::FromStr;
// Third party
use bitflags::bitflags;
@ -157,10 +159,11 @@ impl_settings! { ArgSettings, ArgFlags,
#[cfg(test)]
mod test {
use super::ArgSettings;
#[test]
#[cfg(feature = "yaml")]
fn arg_settings_fromstr() {
use super::ArgSettings;
assert_eq!(
"allowhyphenvalues".parse::<ArgSettings>().unwrap(),
ArgSettings::AllowHyphenValues

View file

@ -879,6 +879,8 @@ macro_rules! impl_settings {
}
}
/// Deprecated in [Issue #3087](https://github.com/clap-rs/clap/issues/3087), maybe [`clap::Parser`][crate::Parser] would fit your use case?
#[cfg(feature = "yaml")]
impl FromStr for $settings {
type Err = String;
fn from_str(s: &str) -> Result<Self, <Self as FromStr>::Err> {