Skip to content

Commit

Permalink
fix!: Limit Setting FromStrs to YAML
Browse files Browse the repository at this point in the history
These exist pretty much just for YAML (clap-rs#3087).  If anyone else is
building on these, it has a limited shelf-life anyways because of clap-rs#2717.

BREAKING CHANGE: `FromStr` for settings requires the `yaml` feature.
  • Loading branch information
epage committed Dec 9, 2021
1 parent 3dec7df commit f16bdcc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/build/app/settings.rs
@@ -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;
Expand Down Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions src/build/arg/settings.rs
@@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/macros.rs
Expand Up @@ -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> {
Expand Down

0 comments on commit f16bdcc

Please sign in to comment.