diff --git a/Cargo.toml b/Cargo.toml index cdcfd5b7..ae4719c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,7 +53,7 @@ unicode-width = "0.1.4" textwrap = "0.10.0" indexmap = "1.0.1" strsim = { version = "0.7.0", optional = true } -yaml-rust = { version = "0.3.5", optional = true } +yaml-rust = { version = "0.4", optional = true } clippy = { version = "~0.0.166", optional = true } atty = { version = "0.2.2", optional = true } vec_map = { version = "0.8", optional = true } diff --git a/src/build/app/mod.rs b/src/build/app/mod.rs index 59937121..5127c493 100644 --- a/src/build/app/mod.rs +++ b/src/build/app/mod.rs @@ -1792,7 +1792,7 @@ impl<'a, 'b> App<'a, 'b> { } /// **Deprecated:** Use - #[deprecated(since="2.30.0", note="Use serde instead. Will be removed in v3.0-beta")] + #[deprecated(since="2.30.0", note="Use App::from instead. Will be removed in v3.0-beta")] #[cfg(feature = "yaml")] pub fn from_yaml(yaml: &'a Yaml) -> App<'a, 'a> { App::from(yaml) } @@ -1951,7 +1951,7 @@ impl<'a, 'b> App<'a, 'b> { #[cfg(feature = "yaml")] impl<'a> From<&'a Yaml> for App<'a, 'a> { fn from(mut yaml: &'a Yaml) -> Self { - use args::SubCommand; + use parse::SubCommand; // We WANT this to panic on error...so expect() is good. let mut is_sc = None; let mut a = if let Some(name) = yaml["name"].as_str() { diff --git a/src/build/arg/mod.rs b/src/build/arg/mod.rs index 6020b925..b8e09b45 100644 --- a/src/build/arg/mod.rs +++ b/src/build/arg/mod.rs @@ -1,11 +1,7 @@ -#[macro_use] -mod macros; mod settings; pub use self::settings::{ArgFlags, ArgSettings}; // Std -#[cfg(feature = "yaml")] -use std::collections::BTreeMap; use std::rc::Rc; use std::borrow::Cow; use std::fmt::{self, Display, Formatter}; @@ -20,7 +16,7 @@ use std::str; // Third Party #[cfg(feature = "yaml")] -use yaml_rust::Yaml; +use yaml_rust; use util::VecMap; // Internal @@ -157,7 +153,7 @@ impl<'a, 'b> Arg<'a, 'b> { /// ``` /// [`Arg`]: ./struct.Arg.html #[cfg(feature = "yaml")] - pub fn from_yaml(y: &BTreeMap) -> Arg { + pub fn from_yaml(y: &yaml_rust::yaml::Hash) -> Arg { // We WANT this to panic on error...so expect() is good. let name_yml = y.keys().nth(0).unwrap(); let name_str = name_yml.as_str().unwrap(); diff --git a/src/build/arg_group/mod.rs b/src/build/arg_group.rs similarity index 98% rename from src/build/arg_group/mod.rs rename to src/build/arg_group.rs index 9f517fd4..38428f1f 100644 --- a/src/build/arg_group/mod.rs +++ b/src/build/arg_group.rs @@ -1,11 +1,9 @@ // Std -#[cfg(feature = "yaml")] -use std::collections::BTreeMap; use std::fmt::{Debug, Formatter, Result}; // Third Party #[cfg(feature = "yaml")] -use yaml_rust::Yaml; +use yaml_rust; /// `ArgGroup`s are a family of related [arguments] and way for you to express, "Any of these /// arguments". By placing arguments in a logical group, you can create easier requirement and @@ -131,7 +129,7 @@ impl<'a> ArgGroup<'a> { /// # } /// ``` #[cfg(feature = "yaml")] - pub fn from_yaml(y: &'a Yaml) -> ArgGroup<'a> { ArgGroup::from(y.as_hash().unwrap()) } + pub fn from_yaml(y: &'a yaml_rust::Yaml) -> ArgGroup<'a> { ArgGroup::from(y.as_hash().unwrap()) } /// Adds an [argument] to this group by name /// @@ -458,8 +456,8 @@ impl<'a, 'z> From<&'z ArgGroup<'a>> for ArgGroup<'a> { } #[cfg(feature = "yaml")] -impl<'a> From<&'a BTreeMap> for ArgGroup<'a> { - fn from(b: &'a BTreeMap) -> Self { +impl<'a> From<&'a yaml_rust::yaml::Hash> for ArgGroup<'a> { + fn from(b: &'a yaml_rust::yaml::Hash) -> Self { // We WANT this to panic on error...so expect() is good. let mut a = ArgGroup::default(); let group_settings = if b.len() == 1 { diff --git a/src/build/arg/macros.rs b/src/build/macros.rs similarity index 100% rename from src/build/arg/macros.rs rename to src/build/macros.rs diff --git a/src/build/mod.rs b/src/build/mod.rs index 6ad2fc04..1647d260 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -1,3 +1,6 @@ +#[macro_use] +mod macros; + pub mod app; pub mod arg; diff --git a/tests/app_2space.yml b/tests/app_2space.yml new file mode 100644 index 00000000..3413935e --- /dev/null +++ b/tests/app_2space.yml @@ -0,0 +1,13 @@ +name: claptests +version: "1.0" +about: tests clap library +author: Kevin K. +settings: + - ArgRequiredElseHelp +help_message: prints help with a nonstandard description +args: + - opt: + short: o + long: option + multiple: true + help: tests options \ No newline at end of file diff --git a/tests/yaml.rs b/tests/yaml.rs index fcd03514..0f497e17 100644 --- a/tests/yaml.rs +++ b/tests/yaml.rs @@ -11,6 +11,13 @@ fn create_app_from_yaml() { App::from_yaml(yml); } +// TODO: Uncomment to test yaml with 2 spaces https://github.com/chyh1990/yaml-rust/issues/101 +// #[test] +// fn create_app_from_yaml_2spaces() { +// let yml = load_yaml!("app_2space.yml"); +// App::from(yml); +// } + #[test] fn help_message() { let yml = load_yaml!("app.yml");