mirror of
https://github.com/clap-rs/clap
synced 2025-01-06 09:48:43 +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
|
// Std
|
||||||
use std::{ops::BitOr, str::FromStr};
|
use std::ops::BitOr;
|
||||||
|
#[cfg(feature = "yaml")]
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
// Third party
|
// Third party
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
|
@ -1158,11 +1160,12 @@ impl_settings! { AppSettings, AppFlags,
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::AppSettings;
|
|
||||||
|
|
||||||
#[allow(clippy::cognitive_complexity)]
|
#[allow(clippy::cognitive_complexity)]
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg(feature = "yaml")]
|
||||||
fn app_settings_fromstr() {
|
fn app_settings_fromstr() {
|
||||||
|
use super::AppSettings;
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"disablehelpflag".parse::<AppSettings>().unwrap(),
|
"disablehelpflag".parse::<AppSettings>().unwrap(),
|
||||||
AppSettings::DisableHelpFlag
|
AppSettings::DisableHelpFlag
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
// Std
|
// Std
|
||||||
use std::{ops::BitOr, str::FromStr};
|
use std::ops::BitOr;
|
||||||
|
#[cfg(feature = "yaml")]
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
// Third party
|
// Third party
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
|
@ -157,10 +159,11 @@ impl_settings! { ArgSettings, ArgFlags,
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
#[test]
|
||||||
|
#[cfg(feature = "yaml")]
|
||||||
|
fn arg_settings_fromstr() {
|
||||||
use super::ArgSettings;
|
use super::ArgSettings;
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn arg_settings_fromstr() {
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"allowhyphenvalues".parse::<ArgSettings>().unwrap(),
|
"allowhyphenvalues".parse::<ArgSettings>().unwrap(),
|
||||||
ArgSettings::AllowHyphenValues
|
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 {
|
impl FromStr for $settings {
|
||||||
type Err = String;
|
type Err = String;
|
||||||
fn from_str(s: &str) -> Result<Self, <Self as FromStr>::Err> {
|
fn from_str(s: &str) -> Result<Self, <Self as FromStr>::Err> {
|
||||||
|
|
Loading…
Reference in a new issue