mirror of
https://github.com/clap-rs/clap
synced 2024-12-15 07:12:32 +00:00
Merge #1930
1930: Consistent From<Yaml> for ArgGroup r=CreepySkeleton a=pksunkara Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
This commit is contained in:
commit
097bec669b
3 changed files with 14 additions and 19 deletions
|
@ -2190,7 +2190,7 @@ impl<'a> From<&'a Yaml> for App<'a> {
|
||||||
}
|
}
|
||||||
if let Some(v) = yaml["groups"].as_vec() {
|
if let Some(v) = yaml["groups"].as_vec() {
|
||||||
for ag_yaml in v {
|
for ag_yaml in v {
|
||||||
a = a.group(ArgGroup::from(ag_yaml.as_hash().unwrap()));
|
a = a.group(ArgGroup::from(ag_yaml));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -414,22 +414,6 @@ impl<'a> Debug for ArgGroup<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "yaml")]
|
|
||||||
impl<'a> From<&'a Yaml> for ArgGroup<'a> {
|
|
||||||
/// Creates a new instance of `ArgGroup` from a .yml (YAML) file.
|
|
||||||
///
|
|
||||||
/// # Examples
|
|
||||||
///
|
|
||||||
/// ```ignore
|
|
||||||
/// # use clap::{ArgGroup, load_yaml};
|
|
||||||
/// let yml = load_yaml!("group.yml");
|
|
||||||
/// let ag = ArgGroup::from(yml);
|
|
||||||
/// ```
|
|
||||||
fn from(y: &'a Yaml) -> Self {
|
|
||||||
ArgGroup::from(y.as_hash().unwrap())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, 'z> From<&'z ArgGroup<'a>> for ArgGroup<'a> {
|
impl<'a, 'z> From<&'z ArgGroup<'a>> for ArgGroup<'a> {
|
||||||
fn from(g: &'z ArgGroup<'a>) -> Self {
|
fn from(g: &'z ArgGroup<'a>) -> Self {
|
||||||
ArgGroup {
|
ArgGroup {
|
||||||
|
@ -445,8 +429,18 @@ impl<'a, 'z> From<&'z ArgGroup<'a>> for ArgGroup<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "yaml")]
|
#[cfg(feature = "yaml")]
|
||||||
impl<'a> From<&'a yaml_rust::yaml::Hash> for ArgGroup<'a> {
|
impl<'a> From<&'a Yaml> for ArgGroup<'a> {
|
||||||
fn from(b: &'a yaml_rust::yaml::Hash) -> Self {
|
/// Creates a new instance of `ArgGroup` from a .yml (YAML) file.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```ignore
|
||||||
|
/// # use clap::{ArgGroup, load_yaml};
|
||||||
|
/// let yml = load_yaml!("group.yml");
|
||||||
|
/// let ag = ArgGroup::from(yml);
|
||||||
|
/// ```
|
||||||
|
fn from(y: &'a Yaml) -> Self {
|
||||||
|
let b = y.as_hash().expect("ArgGroup::from::<Yaml> expects a table");
|
||||||
// We WANT this to panic on error...so expect() is good.
|
// We WANT this to panic on error...so expect() is good.
|
||||||
let mut a = ArgGroup::default();
|
let mut a = ArgGroup::default();
|
||||||
let group_settings = if b.len() == 1 {
|
let group_settings = if b.len() == 1 {
|
||||||
|
|
|
@ -29,6 +29,7 @@ pub use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "yaml")]
|
#[cfg(feature = "yaml")]
|
||||||
|
#[cfg_attr(feature = "yaml", doc(hidden))]
|
||||||
pub use yaml_rust::YamlLoader;
|
pub use yaml_rust::YamlLoader;
|
||||||
|
|
||||||
#[cfg(feature = "derive")]
|
#[cfg(feature = "derive")]
|
||||||
|
|
Loading…
Reference in a new issue