diff options
author | Haibo Huang <hhb@google.com> | 2020-09-23 21:23:42 -0700 |
---|---|---|
committer | Haibo Huang <hhb@google.com> | 2020-09-23 21:23:42 -0700 |
commit | e7bfadf396e6d7aca36ef17424eae852404775d6 (patch) | |
tree | 254d00e0918f220a2662ca8f65ed510bd2220eba | |
parent | 67fbbcc40fbcbcb1d18c74f7e1edcffb33d79b58 (diff) | |
download | structopt-e7bfadf396e6d7aca36ef17424eae852404775d6.tar.gz |
Upgrade rust/crates/structopt to 0.3.18
Test: make
Change-Id: Ib5d515b0f5e9ac7fdd0f2f8e2f00ecf54dbf63ca
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 15 | ||||
-rw-r--r-- | CHANGELOG.md | 24 | ||||
-rw-r--r-- | Cargo.toml | 13 | ||||
-rw-r--r-- | Cargo.toml.orig | 9 | ||||
-rw-r--r-- | METADATA | 8 | ||||
-rw-r--r-- | README.md | 5 | ||||
-rw-r--r-- | examples/README.md | 4 | ||||
-rw-r--r-- | examples/rename_all.rs | 4 | ||||
-rw-r--r-- | examples/required_if.rs | 43 | ||||
-rw-r--r-- | src/lib.rs | 13 | ||||
-rw-r--r-- | tests/argument_naming.rs | 28 | ||||
-rw-r--r-- | tests/flatten.rs | 53 | ||||
-rw-r--r-- | tests/macro-errors.rs | 2 | ||||
-rw-r--r-- | tests/ui/flatten_and_doc.rs | 30 | ||||
-rw-r--r-- | tests/ui/flatten_and_doc.stderr | 5 | ||||
-rw-r--r-- | tests/ui/flatten_and_methods.stderr | 2 | ||||
-rw-r--r-- | tests/ui/non_existent_attr.stderr | 4 | ||||
-rw-r--r-- | tests/ui/tuple_struct.stderr | 2 |
19 files changed, 200 insertions, 66 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 2df1587..bb978e8 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "203c6bc19e561da1734873794bbd420e0bfc79b9" + "sha1": "ff542c67023cbddbb2198df4087abc6aa6c8d5b7" } } @@ -22,18 +22,17 @@ rust_library { // ansi_term-0.11.0 // atty-0.2.14 // bitflags-1.2.1 "default" -// clap-2.33.1 "ansi_term,atty,color,default,strsim,suggestions,vec_map" +// clap-2.33.3 "ansi_term,atty,color,default,strsim,suggestions,vec_map" // heck-0.3.1 // lazy_static-1.4.0 -// libc-0.2.74 -// proc-macro-error-1.0.3 -// proc-macro-error-attr-1.0.3 -// proc-macro2-1.0.19 "default,proc-macro" +// libc-0.2.77 +// proc-macro-error-1.0.4 "default,syn,syn-error" +// proc-macro-error-attr-1.0.4 +// proc-macro2-1.0.21 "default,proc-macro" // quote-1.0.7 "default,proc-macro" // strsim-0.8.0 -// structopt-derive-0.4.7 -// syn-1.0.36 "clone-impls,default,derive,full,parsing,printing,proc-macro,quote,visit" -// syn-mid-0.5.0 +// structopt-derive-0.4.11 +// syn-1.0.41 "clone-impls,default,derive,full,parsing,printing,proc-macro,quote,visit" // textwrap-0.11.0 // unicode-segmentation-1.6.0 // unicode-width-0.1.8 "default" diff --git a/CHANGELOG.md b/CHANGELOG.md index 22dca96..ae28950 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,27 @@ +# v0.3.18 (2020-09-23) + +* Unsafe code [has been forbidden](https://github.com/TeXitoi/structopt/issues/432). This makes + [`cargo geiger`](https://github.com/rust-secure-code/cargo-geiger) list structopt as "safe". + Maybe it will help somebody trying to locate a bug in their dependency tree. + +# v0.3.17 (2020-08-25) + +* Fixed [a breakage](https://github.com/TeXitoi/structopt/issues/424) with resent rustc versions + due to `quote_spanned` misuse. + +# v0.3.16 (2020-08-05) + +* Added [the new example](https://github.com/TeXitoi/structopt/blob/master/examples/required_if.rs). +* Allow `#[structopt(flatten)]` fields to have doc comments. The comments are ignored. +* The `paw` crate is now being reexported when `paw` feature is enabled, + see [`#407`](https://github.com/TeXitoi/structopt/issues/407). + +# v0.3.15 (2020-06-16) + +* Minor documentation improvements. +* Fixed [a latent bug](https://github.com/TeXitoi/structopt/pull/398), + courtesy of [@Aaron1011](https://github.com/Aaron1011). + # v0.3.14 (2020-04-22) * Minor documentation improvements. @@ -13,14 +13,14 @@ [package] edition = "2018" name = "structopt" -version = "0.3.14" +version = "0.3.18" authors = ["Guillaume Pinot <texitoi@texitoi.eu>", "others"] description = "Parse command line argument by defining a struct." documentation = "https://docs.rs/structopt" readme = "README.md" keywords = ["clap", "cli", "derive", "docopt"] categories = ["command-line-interface"] -license = "Apache-2.0/MIT" +license = "Apache-2.0 OR MIT" repository = "https://github.com/TeXitoi/structopt" [dependencies.clap] version = "2.33" @@ -29,8 +29,13 @@ default-features = false [dependencies.lazy_static] version = "1.4.0" +[dependencies.paw_dep] +version = "1" +optional = true +package = "paw" + [dependencies.structopt-derive] -version = "=0.4.7" +version = "=0.4.11" [dev-dependencies.rustversion] version = "1" @@ -45,7 +50,7 @@ default = ["clap/default"] doc = ["clap/doc"] lints = ["clap/lints"] no_cargo = ["clap/no_cargo"] -paw = ["structopt-derive/paw"] +paw = ["structopt-derive/paw", "paw_dep"] suggestions = ["clap/suggestions"] wrap_help = ["clap/wrap_help"] yaml = ["clap/yaml"] diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 12b2dbe..9fc207a 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "structopt" -version = "0.3.14" +version = "0.3.18" edition = "2018" authors = ["Guillaume Pinot <texitoi@texitoi.eu>", "others"] description = "Parse command line argument by defining a struct." @@ -8,7 +8,7 @@ documentation = "https://docs.rs/structopt" repository = "https://github.com/TeXitoi/structopt" keywords = ["clap", "cli", "derive", "docopt"] categories = ["command-line-interface"] -license = "Apache-2.0/MIT" +license = "Apache-2.0 OR MIT" readme = "README.md" [features] @@ -21,15 +21,16 @@ lints = ["clap/lints"] debug = ["clap/debug"] no_cargo = ["clap/no_cargo"] doc = ["clap/doc"] -paw = ["structopt-derive/paw"] +paw = ["structopt-derive/paw", "paw_dep"] [badges] travis-ci = { repository = "TeXitoi/structopt" } [dependencies] clap = { version = "2.33", default-features = false } -structopt-derive = { path = "structopt-derive", version = "=0.4.7" } +structopt-derive = { path = "structopt-derive", version = "=0.4.11" } lazy_static = "1.4.0" +paw_dep = { version = "1", optional = true, package = "paw" } [dev-dependencies] trybuild = { version = "1.0.5", features = ["diff"] } @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/structopt/structopt-0.3.14.crate" + value: "https://static.crates.io/crates/structopt/structopt-0.3.18.crate" } - version: "0.3.14" + version: "0.3.18" license_type: NOTICE last_upgrade_date { year: 2020 - month: 5 - day: 6 + month: 9 + day: 23 } } @@ -1,4 +1,7 @@ -# StructOpt [![Build status](https://travis-ci.org/TeXitoi/structopt.svg?branch=master)](https://travis-ci.org/TeXitoi/structopt) [![](https://img.shields.io/crates/v/structopt.svg)](https://crates.io/crates/structopt) [![](https://docs.rs/structopt/badge.svg)](https://docs.rs/structopt) +# StructOpt + +[![Build status](https://travis-ci.org/TeXitoi/structopt.svg?branch=master)](https://travis-ci.org/TeXitoi/structopt) [![](https://img.shields.io/crates/v/structopt.svg)](https://crates.io/crates/structopt) [![](https://docs.rs/structopt/badge.svg)](https://docs.rs/structopt) +[![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/) Parse command line arguments by defining a struct. It combines [clap](https://crates.io/crates/clap) with custom derive. diff --git a/examples/README.md b/examples/README.md index f0db20b..b485393 100644 --- a/examples/README.md +++ b/examples/README.md @@ -69,6 +69,10 @@ How to completely remove version. How `#[structopt(rename_all)]` works. +### [Required If](required_if.rs) + +How to use `#[structopt(required_if)]`. + ### [Skip](skip.rs) How to use `#[structopt(skip)]`. diff --git a/examples/rename_all.rs b/examples/rename_all.rs index 35f3c4f..c7c3538 100644 --- a/examples/rename_all.rs +++ b/examples/rename_all.rs @@ -17,6 +17,10 @@ //! - **Snake Case**: Keep all letters lowercase and indicate word boundaries //! with underscores. //! - **Verbatim**: Use the original attribute name defined in the code. +//! +//! - **Lower Case**: Keep all letters lowercase and remove word boundaries. +//! +//! - **Upper Case**: Keep all letters upperrcase and remove word boundaries. use structopt::StructOpt; diff --git a/examples/required_if.rs b/examples/required_if.rs new file mode 100644 index 0000000..cb6b414 --- /dev/null +++ b/examples/required_if.rs @@ -0,0 +1,43 @@ +//! How to use `required_if` with structopt. +use structopt::StructOpt; + +#[derive(Debug, StructOpt, PartialEq)] +struct Opt { + /// Where to write the output: to `stdout` or `file` + #[structopt(short)] + out_type: String, + + /// File name: only required when `out-type` is set to `file` + #[structopt(name = "FILE", required_if("out-type", "file"))] + file_name: Option<String>, +} + +fn main() { + let opt = Opt::from_args(); + println!("{:?}", opt); +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_opt_out_type_file_without_file_name_returns_err() { + let opt = Opt::from_iter_safe(&["test", "-o", "file"]); + let err = opt.unwrap_err(); + assert_eq!(err.kind, clap::ErrorKind::MissingRequiredArgument); + } + + #[test] + fn test_opt_out_type_file_with_file_name_returns_ok() { + let opt = Opt::from_iter_safe(&["test", "-o", "file", "filename"]); + let opt = opt.unwrap(); + assert_eq!( + opt, + Opt { + out_type: "file".into(), + file_name: Some("filename".into()), + } + ); + } +} @@ -7,6 +7,7 @@ // except according to those terms. #![deny(missing_docs)] +#![forbid(unsafe_code)] //! This crate defines the `StructOpt` trait and its custom derive. //! @@ -87,9 +88,9 @@ //! #[structopt(short)] //! out_type: String, //! -//! /// File name: only required when `out` is set to `file` -//! #[structopt(name = "FILE", required_if("out_type", "file"))] -//! file_name: String, +//! /// File name: only required when `out-type` is set to `file` +//! #[structopt(name = "FILE", required_if("out-type", "file"))] +//! file_name: Option<String>, //! } //! //! fn main() { @@ -280,7 +281,7 @@ //! Usable only on field-level. //! //! - [`rename_all`](#specifying-argument-types): -//! [`rename_all = "kebab"/"snake"/"screaming-snake"/"camel"/"pascal"/"verbatim"]` +//! [`rename_all = "kebab"/"snake"/"screaming-snake"/"camel"/"pascal"/"verbatim"/"lower"/"upper"]` //! //! Usable both on top level and field level. //! @@ -309,7 +310,7 @@ //! Usable only on field-level. //! //! - [`rename_all_env`](##auto-deriving-environment-variables): -//! [`rename_all_env = "kebab"/"snake"/"screaming-snake"/"camel"/"pascal"/"verbatim"]` +//! [`rename_all_env = "kebab"/"snake"/"screaming-snake"/"camel"/"pascal"/"verbatim"/"lower"/"upper"]` //! //! Usable both on top level and field level. //! @@ -1063,6 +1064,8 @@ use std::ffi::OsString; /// Re-exports pub use clap; +#[cfg(feature = "paw")] +pub use paw_dep as paw; /// **This is NOT PUBLIC API**. #[doc(hidden)] diff --git a/tests/argument_naming.rs b/tests/argument_naming.rs index e7fe3d5..88b549d 100644 --- a/tests/argument_naming.rs +++ b/tests/argument_naming.rs @@ -309,3 +309,31 @@ fn test_rename_all_is_propagation_can_be_overridden() { Opt::from_clap(&Opt::clap().get_matches_from(&["test", "SECOND_VARIANT", "--foo-option"])) ); } + +#[test] +fn test_lower_is_renamed() { + #[derive(StructOpt, Debug, PartialEq)] + struct Opt { + #[structopt(rename_all = "lower", long)] + foo_option: bool, + } + + assert_eq!( + Opt { foo_option: true }, + Opt::from_clap(&Opt::clap().get_matches_from(&["test", "--foooption"])) + ); +} + +#[test] +fn test_upper_is_renamed() { + #[derive(StructOpt, Debug, PartialEq)] + struct Opt { + #[structopt(rename_all = "upper", long)] + foo_option: bool, + } + + assert_eq!( + Opt { foo_option: true }, + Opt::from_clap(&Opt::clap().get_matches_from(&["test", "--FOOOPTION"])) + ); +} diff --git a/tests/flatten.rs b/tests/flatten.rs index f01e44e..05de185 100644 --- a/tests/flatten.rs +++ b/tests/flatten.rs @@ -8,6 +8,8 @@ use structopt::StructOpt; +mod utils; + #[test] fn flatten() { #[derive(StructOpt, PartialEq, Debug)] @@ -127,3 +129,54 @@ fn merge_subcommands_with_flatten() { Opt::from_iter(&["test", "command2", "43"]) ); } + +#[test] +#[should_panic = "structopt misuse: You likely tried to #[flatten] a struct \ + that contains #[subcommand]. This is forbidden."] +fn subcommand_in_flatten() { + #[derive(Debug, StructOpt)] + pub enum Struct1 { + #[structopt(flatten)] + Struct1(Struct2), + } + + #[derive(Debug, StructOpt)] + pub struct Struct2 { + #[structopt(subcommand)] + command_type: Enum3, + } + + #[derive(Debug, StructOpt)] + pub enum Enum3 { + Command { args: Vec<String> }, + } + + Struct1::from_iter(&["test", "command", "foo"]); +} + +#[test] +fn flatten_doc_comment() { + #[derive(StructOpt, PartialEq, Debug)] + struct Common { + /// This is an arg. Arg means "argument". Command line argument. + arg: i32, + } + + #[derive(StructOpt, PartialEq, Debug)] + struct Opt { + /// The very important comment that clippy had me put here. + /// It knows better. + #[structopt(flatten)] + common: Common, + } + assert_eq!( + Opt { + common: Common { arg: 42 } + }, + Opt::from_iter(&["test", "42"]) + ); + + let help = utils::get_help::<Opt>(); + assert!(help.contains("This is an arg.")); + assert!(!help.contains("The very important")); +} diff --git a/tests/macro-errors.rs b/tests/macro-errors.rs index ae4f5a2..54b405a 100644 --- a/tests/macro-errors.rs +++ b/tests/macro-errors.rs @@ -5,7 +5,7 @@ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed -#[rustversion::attr(any(not(stable), before(1.39)), ignore)] +#[rustversion::attr(any(not(stable), before(1.43)), ignore)] #[test] fn ui() { let t = trybuild::TestCases::new(); diff --git a/tests/ui/flatten_and_doc.rs b/tests/ui/flatten_and_doc.rs deleted file mode 100644 index 2dc154d..0000000 --- a/tests/ui/flatten_and_doc.rs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2018 Guillaume Pinot (@TeXitoi) <texitoi@texitoi.eu> -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use structopt::StructOpt; - -#[derive(StructOpt, Debug)] -struct DaemonOpts { - #[structopt(short)] - user: String, - #[structopt(short)] - group: String, -} - -#[derive(StructOpt, Debug)] -#[structopt(name = "basic")] -struct Opt { - /// Opts. - #[structopt(flatten)] - opts: DaemonOpts, -} - -fn main() { - let opt = Opt::from_args(); - println!("{:?}", opt); -} diff --git a/tests/ui/flatten_and_doc.stderr b/tests/ui/flatten_and_doc.stderr deleted file mode 100644 index 2724dbb..0000000 --- a/tests/ui/flatten_and_doc.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: methods and doc comments are not allowed for flattened entry - --> $DIR/flatten_and_doc.rs:23:17 - | -23 | #[structopt(flatten)] - | ^^^^^^^ diff --git a/tests/ui/flatten_and_methods.stderr b/tests/ui/flatten_and_methods.stderr index f058eb3..77d97ae 100644 --- a/tests/ui/flatten_and_methods.stderr +++ b/tests/ui/flatten_and_methods.stderr @@ -1,4 +1,4 @@ -error: methods and doc comments are not allowed for flattened entry +error: methods are not allowed for flattened entry --> $DIR/flatten_and_methods.rs:22:24 | 22 | #[structopt(short, flatten)] diff --git a/tests/ui/non_existent_attr.stderr b/tests/ui/non_existent_attr.stderr index 99dc781..e5edb56 100644 --- a/tests/ui/non_existent_attr.stderr +++ b/tests/ui/non_existent_attr.stderr @@ -1,5 +1,5 @@ -error[E0599]: no method named `non_existing_attribute` found for struct `clap::args::arg::Arg<'_, '_>` in the current scope +error[E0599]: no method named `non_existing_attribute` found for struct `structopt::clap::Arg<'_, '_>` in the current scope --> $DIR/non_existent_attr.rs:14:24 | 14 | #[structopt(short, non_existing_attribute = 1)] - | ^^^^^^^^^^^^^^^^^^^^^^ method not found in `clap::args::arg::Arg<'_, '_>` + | ^^^^^^^^^^^^^^^^^^^^^^ method not found in `structopt::clap::Arg<'_, '_>` diff --git a/tests/ui/tuple_struct.stderr b/tests/ui/tuple_struct.stderr index 9f2876f..31705c9 100644 --- a/tests/ui/tuple_struct.stderr +++ b/tests/ui/tuple_struct.stderr @@ -3,3 +3,5 @@ error: structopt only supports non-tuple structs and enums | 11 | #[derive(StructOpt, Debug)] | ^^^^^^^^^ + | + = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) |