aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Vander Stoep <jeffv@google.com>2023-02-01 15:16:33 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-02-01 15:16:33 +0000
commitd887a58038a1618f5efea9bd8502dce52e4058fb (patch)
tree3191aa09161d573be478e475ec73977ba77b8264
parent8d8e132790b3c5a8e223e9450d301e61691b28f5 (diff)
parentb4370db489b5c2bb03884678790d521721153d65 (diff)
downloadargh-d887a58038a1618f5efea9bd8502dce52e4058fb.tar.gz
Upgrade argh to 0.1.10 am: b43b49e846 am: b4370db489
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/argh/+/2411579 Change-Id: I6f09a43b7799b576e68154536ff1e4bdbf9bdced Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--Android.bp6
-rw-r--r--Cargo.lock (renamed from Cargo.lock.saved)69
-rw-r--r--Cargo.toml6
-rw-r--r--Cargo.toml.orig6
-rw-r--r--METADATA10
-rw-r--r--src/lib.rs47
-rw-r--r--tests/lib.rs50
-rw-r--r--tests/ui/bad-long-names/bad-long-names.rs15
-rw-r--r--tests/ui/bad-long-names/bad-long-names.stderr17
10 files changed, 174 insertions, 54 deletions
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.saved b/Cargo.lock
index fe2463c..59f8c1a 100644
--- a/Cargo.lock.saved
+++ b/Cargo.lock
@@ -4,7 +4,7 @@ version = 3
[[package]]
name = "argh"
-version = "0.1.9"
+version = "0.1.10"
dependencies = [
"argh_derive",
"argh_shared",
@@ -14,12 +14,11 @@ dependencies = [
[[package]]
name = "argh_derive"
-version = "0.1.9"
+version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "aa013479b80109a1bf01a039412b0f0013d716f36921226d86c6709032fb7a03"
+checksum = "b382dbd3288e053331f03399e1db106c9fb0d8562ad62cb04859ae926f324fa6"
dependencies = [
"argh_shared",
- "heck",
"proc-macro2",
"quote",
"syn",
@@ -27,69 +26,63 @@ dependencies = [
[[package]]
name = "argh_shared"
-version = "0.1.9"
+version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "149f75bbec1827618262e0855a68f0f9a7f2edc13faebf33c4f16d6725edb6a9"
+checksum = "64cb94155d965e3d37ffbbe7cc5b82c3dd79dd33bd48e536f73d2cfb8d85506f"
[[package]]
name = "glob"
-version = "0.3.0"
+version = "0.3.1"
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"
+checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]]
name = "itoa"
-version = "1.0.3"
+version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754"
+checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440"
[[package]]
name = "once_cell"
-version = "1.15.0"
+version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1"
+checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66"
[[package]]
name = "proc-macro2"
-version = "1.0.43"
+version = "1.0.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab"
+checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
-version = "1.0.21"
+version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
+checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
dependencies = [
"proc-macro2",
]
[[package]]
name = "ryu"
-version = "1.0.11"
+version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
+checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde"
[[package]]
name = "serde"
-version = "1.0.145"
+version = "1.0.152"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b"
+checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb"
[[package]]
name = "serde_derive"
-version = "1.0.145"
+version = "1.0.152"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c"
+checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e"
dependencies = [
"proc-macro2",
"quote",
@@ -98,9 +91,9 @@ dependencies = [
[[package]]
name = "serde_json"
-version = "1.0.85"
+version = "1.0.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44"
+checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883"
dependencies = [
"itoa",
"ryu",
@@ -109,9 +102,9 @@ dependencies = [
[[package]]
name = "syn"
-version = "1.0.100"
+version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "52205623b1b0f064a4e71182c3b18ae902267282930c6d5462c91b859668426e"
+checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5"
dependencies = [
"proc-macro2",
"quote",
@@ -129,18 +122,18 @@ dependencies = [
[[package]]
name = "toml"
-version = "0.5.9"
+version = "0.5.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7"
+checksum = "1333c76748e868a4d9d1017b5ab53171dfd095f70c712fdb4653a406547f598f"
dependencies = [
"serde",
]
[[package]]
name = "trybuild"
-version = "1.0.64"
+version = "1.0.75"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e7f408301c7480f9e6294eb779cfc907f54bd901a9660ef24d7f233ed5376485"
+checksum = "f1212c215a87a183687a7cc7065901b1a98da6b37277d51a1b5faedbb4efd4f3"
dependencies = [
"glob",
"once_cell",
@@ -153,9 +146,9 @@ dependencies = [
[[package]]
name = "unicode-ident"
-version = "1.0.4"
+version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd"
+checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
[[package]]
name = "winapi"
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 <cramertj@google.com>",
"Benjamin Brittain <bwb@google.com>",
@@ -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 <cramertj@google.com>", "Benjamin Brittain <bwb@google.com>", "Erick Tryzelaar <etryzelaar@google.com>"]
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: TopLevelCommand>() -> T {
- let strings: Vec<String> = std::env::args().collect();
+ let strings: Vec<String> = std::env::args_os()
+ .map(|s| s.into_string())
+ .collect::<Result<Vec<_>, _>>()
+ .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<bool> {
+ 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::<Underscores>(
+ &[],
+ r###"Required positional arguments not provided:
+ a
+"###,
+ );
+ }
}
/// Tests derived from
@@ -1173,6 +1193,36 @@ Options:
"###,
);
}
+
+ #[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::<Cmd>(
+ r###"Usage: test_arg_0 <two>
+
+Short description
+
+Positional Arguments:
+ two this one is real
+
+Options:
+ --help display usage information
+"###,
+ );
+ }
}
#[test]
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")]
+ | ^^^^^^^^^^^^