mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52:33 +00:00
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:
parent
3dec7df14f
commit
f16bdcc821
3 changed files with 14 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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> {
|
||||
|
|
Loading…
Reference in a new issue