From b43b49e8462381b628fa87f595c56a52db77ccfa Mon Sep 17 00:00:00 2001 From: Jeff Vander Stoep Date: Wed, 1 Feb 2023 12:16:42 +0100 Subject: Upgrade argh to 0.1.10 This project was upgraded with external_updater. Usage: tools/external_updater/updater.sh update rust/crates/argh For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md Test: TreeHugger Change-Id: I95a75c69f9f02fc7e3d50892d03e419b6fc054ad --- .cargo_vcs_info.json | 2 +- Android.bp | 6 +- Cargo.lock | 182 +++++++++++++++++++++++++ Cargo.lock.saved | 189 -------------------------- Cargo.toml | 6 +- Cargo.toml.orig | 6 +- METADATA | 10 +- src/lib.rs | 47 ++++++- tests/lib.rs | 50 +++++++ tests/ui/bad-long-names/bad-long-names.rs | 15 ++ tests/ui/bad-long-names/bad-long-names.stderr | 17 +++ 11 files changed, 325 insertions(+), 205 deletions(-) create mode 100644 Cargo.lock delete mode 100644 Cargo.lock.saved create mode 100644 tests/ui/bad-long-names/bad-long-names.rs create mode 100644 tests/ui/bad-long-names/bad-long-names.stderr diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 13adf5d..eed94c9 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "adc704cd29f710864b0fc1872bc86f857bebfdbf" + "sha1": "3f3c29726a21c4b541bb2b9aa2c592461897ded0" }, "path_in_vcs": "argh" } \ No newline at end of file diff --git a/Android.bp b/Android.bp index 04c0314..d06cb16 100644 --- a/Android.bp +++ b/Android.bp @@ -23,7 +23,7 @@ rust_test { host_supported: true, crate_name: "argh", cargo_env_compat: true, - cargo_pkg_version: "0.1.9", + cargo_pkg_version: "0.1.10", srcs: ["src/lib.rs"], test_suites: ["general-tests"], auto_gen_config: true, @@ -43,7 +43,7 @@ rust_test { host_supported: true, crate_name: "argh", cargo_env_compat: true, - cargo_pkg_version: "0.1.9", + cargo_pkg_version: "0.1.10", srcs: ["tests/lib.rs"], test_suites: ["general-tests"], auto_gen_config: true, @@ -64,7 +64,7 @@ rust_library { host_supported: true, crate_name: "argh", cargo_env_compat: true, - cargo_pkg_version: "0.1.9", + cargo_pkg_version: "0.1.10", srcs: ["src/lib.rs"], edition: "2018", rustlibs: [ diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..59f8c1a --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,182 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "argh" +version = "0.1.10" +dependencies = [ + "argh_derive", + "argh_shared", + "once_cell", + "trybuild", +] + +[[package]] +name = "argh_derive" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b382dbd3288e053331f03399e1db106c9fb0d8562ad62cb04859ae926f324fa6" +dependencies = [ + "argh_shared", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "argh_shared" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64cb94155d965e3d37ffbbe7cc5b82c3dd79dd33bd48e536f73d2cfb8d85506f" + +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "itoa" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" + +[[package]] +name = "once_cell" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" + +[[package]] +name = "proc-macro2" +version = "1.0.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ryu" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" + +[[package]] +name = "serde" +version = "1.0.152" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" + +[[package]] +name = "serde_derive" +version = "1.0.152" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "syn" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "toml" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1333c76748e868a4d9d1017b5ab53171dfd095f70c712fdb4653a406547f598f" +dependencies = [ + "serde", +] + +[[package]] +name = "trybuild" +version = "1.0.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1212c215a87a183687a7cc7065901b1a98da6b37277d51a1b5faedbb4efd4f3" +dependencies = [ + "glob", + "once_cell", + "serde", + "serde_derive", + "serde_json", + "termcolor", + "toml", +] + +[[package]] +name = "unicode-ident" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.lock.saved b/Cargo.lock.saved deleted file mode 100644 index fe2463c..0000000 --- a/Cargo.lock.saved +++ /dev/null @@ -1,189 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "argh" -version = "0.1.9" -dependencies = [ - "argh_derive", - "argh_shared", - "once_cell", - "trybuild", -] - -[[package]] -name = "argh_derive" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa013479b80109a1bf01a039412b0f0013d716f36921226d86c6709032fb7a03" -dependencies = [ - "argh_shared", - "heck", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "argh_shared" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "149f75bbec1827618262e0855a68f0f9a7f2edc13faebf33c4f16d6725edb6a9" - -[[package]] -name = "glob" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" - -[[package]] -name = "heck" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" - -[[package]] -name = "itoa" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" - -[[package]] -name = "once_cell" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" - -[[package]] -name = "proc-macro2" -version = "1.0.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "ryu" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" - -[[package]] -name = "serde" -version = "1.0.145" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b" - -[[package]] -name = "serde_derive" -version = "1.0.145" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.85" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "syn" -version = "1.0.100" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52205623b1b0f064a4e71182c3b18ae902267282930c6d5462c91b859668426e" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "termcolor" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "toml" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" -dependencies = [ - "serde", -] - -[[package]] -name = "trybuild" -version = "1.0.64" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7f408301c7480f9e6294eb779cfc907f54bd901a9660ef24d7f233ed5376485" -dependencies = [ - "glob", - "once_cell", - "serde", - "serde_derive", - "serde_json", - "termcolor", - "toml", -] - -[[package]] -name = "unicode-ident" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi", -] - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 220a383..2867953 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ [package] edition = "2018" name = "argh" -version = "0.1.9" +version = "0.1.10" authors = [ "Taylor Cramer ", "Benjamin Brittain ", @@ -30,10 +30,10 @@ license = "BSD-3-Clause" repository = "https://github.com/google/argh" [dependencies.argh_derive] -version = "0.1.9" +version = "0.1.10" [dependencies.argh_shared] -version = "0.1.9" +version = "0.1.10" [dev-dependencies.once_cell] version = "1.10.0" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 4b3bb43..2f1b7f0 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "argh" -version = "0.1.9" +version = "0.1.10" authors = ["Taylor Cramer ", "Benjamin Brittain ", "Erick Tryzelaar "] edition = "2018" keywords = ["args", "arguments", "derive", "cli"] @@ -10,8 +10,8 @@ repository = "https://github.com/google/argh" readme = "README.md" [dependencies] -argh_shared = { version = "0.1.9", path = "../argh_shared" } -argh_derive = { version = "0.1.9", path = "../argh_derive" } +argh_shared = { version = "0.1.10", path = "../argh_shared" } +argh_derive = { version = "0.1.10", path = "../argh_derive" } [dev-dependencies] once_cell = "1.10.0" diff --git a/METADATA b/METADATA index 4a58820..6a1602e 100644 --- a/METADATA +++ b/METADATA @@ -11,13 +11,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/argh/argh-0.1.9.crate" + value: "https://static.crates.io/crates/argh/argh-0.1.10.crate" } - version: "0.1.9" + version: "0.1.10" license_type: NOTICE last_upgrade_date { - year: 2022 - month: 12 - day: 5 + year: 2023 + month: 2 + day: 1 } } diff --git a/src/lib.rs b/src/lib.rs index c507be0..4fb6ff5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -290,6 +290,29 @@ //! } //! } //! ``` +//! +//! Programs that are run from an environment such as cargo may find it +//! useful to have positional arguments present in the structure but +//! omitted from the usage output. This can be accomplished by adding +//! the `hidden_help` attribute to that argument: +//! +//! ```rust +//! # use argh::FromArgs; +//! +//! #[derive(FromArgs)] +//! /// Cargo arguments +//! struct CargoArgs { +//! // Cargo puts the command name invoked into the first argument, +//! // so we don't want this argument to show up in the usage text. +//! #[argh(positional, hidden_help)] +//! command: String, +//! /// an option used for internal debugging +//! #[argh(option, hidden_help)] +//! internal_debugging: String, +//! #[argh(positional)] +//! real_first_arg: String, +//! } +//! ``` #![deny(missing_docs)] @@ -646,7 +669,19 @@ fn cmd<'a>(default: &'a str, path: &'a str) -> &'a str { /// was unsuccessful or if information like `--help` was requested. Error messages will be printed /// to stderr, and `--help` output to stdout. pub fn from_env() -> T { - let strings: Vec = std::env::args().collect(); + let strings: Vec = std::env::args_os() + .map(|s| s.into_string()) + .collect::, _>>() + .unwrap_or_else(|arg| { + eprintln!("Invalid utf8: {}", arg.to_string_lossy()); + std::process::exit(1) + }); + + if strings.is_empty() { + eprintln!("No program name, argv is empty"); + std::process::exit(1) + } + let cmd = cmd(&strings[0], &strings[0]); let strs: Vec<&str> = strings.iter().map(|s| s.as_str()).collect(); T::from_args(&[cmd], &strs[1..]).unwrap_or_else(|early_exit| { @@ -799,6 +834,16 @@ impl Flag for bool { } } +impl Flag for Option { + fn default() -> Self { + None + } + + fn set_flag(&mut self) { + *self = Some(true); + } +} + macro_rules! impl_flag_for_integers { ($($ty:ty,)*) => { $( diff --git a/tests/lib.rs b/tests/lib.rs index 584897c..713c73d 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -703,6 +703,26 @@ Required options not provided: }, ); } + + #[derive(FromArgs, Debug, PartialEq)] + /// Woot + struct Underscores { + #[argh(positional)] + /// fooey + a_: String, + } + + #[test] + fn positional_name_with_underscores() { + assert_output(&["first"], Underscores { a_: "first".into() }); + + assert_error::( + &[], + r###"Required positional arguments not provided: + a +"###, + ); + } } /// Tests derived from @@ -1168,6 +1188,36 @@ Destroy the contents of . Positional Arguments: name +Options: + --help display usage information +"###, + ); + } + + #[test] + fn hidden_help_attribute() { + #[derive(FromArgs)] + /// Short description + struct Cmd { + /// this one should be hidden + #[argh(positional, hidden_help)] + _one: String, + #[argh(positional)] + /// this one is real + _two: String, + /// this one should be hidden + #[argh(option, hidden_help)] + _three: String, + } + + assert_help_string::( + r###"Usage: test_arg_0 + +Short description + +Positional Arguments: + two this one is real + Options: --help display usage information "###, diff --git a/tests/ui/bad-long-names/bad-long-names.rs b/tests/ui/bad-long-names/bad-long-names.rs new file mode 100644 index 0000000..61a9696 --- /dev/null +++ b/tests/ui/bad-long-names/bad-long-names.rs @@ -0,0 +1,15 @@ +/// Command +#[derive(argh::FromArgs)] +struct Cmd { + #[argh(switch)] + /// non-ascii + привет: bool, + #[argh(switch)] + /// uppercase + XMLHTTPRequest: bool, + #[argh(switch, long = "not really")] + /// bad attr + ok: bool, +} + +fn main() {} diff --git a/tests/ui/bad-long-names/bad-long-names.stderr b/tests/ui/bad-long-names/bad-long-names.stderr new file mode 100644 index 0000000..3396a5a --- /dev/null +++ b/tests/ui/bad-long-names/bad-long-names.stderr @@ -0,0 +1,17 @@ +error: Long names must be ASCII + --> tests/ui/bad-long-names/bad-long-names.rs:6:5 + | +6 | привет: bool, + | ^^^^^^ + +error: Long names must be lowercase + --> tests/ui/bad-long-names/bad-long-names.rs:9:5 + | +9 | XMLHTTPRequest: bool, + | ^^^^^^^^^^^^^^ + +error: Long names must be lowercase + --> tests/ui/bad-long-names/bad-long-names.rs:10:27 + | +10 | #[argh(switch, long = "not really")] + | ^^^^^^^^^^^^ -- cgit v1.2.3