mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 06:42:33 +00:00
Merge #2030
2030: style: replacing yml with yaml for consistency r=pksunkara a=marcospb19 Co-authored-by: João Marcos <marcospb19@hotmail.com>
This commit is contained in:
commit
1d57aa2ffb
11 changed files with 38 additions and 37 deletions
|
@ -275,7 +275,7 @@ fn main() {
|
|||
This third method shows how you can use a YAML file to build your CLI and keep your Rust source tidy
|
||||
or support multiple localized translations by having different YAML files for each localization.
|
||||
|
||||
First, create the `cli.yml` file to hold your CLI options, but it could be called anything we like:
|
||||
First, create the `cli.yaml` file to hold your CLI options, but it could be called anything we like:
|
||||
|
||||
```yaml
|
||||
name: myapp
|
||||
|
@ -328,7 +328,7 @@ use clap::{App, load_yaml};
|
|||
|
||||
fn main() {
|
||||
// The YAML file is found relative to the current file, similar to how modules are found
|
||||
let yaml = load_yaml!("cli.yml");
|
||||
let yaml = load_yaml!("cli.yaml");
|
||||
let matches = App::from(yaml).get_matches();
|
||||
|
||||
// Same as previous examples...
|
||||
|
|
|
@ -133,7 +133,7 @@ Opt {
|
|||
|
||||
## clap_derive rustc version policy
|
||||
|
||||
- Minimum rustc version modification must be specified in the [changelog](https://github.com/clap-rs/clap_derive/blob/master/CHANGELOG.md) and in the [travis configuration](https://github.com/clap-rs/clap_derive/blob/master/.travis.yml).
|
||||
- Minimum rustc version modification must be specified in the [changelog](https://github.com/clap-rs/clap_derive/blob/master/CHANGELOG.md) and in the [travis configuration](https://github.com/clap-rs/clap_derive/blob/master/.travis.yaml).
|
||||
- Contributors can increment minimum rustc version without any justification if the new version is required by the latest version of one of clap_derive's depedencies (`cargo update` will not fail on clap_derive).
|
||||
- Contributors can increment minimum rustc version if the library user experience is improved.
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
fn main() {
|
||||
use clap::{load_yaml, App};
|
||||
|
||||
// To load a yaml file containing our CLI definition such as the example '17_yaml.yml' we can
|
||||
// To load a yaml file containing our CLI definition such as the example '17_yaml.yaml' we can
|
||||
// use the convenience macro which loads the file at compile relative to the current file
|
||||
// similar to how modules are found.
|
||||
//
|
||||
|
@ -26,10 +26,10 @@ fn main() {
|
|||
//
|
||||
// Finally we call get_matches() to start the parsing process. We use the matches just as we
|
||||
// normally would
|
||||
let yml = load_yaml!("17_yaml.yml");
|
||||
let m = App::from(yml).get_matches();
|
||||
let yaml = load_yaml!("17_yaml.yaml");
|
||||
let m = App::from(yaml).get_matches();
|
||||
|
||||
// Because the example 17_yaml.yml is rather large we'll just look a single arg so you can
|
||||
// Because the example 17_yaml.yaml is rather large we'll just look a single arg so you can
|
||||
// see that it works...
|
||||
if let Some(mode) = m.value_of("mode") {
|
||||
match mode {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: yml_app
|
||||
name: yaml_app
|
||||
version: "1.0"
|
||||
about: an example using a .yml file to build a CLI
|
||||
about: an example using a .yaml file to build a CLI
|
||||
author: Kevin K. <kbknapp@gmail.com>
|
||||
|
||||
# AppSettings can be defined as a list and are **not** ascii case sensitive
|
|
@ -388,8 +388,8 @@ impl<'b> App<'b> {
|
|||
/// # Examples
|
||||
/// ```ignore
|
||||
/// # use clap::{App, load_yaml};
|
||||
/// let yml = load_yaml!("app.yml");
|
||||
/// let app = App::from(yml)
|
||||
/// let yaml = load_yaml!("app.yaml");
|
||||
/// let app = App::from(yaml)
|
||||
/// .name(crate_name!());
|
||||
///
|
||||
/// // continued logic goes here, such as `app.get_matches()` etc.
|
||||
|
|
|
@ -4201,24 +4201,24 @@ impl<'a> Arg<'a> {
|
|||
|
||||
#[cfg(feature = "yaml")]
|
||||
impl<'a> From<&'a Yaml> for Arg<'a> {
|
||||
/// Creates a new instance of [`Arg`] from a .yml (YAML) file.
|
||||
/// Creates a new instance of [`Arg`] from a .yaml (YAML) file.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```ignore
|
||||
/// use clap::{Arg, load_yaml};
|
||||
/// let yml = load_yaml!("arg.yml");
|
||||
/// let arg = Arg::from(yml);
|
||||
/// let yaml = load_yaml!("arg.yaml");
|
||||
/// let arg = Arg::from(yaml);
|
||||
/// ```
|
||||
/// [`Arg`]: ./struct.Arg.html
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
fn from(y: &'a Yaml) -> Self {
|
||||
let y = y.as_hash().unwrap();
|
||||
// We WANT this to panic on error...so expect() is good.
|
||||
let name_yml = y.keys().next().unwrap();
|
||||
let name_str = name_yml.as_str().unwrap();
|
||||
let name_yaml = y.keys().next().unwrap();
|
||||
let name_str = name_yaml.as_str().unwrap();
|
||||
let mut a = Arg::new(name_str);
|
||||
let arg_settings = y.get(name_yml).unwrap().as_hash().unwrap();
|
||||
let arg_settings = y.get(name_yaml).unwrap().as_hash().unwrap();
|
||||
|
||||
for (k, v) in arg_settings.iter() {
|
||||
a = match k.as_str().unwrap() {
|
||||
|
|
|
@ -411,26 +411,26 @@ impl<'a, 'z> From<&'z ArgGroup<'a>> 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.
|
||||
/// Creates a new instance of `ArgGroup` from a .yaml (YAML) file.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```ignore
|
||||
/// # use clap::{ArgGroup, load_yaml};
|
||||
/// let yml = load_yaml!("group.yml");
|
||||
/// let ag = ArgGroup::from(yml);
|
||||
/// let yaml = load_yaml!("group.yaml");
|
||||
/// let ag = ArgGroup::from(yaml);
|
||||
/// ```
|
||||
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.
|
||||
let mut a = ArgGroup::default();
|
||||
let group_settings = if b.len() == 1 {
|
||||
let name_yml = b.keys().next().expect("failed to get name");
|
||||
let name_str = name_yml
|
||||
let name_yaml = b.keys().next().expect("failed to get name");
|
||||
let name_str = name_yaml
|
||||
.as_str()
|
||||
.expect("failed to convert arg YAML name to str");
|
||||
a.name = name_str;
|
||||
b.get(name_yml)
|
||||
b.get(name_yaml)
|
||||
.expect("failed to get name_str")
|
||||
.as_hash()
|
||||
.expect("failed to convert to a hash")
|
||||
|
@ -541,8 +541,8 @@ requires:
|
|||
- r2
|
||||
- r3
|
||||
- r4";
|
||||
let yml = &YamlLoader::load_from_str(g_yaml).expect("failed to load YAML file")[0];
|
||||
let g = ArgGroup::from(yml);
|
||||
let yaml = &YamlLoader::load_from_str(g_yaml).expect("failed to load YAML file")[0];
|
||||
let g = ArgGroup::from(yaml);
|
||||
let args = vec!["a1".into(), "a4".into(), "a2".into(), "a3".into()];
|
||||
let reqs = vec!["r1".into(), "r2".into(), "r3".into(), "r4".into()];
|
||||
let confs = vec!["c1".into(), "c2".into(), "c3".into(), "c4".into()];
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
/// # extern crate clap;
|
||||
/// # use clap::App;
|
||||
/// # fn main() {
|
||||
/// let yml = load_yaml!("app.yml");
|
||||
/// let app = App::from(yml);
|
||||
/// let yaml = load_yaml!("app.yaml");
|
||||
/// let app = App::from(yaml);
|
||||
///
|
||||
/// // continued logic goes here, such as `app.get_matches()` etc.
|
||||
/// # }
|
||||
|
@ -26,8 +26,9 @@
|
|||
#[cfg(feature = "yaml")]
|
||||
#[macro_export]
|
||||
macro_rules! load_yaml {
|
||||
($yml:expr) => {
|
||||
&$crate::YamlLoader::load_from_str(include_str!($yml)).expect("failed to load YAML file")[0]
|
||||
($yaml:expr) => {
|
||||
&$crate::YamlLoader::load_from_str(include_str!($yaml)).expect("failed to load YAML file")
|
||||
[0]
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -4,21 +4,21 @@ use clap::{load_yaml, App};
|
|||
|
||||
#[test]
|
||||
fn create_app_from_yaml() {
|
||||
let yml = load_yaml!("fixtures/app.yml");
|
||||
App::from(yml);
|
||||
let yaml = load_yaml!("fixtures/app.yaml");
|
||||
App::from(yaml);
|
||||
}
|
||||
|
||||
// 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!("fixtures/app_2space.yml");
|
||||
// App::from(yml);
|
||||
// let yaml = load_yaml!("fixtures/app_2space.yaml");
|
||||
// App::from(yaml);
|
||||
// }
|
||||
|
||||
#[test]
|
||||
fn help_message() {
|
||||
let yml = load_yaml!("fixtures/app.yml");
|
||||
let mut app = App::from(yml);
|
||||
let yaml = load_yaml!("fixtures/app.yaml");
|
||||
let mut app = App::from(yaml);
|
||||
// Generate the full help message!
|
||||
let _ = app.try_get_matches_from_mut(Vec::<String>::new());
|
||||
|
||||
|
@ -31,8 +31,8 @@ fn help_message() {
|
|||
|
||||
#[test]
|
||||
fn author() {
|
||||
let yml = load_yaml!("fixtures/app.yml");
|
||||
let mut app = App::from(yml);
|
||||
let yaml = load_yaml!("fixtures/app.yaml");
|
||||
let mut app = App::from(yaml);
|
||||
// Generate the full help message!
|
||||
let _ = app.try_get_matches_from_mut(Vec::<String>::new());
|
||||
|
||||
|
|
Loading…
Reference in a new issue