mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52:33 +00:00
Merge pull request #1300 from kbknapp/update-yaml-rust
Update yaml rust
This commit is contained in:
commit
714b8a5df8
8 changed files with 32 additions and 15 deletions
|
@ -53,7 +53,7 @@ unicode-width = "0.1.4"
|
||||||
textwrap = "0.10.0"
|
textwrap = "0.10.0"
|
||||||
indexmap = "1.0.1"
|
indexmap = "1.0.1"
|
||||||
strsim = { version = "0.7.0", optional = true }
|
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 }
|
clippy = { version = "~0.0.166", optional = true }
|
||||||
atty = { version = "0.2.2", optional = true }
|
atty = { version = "0.2.2", optional = true }
|
||||||
vec_map = { version = "0.8", optional = true }
|
vec_map = { version = "0.8", optional = true }
|
||||||
|
|
|
@ -1792,7 +1792,7 @@ impl<'a, 'b> App<'a, 'b> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// **Deprecated:** Use
|
/// **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")]
|
#[cfg(feature = "yaml")]
|
||||||
pub fn from_yaml(yaml: &'a Yaml) -> App<'a, 'a> { App::from(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")]
|
#[cfg(feature = "yaml")]
|
||||||
impl<'a> From<&'a Yaml> for App<'a, 'a> {
|
impl<'a> From<&'a Yaml> for App<'a, 'a> {
|
||||||
fn from(mut yaml: &'a Yaml) -> Self {
|
fn from(mut yaml: &'a Yaml) -> Self {
|
||||||
use args::SubCommand;
|
use parse::SubCommand;
|
||||||
// We WANT this to panic on error...so expect() is good.
|
// We WANT this to panic on error...so expect() is good.
|
||||||
let mut is_sc = None;
|
let mut is_sc = None;
|
||||||
let mut a = if let Some(name) = yaml["name"].as_str() {
|
let mut a = if let Some(name) = yaml["name"].as_str() {
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
#[macro_use]
|
|
||||||
mod macros;
|
|
||||||
mod settings;
|
mod settings;
|
||||||
pub use self::settings::{ArgFlags, ArgSettings};
|
pub use self::settings::{ArgFlags, ArgSettings};
|
||||||
|
|
||||||
// Std
|
// Std
|
||||||
#[cfg(feature = "yaml")]
|
|
||||||
use std::collections::BTreeMap;
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::fmt::{self, Display, Formatter};
|
use std::fmt::{self, Display, Formatter};
|
||||||
|
@ -20,7 +16,7 @@ use std::str;
|
||||||
|
|
||||||
// Third Party
|
// Third Party
|
||||||
#[cfg(feature = "yaml")]
|
#[cfg(feature = "yaml")]
|
||||||
use yaml_rust::Yaml;
|
use yaml_rust;
|
||||||
use util::VecMap;
|
use util::VecMap;
|
||||||
|
|
||||||
// Internal
|
// Internal
|
||||||
|
@ -157,7 +153,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
||||||
/// ```
|
/// ```
|
||||||
/// [`Arg`]: ./struct.Arg.html
|
/// [`Arg`]: ./struct.Arg.html
|
||||||
#[cfg(feature = "yaml")]
|
#[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.
|
// We WANT this to panic on error...so expect() is good.
|
||||||
let name_yml = y.keys().nth(0).unwrap();
|
let name_yml = y.keys().nth(0).unwrap();
|
||||||
let name_str = name_yml.as_str().unwrap();
|
let name_str = name_yml.as_str().unwrap();
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
// Std
|
// Std
|
||||||
#[cfg(feature = "yaml")]
|
|
||||||
use std::collections::BTreeMap;
|
|
||||||
use std::fmt::{Debug, Formatter, Result};
|
use std::fmt::{Debug, Formatter, Result};
|
||||||
|
|
||||||
// Third Party
|
// Third Party
|
||||||
#[cfg(feature = "yaml")]
|
#[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
|
/// `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
|
/// 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")]
|
#[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
|
/// 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")]
|
#[cfg(feature = "yaml")]
|
||||||
impl<'a> From<&'a BTreeMap<Yaml, Yaml>> for ArgGroup<'a> {
|
impl<'a> From<&'a yaml_rust::yaml::Hash> for ArgGroup<'a> {
|
||||||
fn from(b: &'a BTreeMap<Yaml, Yaml>) -> Self {
|
fn from(b: &'a yaml_rust::yaml::Hash) -> Self {
|
||||||
// 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 {
|
|
@ -1,3 +1,6 @@
|
||||||
|
#[macro_use]
|
||||||
|
mod macros;
|
||||||
|
|
||||||
pub mod app;
|
pub mod app;
|
||||||
pub mod arg;
|
pub mod arg;
|
||||||
|
|
||||||
|
|
13
tests/app_2space.yml
Normal file
13
tests/app_2space.yml
Normal 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
|
|
@ -11,6 +11,13 @@ fn create_app_from_yaml() {
|
||||||
App::from_yaml(yml);
|
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]
|
#[test]
|
||||||
fn help_message() {
|
fn help_message() {
|
||||||
let yml = load_yaml!("app.yml");
|
let yml = load_yaml!("app.yml");
|
||||||
|
|
Loading…
Reference in a new issue