Merge pull request #1300 from kbknapp/update-yaml-rust

Update yaml rust
This commit is contained in:
Alan K 2018-06-22 12:54:09 +01:00 committed by GitHub
commit 714b8a5df8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 32 additions and 15 deletions

View file

@ -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 }

View file

@ -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() {

View file

@ -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<Yaml, Yaml>) -> 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();

View file

@ -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<Yaml, Yaml>> for ArgGroup<'a> {
fn from(b: &'a BTreeMap<Yaml, Yaml>) -> 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 {

View file

@ -1,3 +1,6 @@
#[macro_use]
mod macros;
pub mod app;
pub mod arg;

13
tests/app_2space.yml Normal file
View file

@ -0,0 +1,13 @@
name: claptests
version: "1.0"
about: tests clap library
author: Kevin K. <kbknapp@gmail.com>
settings:
- ArgRequiredElseHelp
help_message: prints help with a nonstandard description
args:
- opt:
short: o
long: option
multiple: true
help: tests options

View file

@ -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");