From 8595357542fece0e7088956d40c42813d72bbb1c Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 6 Dec 2021 11:03:12 -0600 Subject: [PATCH 1/6] chore: Only error for warnings in CI This makes it easier for developers to iterate, not having to stop to write docs just to get things building. --- clap_generate/src/lib.rs | 2 +- clap_generate_fig/src/lib.rs | 2 +- src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clap_generate/src/lib.rs b/clap_generate/src/lib.rs index c1651973536..09b84b93dfb 100644 --- a/clap_generate/src/lib.rs +++ b/clap_generate/src/lib.rs @@ -8,7 +8,7 @@ #![doc(html_logo_url = "https://clap.rs/images/media/clap.png")] #![doc(html_root_url = "https://docs.rs/clap_generate/3.0.0-beta.5")] #![doc = include_str!("../README.md")] -#![deny(missing_docs, trivial_casts, unused_allocation, trivial_numeric_casts)] +#![warn(missing_docs, trivial_casts, unused_allocation, trivial_numeric_casts)] #![forbid(unsafe_code)] #![allow(clippy::needless_doctest_main)] diff --git a/clap_generate_fig/src/lib.rs b/clap_generate_fig/src/lib.rs index 01a4f125953..a50a6cd1549 100644 --- a/clap_generate_fig/src/lib.rs +++ b/clap_generate_fig/src/lib.rs @@ -7,7 +7,7 @@ #![doc(html_logo_url = "https://clap.rs/images/media/clap.png")] #![doc(html_root_url = "https://docs.rs/clap_generate_fig/3.0.0-beta.5")] -#![deny(missing_docs, trivial_casts, unused_allocation, trivial_numeric_casts)] +#![warn(missing_docs, trivial_casts, unused_allocation, trivial_numeric_casts)] #![forbid(unsafe_code)] #![allow(clippy::needless_doctest_main)] diff --git a/src/lib.rs b/src/lib.rs index 126f98f32a5..dacfa9e1607 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,7 @@ #![cfg_attr(feature = "doc", doc = include_str!("../README.md"))] //! #![crate_type = "lib"] -#![deny( +#![warn( missing_docs, missing_debug_implementations, missing_copy_implementations, From c23f9230d16a0f6f7d5392ff088fb7b55d32a300 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 6 Dec 2021 11:04:41 -0600 Subject: [PATCH 2/6] chore: Remove stale boiletplate --- clap_derive/src/lib.rs | 2 -- clap_generate/src/lib.rs | 2 -- clap_generate_fig/src/lib.rs | 2 -- src/lib.rs | 3 --- 4 files changed, 9 deletions(-) diff --git a/clap_derive/src/lib.rs b/clap_derive/src/lib.rs index 48ea2dcc007..ec873098776 100644 --- a/clap_derive/src/lib.rs +++ b/clap_derive/src/lib.rs @@ -12,8 +12,6 @@ // commit#ea76fa1b1b273e65e3b0b1046643715b49bec51f which is licensed under the // MIT/Apache 2.0 license. -#![doc(html_logo_url = "https://clap.rs/images/media/clap.png")] -#![doc(html_root_url = "https://docs.rs/clap_derive/3.0.0-beta.5")] #![doc = include_str!("../README.md")] #![forbid(unsafe_code)] diff --git a/clap_generate/src/lib.rs b/clap_generate/src/lib.rs index 09b84b93dfb..942c280eb1f 100644 --- a/clap_generate/src/lib.rs +++ b/clap_generate/src/lib.rs @@ -5,8 +5,6 @@ // See the [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT) files in this repository // for more information. -#![doc(html_logo_url = "https://clap.rs/images/media/clap.png")] -#![doc(html_root_url = "https://docs.rs/clap_generate/3.0.0-beta.5")] #![doc = include_str!("../README.md")] #![warn(missing_docs, trivial_casts, unused_allocation, trivial_numeric_casts)] #![forbid(unsafe_code)] diff --git a/clap_generate_fig/src/lib.rs b/clap_generate_fig/src/lib.rs index a50a6cd1549..f620c64661f 100644 --- a/clap_generate_fig/src/lib.rs +++ b/clap_generate_fig/src/lib.rs @@ -5,8 +5,6 @@ //! Generates [Fig](https://github.com/withfig/autocomplete) completions for [`clap`](https://github.com/clap-rs/clap) based CLIs -#![doc(html_logo_url = "https://clap.rs/images/media/clap.png")] -#![doc(html_root_url = "https://docs.rs/clap_generate_fig/3.0.0-beta.5")] #![warn(missing_docs, trivial_casts, unused_allocation, trivial_numeric_casts)] #![forbid(unsafe_code)] #![allow(clippy::needless_doctest_main)] diff --git a/src/lib.rs b/src/lib.rs index dacfa9e1607..fb85b041ca8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,11 +3,8 @@ // (see LICENSE or ) All files in the project carrying such // notice may not be copied, modified, or distributed except according to those terms. -#![doc(html_logo_url = "https://clap.rs/images/media/clap.png")] -#![doc(html_root_url = "https://docs.rs/clap/3.0.0-beta.5")] #![cfg_attr(feature = "doc", doc = include_str!("../README.md"))] //! -#![crate_type = "lib"] #![warn( missing_docs, missing_debug_implementations, From 1acc95ff555c652781b5699bd27eb18f225f9160 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 6 Dec 2021 11:06:34 -0600 Subject: [PATCH 3/6] docs: Make clap_derive reflect it not being user-facing --- clap_derive/README.md | 143 +----------------------------------------- 1 file changed, 1 insertion(+), 142 deletions(-) diff --git a/clap_derive/README.md b/clap_derive/README.md index 35c1fb9bea1..4857976be6e 100644 --- a/clap_derive/README.md +++ b/clap_derive/README.md @@ -1,147 +1,6 @@ # clap_derive -Parse command line argument by defining a struct. It combines [structopt](https://github.com/TeXitoi/structopt) and [clap](https://crates.io/crates/clap) into a single experience. This crate is used by clap, and not meant to be used directly by -consumers. - -## Documentation - -Find it on [Docs.rs](https://docs.rs/clap_derive). You can also check the [examples](https://github.com/clap-rs/clap/tree/master/clap_derive/examples) and the [changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md). - -## Example - -Add `clap` to your dependencies of your `Cargo.toml`: - -```toml -[dependencies] -clap = "3" -``` - -And then, in your rust file: -```rust,no_run -use std::path::PathBuf; -use clap::{Parser, ValueHint}; - -/// A basic example -#[derive(Parser, Debug)] -#[clap(name = "basic")] -struct Opt { - // A flag, true if used in the command line. Note doc comment will - // be used for the help message of the flag. The name of the - // argument will be, by default, based on the name of the field. - /// Activate debug mode - #[clap(short, long)] - debug: bool, - - // The number of occurrences of the `v/verbose` flag - /// Verbose mode (-v, -vv, -vvv, etc.) - #[clap(short, long, parse(from_occurrences))] - verbose: u8, - - /// Set speed - #[clap(short, long, default_value = "42")] - speed: f64, - - /// Output file - #[clap(short, long, parse(from_os_str), value_hint = ValueHint::FilePath)] - output: PathBuf, - - // the long option will be translated by default to kebab case, - // i.e. `--nb-cars`. - /// Number of cars - #[clap(short = 'c', long)] - nb_cars: Option, - - /// admin_level to consider - #[clap(short, long)] - level: Vec, - - /// Files to process - #[clap(name = "FILE", parse(from_os_str), value_hint = ValueHint::AnyPath)] - files: Vec, -} - -fn main() { - let opt = Opt::parse(); - println!("{:#?}", opt); -} -``` - -Using this example: -```bash -$ ./basic -error: The following required arguments were not provided: - --output - -USAGE: - basic --output --speed - -For more information try --help -$ ./basic --help -basic 0.3.0 -Guillaume Pinot , others -A basic example - -USAGE: - basic [OPTIONS] --output [--] [file]... - -ARGS: - ... Files to process - -OPTIONS: - -c, --nb-cars Number of cars - -d, --debug Activate debug mode - -h, --help Print help information - -l, --level ... admin_level to consider - -o, --output Output file - -s, --speed Set speed [default: 42] - -V, --version Print version information - -v, --verbose Verbose mode (-v, -vv, -vvv, etc.) - -ARGS: - ... Files to process -$ ./basic -o foo.txt -Opt { - debug: false, - verbose: 0, - speed: 42.0, - output: "foo.txt", - nb_cars: None, - level: [], - files: [], -} -$ ./basic -o foo.txt -dvvvs 1337 -l alice -l bob --nb-cars 4 bar.txt baz.txt -Opt { - debug: true, - verbose: 3, - speed: 1337.0, - output: "foo.txt", - nb_cars: Some( - 4, - ), - level: [ - "alice", - "bob", - ], - files: [ - "bar.txt", - "baz.txt", - ], -} -``` - -## 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.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 dependencies (`cargo update` will not fail on clap_derive). -- Contributors can increment minimum rustc version if the library user experience is improved. - -## Why - -I've (@TeXitoi) used [docopt](https://crates.io/crates/docopt) for a long time (pre rust 1.0). I really like the fact that you have a structure with the parsed argument: no need to convert `String` to `f64`, no useless `unwrap`. But on the other hand, I don't like to write by hand the usage string. That's like going back to the golden age of WYSIWYG editors. Field naming is also a bit artificial. - -Today, the new standard to read command line arguments in Rust is [clap](https://crates.io/crates/clap). This library is so feature full! But I think there is one downside: even if you can validate argument and expressing that an argument is required, you still need to transform something looking like a hashmap of string vectors to something useful for your application. - -Now, there is stable custom derive. Thus I can add to clap the automatic conversion that I miss. Here is the result. +Macro implementation for clap's derives. ## License From f3268b0a4cabc7c2b18b7e3415c5130c14a326f6 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 6 Dec 2021 11:07:11 -0600 Subject: [PATCH 4/6] chore: Remove clap dependency --- clap_derive/Cargo.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/clap_derive/Cargo.toml b/clap_derive/Cargo.toml index 0a17f290fd8..d1e85c6a2ae 100644 --- a/clap_derive/Cargo.toml +++ b/clap_derive/Cargo.toml @@ -38,9 +38,6 @@ proc-macro2 = "1.0.28" heck = "0.3.0" proc-macro-error = "1" -[dev-dependencies] -clap = { path = "../", default-features = false, features = ["std", "derive", "env"] } - [features] default = [] debug = [] From f517c0ede1f1c1158cce1851d8ac9fdc5a1d0bd7 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 6 Dec 2021 11:11:56 -0600 Subject: [PATCH 5/6] docs: Remove author fields --- Cargo.toml | 4 ---- README.md | 2 +- clap_derive/Cargo.toml | 4 ---- clap_generate/Cargo.toml | 4 ---- clap_generate_fig/Cargo.toml | 3 --- examples/demo.md | 2 +- examples/escaped_positional.md | 2 +- examples/escaped_positional_derive.md | 2 +- examples/tutorial_builder/README.md | 30 +++++++++++++-------------- examples/tutorial_derive/README.md | 28 ++++++++++++------------- tests/builder/app_from_crate.rs | 2 +- tests/builder/cargo.rs | 2 +- tests/derive/author_version_about.rs | 1 - 13 files changed, 35 insertions(+), 51 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 346da465fc8..909e5cf2302 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,10 +9,6 @@ members = [ name = "clap" version = "3.0.0-beta.5" description = "A simple to use, efficient, and full-featured Command Line Argument Parser" -authors = [ - "Kevin K. ", - "Clap Maintainers" -] repository = "https://github.com/clap-rs/clap" documentation = "https://docs.rs/clap/" homepage = "https://clap.rs/" diff --git a/README.md b/README.md index e49f69b5662..cdedda2561c 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ fn main() { $ demo --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser diff --git a/clap_derive/Cargo.toml b/clap_derive/Cargo.toml index d1e85c6a2ae..865c6e89a8d 100644 --- a/clap_derive/Cargo.toml +++ b/clap_derive/Cargo.toml @@ -2,10 +2,6 @@ name = "clap_derive" version = "3.0.0-beta.5" edition = "2018" -authors = [ - "Guillaume Pinot ", - "Clap Maintainers" -] include = [ "src/**/*", "Cargo.toml", diff --git a/clap_generate/Cargo.toml b/clap_generate/Cargo.toml index 328352a8e06..53248c19489 100644 --- a/clap_generate/Cargo.toml +++ b/clap_generate/Cargo.toml @@ -2,10 +2,6 @@ name = "clap_generate" version = "3.0.0-beta.5" edition = "2018" -authors = [ - "Kevin K. ", - "Clap Maintainers" -] include = [ "src/**/*", "Cargo.toml", diff --git a/clap_generate_fig/Cargo.toml b/clap_generate_fig/Cargo.toml index 51a4458dd0a..5287e6ffa74 100644 --- a/clap_generate_fig/Cargo.toml +++ b/clap_generate_fig/Cargo.toml @@ -2,9 +2,6 @@ name = "clap_generate_fig" version = "3.0.0-beta.5" edition = "2018" -authors = [ - "Clap Maintainers" -] include = [ "src/**/*", "Cargo.toml", diff --git a/examples/demo.md b/examples/demo.md index ac0cafe8a13..a517660eabd 100644 --- a/examples/demo.md +++ b/examples/demo.md @@ -5,7 +5,7 @@ Used to validate README.md's content $ demo --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser diff --git a/examples/escaped_positional.md b/examples/escaped_positional.md index 8d295ebb3ee..70d9ec2ed2e 100644 --- a/examples/escaped_positional.md +++ b/examples/escaped_positional.md @@ -7,7 +7,7 @@ Let's see what this looks like in the help: $ escaped_positional --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser diff --git a/examples/escaped_positional_derive.md b/examples/escaped_positional_derive.md index 599d20eaea9..1a2fdcf2b6d 100644 --- a/examples/escaped_positional_derive.md +++ b/examples/escaped_positional_derive.md @@ -7,7 +7,7 @@ Let's see what this looks like in the help: $ escaped_positional_derive --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser diff --git a/examples/tutorial_builder/README.md b/examples/tutorial_builder/README.md index b5d040f80e9..535c49012b2 100644 --- a/examples/tutorial_builder/README.md +++ b/examples/tutorial_builder/README.md @@ -26,7 +26,7 @@ You can create an application with several arguments using usage strings. $ 01_quick --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser @@ -93,7 +93,7 @@ file. **This requires the `cargo` feature flag.** $ 02_crate --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser @@ -118,7 +118,7 @@ all subcommands (`app.global_setting()`). $ 02_app_settings --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser @@ -146,7 +146,7 @@ Flags are switches that can be on/off: $ 03_01_flag_bool --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser @@ -178,7 +178,7 @@ Or counted. $ 03_01_flag_count --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser @@ -206,7 +206,7 @@ Flags can also accept a value. $ 03_02_option --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser @@ -240,7 +240,7 @@ Or you can have users specify values by their position on the command-line: $ 03_03_positional --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser @@ -271,7 +271,7 @@ $ 03_04_subcommands ? failed clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser @@ -288,7 +288,7 @@ SUBCOMMANDS: $ 03_04_subcommands help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser @@ -339,7 +339,7 @@ set `Arg::default_value`. $ 03_05_default_values --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser @@ -374,7 +374,7 @@ of the mistake, and what the possible valid values are $ 04_01_possible --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser @@ -409,7 +409,7 @@ When enabling the `derive` feature, you can use `ArgEnum` to take care of the bo $ 04_01_enum --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser @@ -446,7 +446,7 @@ More generally, you can validate and parse into any data type. $ 04_02_validate --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser @@ -485,7 +485,7 @@ each other. $ 04_03_relations --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser @@ -546,7 +546,7 @@ As a last resort, you can create custom errors with the basics of clap's formatt $ 04_04_custom --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser diff --git a/examples/tutorial_derive/README.md b/examples/tutorial_derive/README.md index a5168b0d9ec..71ffbb4bc8f 100644 --- a/examples/tutorial_derive/README.md +++ b/examples/tutorial_derive/README.md @@ -27,7 +27,7 @@ attributes. **This requires enabling the `derive` feature flag.** $ 01_quick_derive --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser @@ -93,7 +93,7 @@ You can use `app_from_crate!()` to fill these fields in from your `Cargo.toml` f $ 02_crate_derive --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser @@ -118,7 +118,7 @@ all subcommands (`app.global_setting()`). $ 02_app_settings_derive --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser @@ -146,7 +146,7 @@ Flags are switches that can be on/off: $ 03_01_flag_bool_derive --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser @@ -178,7 +178,7 @@ Or counted. $ 03_01_flag_count_derive --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser @@ -206,7 +206,7 @@ Flags can also accept a value. $ 03_02_option_derive --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser @@ -240,7 +240,7 @@ Or you can have users specify values by their position on the command-line: $ 03_03_positional_derive --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser @@ -271,7 +271,7 @@ $ 03_04_subcommands_derive ? failed clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser @@ -288,7 +288,7 @@ SUBCOMMANDS: $ 03_04_subcommands_derive help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser @@ -339,7 +339,7 @@ set `Arg::default_value`. $ 03_05_default_values_derive --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser @@ -374,7 +374,7 @@ of the mistake, and what the possible valid values are $ 04_01_enum_derive --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser @@ -411,7 +411,7 @@ More generally, you can validate and parse into any data type. $ 04_02_validate_derive --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser @@ -450,7 +450,7 @@ each other. $ 04_03_relations_derive --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser @@ -511,7 +511,7 @@ As a last resort, you can create custom errors with the basics of clap's formatt $ 04_04_custom_derive --help clap [..] -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser diff --git a/tests/builder/app_from_crate.rs b/tests/builder/app_from_crate.rs index 51a1a96a711..9494aecff83 100644 --- a/tests/builder/app_from_crate.rs +++ b/tests/builder/app_from_crate.rs @@ -4,7 +4,7 @@ use clap::{app_from_crate, ErrorKind}; static EVERYTHING: &str = "clap {{version}} -Kevin K. , Clap Maintainers + A simple to use, efficient, and full-featured Command Line Argument Parser diff --git a/tests/builder/cargo.rs b/tests/builder/cargo.rs index 79c42990111..c0b86d9fe3c 100644 --- a/tests/builder/cargo.rs +++ b/tests/builder/cargo.rs @@ -16,7 +16,7 @@ OPTIONS: static AUTHORS_ONLY: &str = "prog 1 -Kevin K. :Clap Maintainers + USAGE: prog diff --git a/tests/derive/author_version_about.rs b/tests/derive/author_version_about.rs index c1bb5a064ec..388697d5077 100644 --- a/tests/derive/author_version_about.rs +++ b/tests/derive/author_version_about.rs @@ -34,7 +34,6 @@ fn use_env() { let output = utils::get_long_help::(); assert!(output.starts_with("clap")); - assert!(output.contains("Kevin K. , Clap Maintainers")); assert!(output .contains("A simple to use, efficient, and full-featured Command Line Argument Parser")); } From b2836c07a7a02872e1933b2bd3463a5ad5bcf67f Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 6 Dec 2021 11:29:07 -0600 Subject: [PATCH 6/6] fix: Gracefully handle empty authors --- CHANGELOG.md | 2 ++ clap_derive/src/attrs.rs | 23 ++++++++++----- examples/demo.md | 2 -- examples/escaped_positional.md | 2 -- examples/escaped_positional_derive.md | 2 -- examples/tutorial_builder/README.md | 30 ------------------- examples/tutorial_derive/README.md | 28 ------------------ src/macros.rs | 42 +++++++++++++++++++-------- tests/builder/app_from_crate.rs | 2 -- 9 files changed, 47 insertions(+), 86 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa96b910727..d9330022032 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -267,11 +267,13 @@ On top of the clap 2 changes - `IgnoreCase` is now unicode aware (requires `unicode` feature flag) - Always respect `ColorChoice::Never`, even if that means we skip colors in some cases - `ArgMatches` panics on unknown arguments +- Gracefully handle empty `authors` field in `Cargo.toml` with `app_from_crate` **From structopt 0.3.25** - Support `SubcommandsNegateReqs` by allowing required `Option<_>`s ([clap-rs/clap#2255](https://github.com/clap-rs/clap/issues/2255)) - Infer `AllowInvalidUtf8` based on parser ([clap-rs/clap#751](https://github.com/clap-rs/clap/issues/2255)) +- Gracefully handle empty `authors` field in `Cargo.toml` On top of the clap 2 changes diff --git a/clap_derive/src/attrs.rs b/clap_derive/src/attrs.rs index 00bd2b11510..700244c951a 100644 --- a/clap_derive/src/attrs.rs +++ b/clap_derive/src/attrs.rs @@ -483,17 +483,19 @@ impl Attrs { } About(ident, about) => { - let method = Method::from_lit_or_env(ident, about, "CARGO_PKG_DESCRIPTION"); - self.methods.push(method); + if let Some(method) = + Method::from_lit_or_env(ident, about, "CARGO_PKG_DESCRIPTION") + { + self.methods.push(method); + } } Author(ident, author) => { - self.author = Some(Method::from_lit_or_env(ident, author, "CARGO_PKG_AUTHORS")); + self.author = Method::from_lit_or_env(ident, author, "CARGO_PKG_AUTHORS"); } Version(ident, version) => { - self.version = - Some(Method::from_lit_or_env(ident, version, "CARGO_PKG_VERSION")); + self.version = Method::from_lit_or_env(ident, version, "CARGO_PKG_VERSION"); } NameLitStr(name, lit) => { @@ -675,12 +677,17 @@ impl Method { Method { name, args } } - fn from_lit_or_env(ident: Ident, lit: Option, env_var: &str) -> Self { + fn from_lit_or_env(ident: Ident, lit: Option, env_var: &str) -> Option { let mut lit = match lit { Some(lit) => lit, None => match env::var(env_var) { - Ok(val) => LitStr::new(&val, ident.span()), + Ok(val) => { + if val.is_empty() { + return None; + } + LitStr::new(&val, ident.span()) + } Err(_) => { abort!(ident, "cannot derive `{}` from Cargo.toml", ident; @@ -696,7 +703,7 @@ impl Method { lit = LitStr::new(&edited, lit.span()); } - Method::new(ident, quote!(#lit)) + Some(Method::new(ident, quote!(#lit))) } } diff --git a/examples/demo.md b/examples/demo.md index a517660eabd..df7948df013 100644 --- a/examples/demo.md +++ b/examples/demo.md @@ -5,8 +5,6 @@ Used to validate README.md's content $ demo --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: diff --git a/examples/escaped_positional.md b/examples/escaped_positional.md index 70d9ec2ed2e..9e22dbc825e 100644 --- a/examples/escaped_positional.md +++ b/examples/escaped_positional.md @@ -7,8 +7,6 @@ Let's see what this looks like in the help: $ escaped_positional --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: diff --git a/examples/escaped_positional_derive.md b/examples/escaped_positional_derive.md index 1a2fdcf2b6d..41278144c1b 100644 --- a/examples/escaped_positional_derive.md +++ b/examples/escaped_positional_derive.md @@ -7,8 +7,6 @@ Let's see what this looks like in the help: $ escaped_positional_derive --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: diff --git a/examples/tutorial_builder/README.md b/examples/tutorial_builder/README.md index 535c49012b2..7e61d13680c 100644 --- a/examples/tutorial_builder/README.md +++ b/examples/tutorial_builder/README.md @@ -26,8 +26,6 @@ You can create an application with several arguments using usage strings. $ 01_quick --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: @@ -93,8 +91,6 @@ file. **This requires the `cargo` feature flag.** $ 02_crate --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: @@ -118,8 +114,6 @@ all subcommands (`app.global_setting()`). $ 02_app_settings --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: @@ -146,8 +140,6 @@ Flags are switches that can be on/off: $ 03_01_flag_bool --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: @@ -178,8 +170,6 @@ Or counted. $ 03_01_flag_count --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: @@ -206,8 +196,6 @@ Flags can also accept a value. $ 03_02_option --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: @@ -240,8 +228,6 @@ Or you can have users specify values by their position on the command-line: $ 03_03_positional --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: @@ -271,8 +257,6 @@ $ 03_04_subcommands ? failed clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: @@ -288,8 +272,6 @@ SUBCOMMANDS: $ 03_04_subcommands help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: @@ -339,8 +321,6 @@ set `Arg::default_value`. $ 03_05_default_values --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: @@ -374,8 +354,6 @@ of the mistake, and what the possible valid values are $ 04_01_possible --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: @@ -409,8 +387,6 @@ When enabling the `derive` feature, you can use `ArgEnum` to take care of the bo $ 04_01_enum --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: @@ -446,8 +422,6 @@ More generally, you can validate and parse into any data type. $ 04_02_validate --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: @@ -485,8 +459,6 @@ each other. $ 04_03_relations --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: @@ -546,8 +518,6 @@ As a last resort, you can create custom errors with the basics of clap's formatt $ 04_04_custom --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: diff --git a/examples/tutorial_derive/README.md b/examples/tutorial_derive/README.md index 71ffbb4bc8f..6d27fe47367 100644 --- a/examples/tutorial_derive/README.md +++ b/examples/tutorial_derive/README.md @@ -27,8 +27,6 @@ attributes. **This requires enabling the `derive` feature flag.** $ 01_quick_derive --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: @@ -93,8 +91,6 @@ You can use `app_from_crate!()` to fill these fields in from your `Cargo.toml` f $ 02_crate_derive --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: @@ -118,8 +114,6 @@ all subcommands (`app.global_setting()`). $ 02_app_settings_derive --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: @@ -146,8 +140,6 @@ Flags are switches that can be on/off: $ 03_01_flag_bool_derive --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: @@ -178,8 +170,6 @@ Or counted. $ 03_01_flag_count_derive --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: @@ -206,8 +196,6 @@ Flags can also accept a value. $ 03_02_option_derive --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: @@ -240,8 +228,6 @@ Or you can have users specify values by their position on the command-line: $ 03_03_positional_derive --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: @@ -271,8 +257,6 @@ $ 03_04_subcommands_derive ? failed clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: @@ -288,8 +272,6 @@ SUBCOMMANDS: $ 03_04_subcommands_derive help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: @@ -339,8 +321,6 @@ set `Arg::default_value`. $ 03_05_default_values_derive --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: @@ -374,8 +354,6 @@ of the mistake, and what the possible valid values are $ 04_01_enum_derive --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: @@ -411,8 +389,6 @@ More generally, you can validate and parse into any data type. $ 04_02_validate_derive --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: @@ -450,8 +426,6 @@ each other. $ 04_03_relations_derive --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: @@ -511,8 +485,6 @@ As a last resort, you can create custom errors with the basics of clap's formatt $ 04_04_custom_derive --help clap [..] - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: diff --git a/src/macros.rs b/src/macros.rs index 11c1af683d2..7d2d6e2f468 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -301,18 +301,36 @@ macro_rules! crate_name { #[cfg(feature = "cargo")] #[macro_export] macro_rules! app_from_crate { - () => { - $crate::App::new($crate::crate_name!()) - .version($crate::crate_version!()) - .author($crate::crate_authors!(", ")) - .about($crate::crate_description!()) - }; - ($sep:expr) => { - $crate::App::new($crate::crate_name!()) - .version($crate::crate_version!()) - .author($crate::crate_authors!($sep)) - .about($crate::crate_description!()) - }; + () => {{ + let mut app = $crate::App::new($crate::crate_name!()).version($crate::crate_version!()); + + let author = $crate::crate_authors!(", "); + if !author.is_empty() { + app = app.author(author) + } + + let about = $crate::crate_description!(); + if !about.is_empty() { + app = app.about(about) + } + + app + }}; + ($sep:expr) => {{ + let mut app = $crate::App::new($crate::crate_name!()).version($crate::crate_version!()); + + let author = $crate::crate_authors!($sep); + if !author.is_empty() { + app = app.author(author) + } + + let about = $crate::crate_description!(); + if !about.is_empty() { + app = app.about(about) + } + + app + }}; } #[doc(hidden)] diff --git a/tests/builder/app_from_crate.rs b/tests/builder/app_from_crate.rs index 9494aecff83..156a0278e29 100644 --- a/tests/builder/app_from_crate.rs +++ b/tests/builder/app_from_crate.rs @@ -4,8 +4,6 @@ use clap::{app_from_crate, ErrorKind}; static EVERYTHING: &str = "clap {{version}} - - A simple to use, efficient, and full-featured Command Line Argument Parser USAGE: