From bef1eec1e1f8c206ed265a340daaab67d9bbe4fe Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Wed, 28 Oct 2020 16:33:12 +0000 Subject: [PATCH] [rust-crates] Bump argh to 0.1.4 This updates argh to 0.1.4, which includes the following changes: * 66e44a7 - Add myself to more authors lists (6 minutes ago) * ce8ce29 - Add Cargo.lock to .gitignore (9 minutes ago) * 567dc18 - Adding myself to the authors list (10 minutes ago) * c2fc87d - Bump versions to 0.1.4 (10 minutes ago) * 83785d1 - Use command base name not full path. (#44) (4 hours ago) * d6abe82 - Merge pull request #64 from erickt/parse-errors (2 weeks ago) |\ | * c728c85 - Fix quoting in errors when parsing arguments (2 weeks ago) * | 14fc76d - Merge pull request #66 from erickt/remove-lock (2 weeks ago) |\ \ | |/ |/| | * e91274f - Remove lockfile (2 weeks ago) |/ * f3da6ae - Merge pull request #60 from elipsitz/support-option-delimiter (2 weeks ago) |\ | * 9022148 - Add support for option delimiter "--" (3 weeks ago) | * 2517d3f - Run rustfmt to fix a pre-existing formatting issue (3 weeks ago) * | 8d9a82f - Merge pull request #49 from siyopao/fix-issue-45 (3 months ago) |\| | * ee6521e - Add missing newline to error message (3 months ago) |/ * 507087f - Merge pull request #41 from benbrittain/kebab-case (4 months ago) |\ | * 5b0c45f - Allow kebab-case in long names (4 months ago) | * ae57b5c - update lockfile (4 months ago) |/ * e59f2c8 - fix default value error message (4 months ago) * aae704e - Merge pull request #24 from foresterre/docs/fix-docsrs-badge-link (6 months ago) |\ | * 1fddf5a - Fix the source of the docs.rs badge link (6 months ago) |/ * 68e7363 - Merge pull request #23 from Atul9/add-cargo-fmt-to-github-actions (7 months ago) |\ | * 1f8930c - Add cargo fmt to github-actions config (7 months ago) |/ * bf49ee6 - Merge pull request #17 from fadeevab/docs-about-default (7 months ago) |\ | * 7d6cc74 - Update package docs from README (about default args) (7 months ago) |/ * c1079ba - Merge pull request #16 from fadeevab/readme-examples-default-optional (7 months ago) |\ | * 1adb4e8 - Example and explanation about default and optional (7 months ago) |/ * dad549b - Merge pull request #10 from MRedies/patch-1 (9 months ago) |\ | * 276fa2b - Confusing syntax highlighting in README.md (9 months ago) |/ * 737d298 - Merge pull request #8 from Atul9/cargo-fmt (9 months ago) |\ | * 7515ada - Format code using 'cargo fmt' (9 months ago) |/ * 6e8c8f5 - Add rustfmt used for this project (9 months ago) * 154e4fe - Add badges to README (9 months ago) * 775c6bc - Update rust.yml (9 months ago) * f587921 - Update rust.yml (9 months ago) * 3ab931f - Add basic CI/CQ with GitHub actions (9 months ago) * 9bd8f0f - Add keywords (9 months ago) * e8a6b13 - Remove duplicate section in README (9 months ago) * bac15ab - Merge pull request #5 from tshepang/patch-1 (9 months ago) |\ | * e5e0d6f - readme: highlight code, and reduce density, for 1 example (9 months ago) |/ * ebfaa78 - Merge pull request #2 from jeremyBanks/patch-1 (9 months ago) * 5e702a1 - Link crates.io badge to crates.io page (9 months ago) Change-Id: Iec1b6164fe477c7e7f0583273a405be1a87064f4 Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/443703 Reviewed-by: George Kulakowski Testability-Review: George Kulakowski Commit-Queue: Erick Tryzelaar --- third_party/rust_crates/BUILD.gn | 32 +++---- third_party/rust_crates/Cargo.lock | 12 +-- third_party/rust_crates/Cargo.toml | 2 +- .../vendor/argh/.cargo-checksum.json | 2 +- .../rust_crates/vendor/argh/Cargo.toml | 9 +- third_party/rust_crates/vendor/argh/README.md | 83 +++++++++-------- .../rust_crates/vendor/argh/rustfmt.toml | 15 ++++ .../rust_crates/vendor/argh/src/lib.rs | 82 +++++++++++++---- .../rust_crates/vendor/argh/tests/lib.rs | 89 ++++++++++++++++++- .../vendor/argh_derive/.cargo-checksum.json | 2 +- .../rust_crates/vendor/argh_derive/Cargo.toml | 6 +- .../rust_crates/vendor/argh_derive/src/lib.rs | 8 +- .../vendor/argh_derive/src/parse_attrs.rs | 4 +- .../vendor/argh_shared/.cargo-checksum.json | 2 +- .../rust_crates/vendor/argh_shared/Cargo.toml | 4 +- 15 files changed, 253 insertions(+), 99 deletions(-) create mode 100644 third_party/rust_crates/vendor/argh/rustfmt.toml diff --git a/third_party/rust_crates/BUILD.gn b/third_party/rust_crates/BUILD.gn index e03d48bd1128..fe4384723160 100644 --- a/third_party/rust_crates/BUILD.gn +++ b/third_party/rust_crates/BUILD.gn @@ -17,7 +17,7 @@ group("arc-swap") { } group("argh") { - deps = [ ":argh-v0_1_3" ] + deps = [ ":argh-v0_1_4" ] } if (!(current_os == "fuchsia")) { @@ -987,40 +987,40 @@ rust_library("arc-swap-v0_4_4") { ] } -rust_library("argh-v0_1_3") { +rust_library("argh-v0_1_4") { crate_name = "argh" crate_root = "//third_party/rust_crates/vendor/argh/src/lib.rs" - output_name = "argh-e6d3638980bc6cc2" + output_name = "argh-bd83e7fcbd154aa3" configs -= [ "//build/config:rust_edition_2018", "//build/config:rust_2018_idioms", ] deps = [] - deps += [ ":argh_derive-v0_1_1($host_toolchain)" ] - deps += [ ":argh_shared-v0_1_1" ] + deps += [ ":argh_derive-v0_1_4($host_toolchain)" ] + deps += [ ":argh_shared-v0_1_4" ] rustenv = [] rustflags = [ "--cap-lints=allow", "--edition=2018", - "-Cmetadata=e6d3638980bc6cc2", - "-Cextra-filename=-e6d3638980bc6cc2", + "-Cmetadata=bd83e7fcbd154aa3", + "-Cextra-filename=-bd83e7fcbd154aa3", ] } -rust_proc_macro("argh_derive-v0_1_1") { +rust_proc_macro("argh_derive-v0_1_4") { crate_name = "argh_derive" crate_root = "//third_party/rust_crates/vendor/argh_derive/src/lib.rs" - output_name = "argh_derive-1a52dd25b67cbf93" + output_name = "argh_derive-d03e76f8d081cdf5" configs -= [ "//build/config:rust_edition_2018", "//build/config:rust_2018_idioms", ] deps = [] - deps += [ ":argh_shared-v0_1_1" ] + deps += [ ":argh_shared-v0_1_4" ] deps += [ ":heck-v0_3_1" ] deps += [ ":proc-macro2-v1_0_19" ] deps += [ ":quote-v1_0_7" ] @@ -1031,15 +1031,15 @@ rust_proc_macro("argh_derive-v0_1_1") { rustflags = [ "--cap-lints=allow", "--edition=2018", - "-Cmetadata=1a52dd25b67cbf93", - "-Cextra-filename=-1a52dd25b67cbf93", + "-Cmetadata=d03e76f8d081cdf5", + "-Cextra-filename=-d03e76f8d081cdf5", ] } -rust_library("argh_shared-v0_1_1") { +rust_library("argh_shared-v0_1_4") { crate_name = "argh_shared" crate_root = "//third_party/rust_crates/vendor/argh_shared/src/lib.rs" - output_name = "argh_shared-caab17a714e9e1db" + output_name = "argh_shared-8b110dad3a849fb" configs -= [ "//build/config:rust_edition_2018", "//build/config:rust_2018_idioms", @@ -1052,8 +1052,8 @@ rust_library("argh_shared-v0_1_1") { rustflags = [ "--cap-lints=allow", "--edition=2018", - "-Cmetadata=caab17a714e9e1db", - "-Cextra-filename=-caab17a714e9e1db", + "-Cmetadata=8b110dad3a849fb", + "-Cextra-filename=-8b110dad3a849fb", ] } diff --git a/third_party/rust_crates/Cargo.lock b/third_party/rust_crates/Cargo.lock index 87db6ee4e176..270697f98ebd 100644 --- a/third_party/rust_crates/Cargo.lock +++ b/third_party/rust_crates/Cargo.lock @@ -56,9 +56,9 @@ checksum = "d7b8a9123b8027467bce0099fe556c628a53c8d83df0507084c31e9ba2e39aff" [[package]] name = "argh" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca1877e24cecacd700d469066e0160c4f8497cc5635367163f50c8beec820154" +checksum = "91792f088f87cdc7a2cfb1d617fa5ea18d7f1dc22ef0e1b5f82f3157cdc522be" dependencies = [ "argh_derive", "argh_shared", @@ -66,9 +66,9 @@ dependencies = [ [[package]] name = "argh_derive" -version = "0.1.1" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e742194e0f43fc932bcb801708c2b279d3ec8f527e3acda05a6a9f342c5ef764" +checksum = "c4eb0c0c120ad477412dc95a4ce31e38f2113e46bd13511253f79196ca68b067" dependencies = [ "argh_shared", "heck", @@ -79,9 +79,9 @@ dependencies = [ [[package]] name = "argh_shared" -version = "0.1.1" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1ba68f4276a778591e36a0c348a269888f3a177c8d2054969389e3b59611ff5" +checksum = "781f336cc9826dbaddb9754cb5db61e64cab4f69668bd19dcc4a0394a86f4cb1" [[package]] name = "arrayref" diff --git a/third_party/rust_crates/Cargo.toml b/third_party/rust_crates/Cargo.toml index c0f750a15748..6994121e82f9 100644 --- a/third_party/rust_crates/Cargo.toml +++ b/third_party/rust_crates/Cargo.toml @@ -25,7 +25,7 @@ version = "0.1.0" # Keep this sorted alphabetically, please. anyhow = "1.0.25" arbitrary = { version = "0.4.0", features = ["derive"] } -argh = "0.1" +argh = "0.1.4" arc-swap = "0.4.4" async-trait = "0.1.40" base64 = "0.9" diff --git a/third_party/rust_crates/vendor/argh/.cargo-checksum.json b/third_party/rust_crates/vendor/argh/.cargo-checksum.json index 1cf03f65211a..d4ff81fb414a 100644 --- a/third_party/rust_crates/vendor/argh/.cargo-checksum.json +++ b/third_party/rust_crates/vendor/argh/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"CONTRIBUTING.md":"a6280cf23d8b0d8d51bb3e1c8ec64d4cd5ce42eb4b8501475a50fae984d46ec3","Cargo.toml":"ec64bd24c446321a1c455951bc297955169ad82032dbcd5c7df02da981632408","LICENSE":"03b114f53e6587a398931762ee11e2395bfdba252a329940e2c8c9e81813845b","README.md":"a0c022062da5573b64222f755507b823e754f779393dd64af17c64307adee182","code-of-conduct.md":"3cb747e51d90a4ee3b8147b1643ab21c14ff91971e254a8b1a96731175b082e6","src/lib.rs":"b6f66338a6a5b58fd0dc287924c783070ba01de0e511c3a72255918f8ced9547","tests/lib.rs":"bf413af0c523cc8c6e85c515377e50cc08430c9b22ab0b39a85f0f8e85834876"},"package":"ca1877e24cecacd700d469066e0160c4f8497cc5635367163f50c8beec820154"} \ No newline at end of file +{"files":{"CONTRIBUTING.md":"a6280cf23d8b0d8d51bb3e1c8ec64d4cd5ce42eb4b8501475a50fae984d46ec3","Cargo.toml":"73594b71ae84cf5292b7e087a4d77afd87aee1b6b295a6f5663e03b30deca712","LICENSE":"03b114f53e6587a398931762ee11e2395bfdba252a329940e2c8c9e81813845b","README.md":"e25fb39b3e5764573173dc89cf11078e8f495b326698b9a1e4506c00f676a407","code-of-conduct.md":"3cb747e51d90a4ee3b8147b1643ab21c14ff91971e254a8b1a96731175b082e6","rustfmt.toml":"a2d6afdf5fa04b78edf3c24877d46edba97000c9cd8a02202419eddf262138c8","src/lib.rs":"8526a2d43ff223e1d7491e752238e0763acf7c066bcf3955fd28d352583e51f9","tests/lib.rs":"89d66c7f9d6dc9772743a337e4de38979bcf176b95e787a48159e23028997769"},"package":"91792f088f87cdc7a2cfb1d617fa5ea18d7f1dc22ef0e1b5f82f3157cdc522be"} \ No newline at end of file diff --git a/third_party/rust_crates/vendor/argh/Cargo.toml b/third_party/rust_crates/vendor/argh/Cargo.toml index a61d9b767a7b..1deee0d5064d 100644 --- a/third_party/rust_crates/vendor/argh/Cargo.toml +++ b/third_party/rust_crates/vendor/argh/Cargo.toml @@ -13,13 +13,14 @@ [package] edition = "2018" name = "argh" -version = "0.1.3" -authors = ["Taylor Cramer ", "Benjamin Brittain"] +version = "0.1.4" +authors = ["Taylor Cramer ", "Benjamin Brittain ", "Erick Tryzelaar "] description = "Derive-based argument parser optimized for code size" +keywords = ["args", "arguments", "derive", "cli"] license = "BSD-3-Clause" repository = "https://github.com/google/argh" [dependencies.argh_derive] -version = "0.1.1" +version = "0.1.4" [dependencies.argh_shared] -version = "0.1.1" +version = "0.1.4" diff --git a/third_party/rust_crates/vendor/argh/README.md b/third_party/rust_crates/vendor/argh/README.md index d088656b7b5f..4e949e49fe64 100644 --- a/third_party/rust_crates/vendor/argh/README.md +++ b/third_party/rust_crates/vendor/argh/README.md @@ -1,7 +1,10 @@ # Argh **Argh is an opinionated Derive-based argument parser optimized for code size** -![crates.io](https://img.shields.io/crates/v/argh.svg) +[![crates.io](https://img.shields.io/crates/v/argh.svg)](https://crates.io/crates/argh) +[![license](https://img.shields.io/badge/license-BSD3.0-blue.svg)](https://github.com/google/argh/LICENSE) +[![docs.rs](https://docs.rs/argh/badge.svg)](https://docs.rs/crate/argh/) +![Argh](https://github.com/google/argh/workflows/Argh/badge.svg) Derive-based argument parsing optimized for code size and conformance to the Fuchsia commandline tools specification @@ -39,7 +42,7 @@ fn main() { `./some_bin --help` will then output the following: -```bash +``` Usage: cmdname [-j] --height [--pilot-nickname ] Reach new heights. @@ -61,15 +64,44 @@ Switches, like `jump`, are optional and will be set to true if provided. Options, like `height` and `pilot_nickname`, can be either required, optional, or repeating, depending on whether they are contained in an `Option` or a `Vec`. Default values can be provided using the -`#[argh(default = "")]` attribute. +`#[argh(default = "")]` attribute, and in this case an +option is treated as optional. + +```rust +use argh::FromArgs; + +fn default_height() -> usize { + 5 +} + +#[derive(FromArgs)] +/// Reach new heights. +struct GoUp { + /// an optional nickname for the pilot + #[argh(option)] + pilot_nickname: Option, + + /// an optional height + #[argh(option, default = "default_height()")] + height: usize, + + /// an optional direction which is "up" by default + #[argh(option, default = "String::from(\"only up\")")] + direction: String, +} + +fn main() { + let up: GoUp = argh::from_env(); +} +``` Custom option types can be deserialized so long as they implement the `FromArgValue` trait (automatically implemented for all `FromStr` types). If more customized parsing is required, you can supply a custom `fn(&str) -> Result` using the `from_str_fn` attribute: -``` -# use argh::FromArgs; +```rust +use argh::FromArgs; #[derive(FromArgs)] /// Goofy thing. @@ -90,6 +122,7 @@ the structure: ```rust use argh::FromArgs; + #[derive(FromArgs, PartialEq, Debug)] /// A command with positional arguments. struct WithPositional { @@ -99,50 +132,14 @@ struct WithPositional { ``` The last positional argument may include a default, or be wrapped in -`Option` or `Vec` to indicate an optional or repeating positional arugment. +`Option` or `Vec` to indicate an optional or repeating positional argument. Subcommands are also supported. To use a subcommand, declare a separate `FromArgs` type for each subcommand as well as an enum that cases over each command: ```rust -# use argh::FromArgs; - -#[derive(FromArgs, PartialEq, Debug)] -/// Top-level command. -struct TopLevel { - #[argh(subcommand)] - nested: MySubCommandEnum, -} - -#[derive(FromArgs, PartialEq, Debug)] -#[argh(subcommand)] -enum MySubCommandEnum { - One(SubCommandOne), - Two(SubCommandTwo), -} - -#[derive(FromArgs, PartialEq, Debug)] -/// First subcommand. -#[argh(subcommand, name = "one")] -struct SubCommandOne { - #[argh(option)] - /// how many x - x: usize, -} - -#[derive(FromArgs, PartialEq, Debug)] -/// Second subcommand. -#[argh(subcommand, name = "two")] -struct SubCommandTwo { - #[argh(switch)] - /// whether to fooey - fooey: bool, -} - - -```rust -# use argh::FromArgs; +use argh::FromArgs; #[derive(FromArgs, PartialEq, Debug)] /// Top-level command. diff --git a/third_party/rust_crates/vendor/argh/rustfmt.toml b/third_party/rust_crates/vendor/argh/rustfmt.toml new file mode 100644 index 000000000000..57d994260964 --- /dev/null +++ b/third_party/rust_crates/vendor/argh/rustfmt.toml @@ -0,0 +1,15 @@ +# Fuchsia Format Style +# last reviewed: Jan 29, 2019 + +# Fuchsia uses 2018 edition only +edition = "2018" + +# The "Default" setting has a heuristic which splits lines too aggresively. +# We are willing to revisit this setting in future versions of rustfmt. +# Bugs: +# * https://github.com/rust-lang/rustfmt/issues/3119 +# * https://github.com/rust-lang/rustfmt/issues/3120 +use_small_heuristics = "Max" + +# Prevent carriage returns +newline_style = "Unix" diff --git a/third_party/rust_crates/vendor/argh/src/lib.rs b/third_party/rust_crates/vendor/argh/src/lib.rs index 95021c50e631..94e2f5ed99a2 100644 --- a/third_party/rust_crates/vendor/argh/src/lib.rs +++ b/third_party/rust_crates/vendor/argh/src/lib.rs @@ -60,7 +60,36 @@ //! Options, like `height` and `pilot_nickname`, can be either required, //! optional, or repeating, depending on whether they are contained in an //! `Option` or a `Vec`. Default values can be provided using the -//! `#[argh(default = "")]` attribute. +//! `#[argh(default = "")]` attribute, and in this case an +//! option is treated as optional. +//! +//! ```rust +//! use argh::FromArgs; +//! +//! fn default_height() -> usize { +//! 5 +//! } +//! +//! #[derive(FromArgs)] +//! /// Reach new heights. +//! struct GoUp { +//! /// an optional nickname for the pilot +//! #[argh(option)] +//! pilot_nickname: Option, +//! +//! /// an optional height +//! #[argh(option, default = "default_height()")] +//! height: usize, +//! +//! /// an optional direction which is "up" by default +//! #[argh(option, default = "String::from(\"only up\")")] +//! direction: String, +//! } +//! +//! fn main() { +//! let up: GoUp = argh::from_env(); +//! } +//! ``` //! //! Custom option types can be deserialized so long as they implement the //! `FromArgValue` trait (automatically implemented for all `FromStr` types). @@ -98,7 +127,7 @@ //! ``` //! //! The last positional argument may include a default, or be wrapped in -//! `Option` or `Vec` to indicate an optional or repeating positional arugment. +//! `Option` or `Vec` to indicate an optional or repeating positional argument. //! //! Subcommands are also supported. To use a subcommand, declare a separate //! `FromArgs` type for each subcommand as well as an enum that cases @@ -201,14 +230,20 @@ impl From for EarlyExit { } } +/// Extract the base cmd from a path +fn cmd<'a>(default: &'a String, path: &'a String) -> &'a str { + std::path::Path::new(path).file_name().map(|s| s.to_str()).flatten().unwrap_or(default.as_str()) +} + /// Create a `FromArgs` type from the current process's `env::args`. /// /// This function will exit early from the current process if argument parsing /// was unsuccessful or if information like `--help` was requested. pub fn from_env() -> T { let strings: Vec = std::env::args().collect(); + let cmd = cmd(&strings[0], &strings[0]); let strs: Vec<&str> = strings.iter().map(|s| s.as_str()).collect(); - T::from_args(&[strs[0]], &strs[1..]).unwrap_or_else(|early_exit| { + T::from_args(&[cmd], &strs[1..]).unwrap_or_else(|early_exit| { println!("{}", early_exit.output); std::process::exit(match early_exit.status { Ok(()) => 0, @@ -226,8 +261,9 @@ pub fn from_env() -> T { /// was unsuccessful or if information like `--help` was requested. pub fn cargo_from_env() -> T { let strings: Vec = std::env::args().collect(); + let cmd = cmd(&strings[1], &strings[1]); let strs: Vec<&str> = strings.iter().map(|s| s.as_str()).collect(); - T::from_args(&[strs[1]], &strs[2..]).unwrap_or_else(|early_exit| { + T::from_args(&[cmd], &strs[2..]).unwrap_or_else(|early_exit| { println!("{}", early_exit.output); std::process::exit(match early_exit.status { Ok(()) => 0, @@ -307,7 +343,9 @@ impl ParseValueSlot for ParseValueSlotTy, T> { /// A type which can be the receiver of a `Flag`. pub trait Flag { /// Creates a default instance of the flag value; - fn default() -> Self where Self: Sized; + fn default() -> Self + where + Self: Sized; /// Sets the flag. This function is called when the flag is provided. fn set_flag(&mut self); } @@ -336,10 +374,7 @@ macro_rules! impl_flag_for_integers { } } -impl_flag_for_integers![ - u8, u16, u32, u64, u128, - i8, i16, i32, i64, i128, -]; +impl_flag_for_integers![u8, u16, u32, u64, u128, i8, i16, i32, i64, i128,]; // `--` or `-` options, including a mutable reference to their value. #[doc(hidden)] @@ -393,9 +428,9 @@ pub fn parse_option( match &mut output_table[pos] { CmdOption::Flag(b) => b.set_flag(), CmdOption::Value(pvs) => { - let value = remaining_args.get(0).ok_or_else(|| { - ["No value provided for option '", arg, "'.\n"].concat() - })?; + let value = remaining_args + .get(0) + .ok_or_else(|| ["No value provided for option '", arg, "'.\n"].concat())?; *remaining_args = &remaining_args[1..]; pvs.fill_slot(value).map_err(|s| { ["Error parsing option '", arg, "' with value '", value, "': ", &s, "\n"].concat() @@ -417,7 +452,8 @@ pub fn parse_positional( ) -> Result<(), String> { let (slot, name) = positional; slot.fill_slot(arg).map_err(|s| { - ["Error parsing positional argument '", name, "' with value '", arg, ": ", &s].concat() + ["Error parsing positional argument '", name, "' with value '", arg, "': ", &s, "\n"] + .concat() }) } @@ -481,9 +517,7 @@ impl MissingRequirements { // describing the missing args. #[doc(hidden)] pub fn err_on_any(&self) -> Result<(), String> { - if self.options.is_empty() - && self.subcommands.is_none() - && self.positional_args.is_empty() + if self.options.is_empty() && self.subcommands.is_none() && self.positional_args.is_empty() { return Ok(()); } @@ -499,6 +533,9 @@ impl MissingRequirements { } if !self.options.is_empty() { + if !self.positional_args.is_empty() { + output.push_str("\n"); + } output.push_str("Required options not provided:"); for option in &self.options { output.push_str(NEWLINE_INDENT); @@ -524,3 +561,16 @@ impl MissingRequirements { Err(output) } } + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test_cmd_extraction() { + let expected = "test_cmd"; + let path = format!("/tmp/{}", expected); + let cmd = cmd(&path, &path); + assert_eq!(expected, cmd); + } +} diff --git a/third_party/rust_crates/vendor/argh/tests/lib.rs b/third_party/rust_crates/vendor/argh/tests/lib.rs index 7cfa7df094a1..b27f3efec018 100644 --- a/third_party/rust_crates/vendor/argh/tests/lib.rs +++ b/third_party/rust_crates/vendor/argh/tests/lib.rs @@ -3,7 +3,6 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. - use {argh::FromArgs, std::fmt::Debug}; #[test] @@ -207,6 +206,28 @@ fn assert_error(args: &[&str], err_msg: &str) { e.status.expect_err("error had a positive status"); } +mod options { + use super::*; + + #[derive(argh::FromArgs, Debug, PartialEq)] + /// Woot + struct Parsed { + #[argh(option, short = 'n')] + /// fooey + n: usize, + } + + #[test] + fn parsed() { + assert_output(&["-n", "5"], Parsed { n: 5 }); + assert_error::( + &["-n", "x"], + r###"Error parsing option '-n' with value 'x': invalid digit found in string +"###, + ); + } +} + mod positional { use super::*; @@ -305,6 +326,49 @@ Options: ); } + #[derive(argh::FromArgs, Debug, PartialEq)] + /// Woot + struct Parsed { + #[argh(positional)] + /// fooey + n: usize, + } + + #[test] + fn parsed() { + assert_output(&["5"], Parsed { n: 5 }); + assert_error::( + &["x"], + r###"Error parsing positional argument 'n' with value 'x': invalid digit found in string +"###, + ); + } + + #[derive(FromArgs, Debug, PartialEq)] + /// Woot + struct WithOption { + #[argh(positional)] + /// fooey + a: String, + #[argh(option)] + /// fooey + b: String, + } + + #[test] + fn mixed_with_option() { + assert_output(&["first", "--b", "foo"], WithOption { a: "first".into(), b: "foo".into() }); + + assert_error::( + &[], + r###"Required positional arguments not provided: + a +Required options not provided: + --b +"###, + ); + } + #[derive(FromArgs, Debug, PartialEq)] /// Woot struct WithSubcommand { @@ -483,7 +547,28 @@ mod fuchsia_commandline_tools_rubric { /// even when their syntax matches that of options. e.g. `foo -- -e` should be parsed /// as passing a single positional argument with the value `-e`. #[test] - fn double_dash_positional() {} + fn double_dash_positional() { + #[derive(FromArgs, Debug, PartialEq)] + /// Positional arguments list + struct StringList { + #[argh(positional)] + /// a list of strings + strs: Vec, + + #[argh(switch)] + /// some flag + flag: bool, + } + + assert_output( + &["--", "a", "-b", "--flag"], + StringList { strs: vec!["a".into(), "-b".into(), "--flag".into()], flag: false }, + ); + assert_output( + &["--flag", "--", "-a", "b"], + StringList { strs: vec!["-a".into(), "b".into()], flag: true }, + ); + } /// Double-dash can be parsed into an optional field using a provided /// `fn(&[&str]) -> Result`. diff --git a/third_party/rust_crates/vendor/argh_derive/.cargo-checksum.json b/third_party/rust_crates/vendor/argh_derive/.cargo-checksum.json index 68d586ffd074..22bf06d29aa7 100644 --- a/third_party/rust_crates/vendor/argh_derive/.cargo-checksum.json +++ b/third_party/rust_crates/vendor/argh_derive/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"cc3362f94081751b80003fa838e0693cb123fa48119fbe47f3c9b5a97fc847e7","LICENSE":"03b114f53e6587a398931762ee11e2395bfdba252a329940e2c8c9e81813845b","src/errors.rs":"82164df72b94a0eb28b51028d104d4b06e144221f22ba692a340d4611f3f169a","src/help.rs":"e757e52210dc6d2a27b6ccfedbeeb11ce71a184a3205bd486332315f9e71497f","src/lib.rs":"8be7d5f341ea82bb1a2223ee73eba203a641960099122a1100d7c4fe7c482375","src/parse_attrs.rs":"4e1eb6b5e507746f3010d7b0ed5b91f3d960b63c1d9764f4505ba7bd8b4e744a"},"package":"e742194e0f43fc932bcb801708c2b279d3ec8f527e3acda05a6a9f342c5ef764"} \ No newline at end of file +{"files":{"Cargo.toml":"808a079582af4921af21b52b9325fa001caae56fa92ca9a6d44d388e564c81aa","LICENSE":"03b114f53e6587a398931762ee11e2395bfdba252a329940e2c8c9e81813845b","src/errors.rs":"82164df72b94a0eb28b51028d104d4b06e144221f22ba692a340d4611f3f169a","src/help.rs":"e757e52210dc6d2a27b6ccfedbeeb11ce71a184a3205bd486332315f9e71497f","src/lib.rs":"f50733b9dd1852ffe51682607cee9b660056e9b0bba65929ee16c61c4f797967","src/parse_attrs.rs":"1b338692e11de3306fa81377eaef5207c747f5301fa3c17a18602068774c4105"},"package":"c4eb0c0c120ad477412dc95a4ce31e38f2113e46bd13511253f79196ca68b067"} \ No newline at end of file diff --git a/third_party/rust_crates/vendor/argh_derive/Cargo.toml b/third_party/rust_crates/vendor/argh_derive/Cargo.toml index cfdadba0bdd4..2f44470a8198 100644 --- a/third_party/rust_crates/vendor/argh_derive/Cargo.toml +++ b/third_party/rust_crates/vendor/argh_derive/Cargo.toml @@ -13,8 +13,8 @@ [package] edition = "2018" name = "argh_derive" -version = "0.1.1" -authors = ["Taylor Cramer ", "Benjamin Brittain"] +version = "0.1.4" +authors = ["Taylor Cramer ", "Benjamin Brittain ", "Erick Tryzelaar "] description = "Derive-based argument parsing optimized for code size" license = "BSD-3-Clause" repository = "https://github.com/google/argh" @@ -22,7 +22,7 @@ repository = "https://github.com/google/argh" [lib] proc-macro = true [dependencies.argh_shared] -version = "0.1.1" +version = "0.1.4" [dependencies.heck] version = "0.3.1" diff --git a/third_party/rust_crates/vendor/argh_derive/src/lib.rs b/third_party/rust_crates/vendor/argh_derive/src/lib.rs index 8d158718fd32..27287a34ad61 100644 --- a/third_party/rust_crates/vendor/argh_derive/src/lib.rs +++ b/third_party/rust_crates/vendor/argh_derive/src/lib.rs @@ -326,6 +326,7 @@ fn impl_from_args_struct( let mut __help = false; let mut __remaining_args = __args; let mut __positional_index = 0; + let mut __options_ended = false; 'parse_args: while let Some(&__next_arg) = __remaining_args.get(0) { __remaining_args = &__remaining_args[1..]; if __next_arg == "--help" || __next_arg == "help" { @@ -333,7 +334,12 @@ fn impl_from_args_struct( continue; } - if __next_arg.starts_with("-") { + if __next_arg.starts_with("-") && !__options_ended { + if __next_arg == "--" { + __options_ended = true; + continue; + } + if __help { return Err( "Trailing arguments are not allowed after `help`." diff --git a/third_party/rust_crates/vendor/argh_derive/src/parse_attrs.rs b/third_party/rust_crates/vendor/argh_derive/src/parse_attrs.rs index df69ffd55190..3fb79de79f84 100644 --- a/third_party/rust_crates/vendor/argh_derive/src/parse_attrs.rs +++ b/third_party/rust_crates/vendor/argh_derive/src/parse_attrs.rs @@ -134,7 +134,7 @@ impl FieldAttrs { FieldKind::SubCommand | FieldKind::Switch => errors.err( default, "`default` may only be specified on `#[argh(option)]` \ - or `#[argh(subcommand)]` fields", + or `#[argh(positional)]` fields", ), } } @@ -161,7 +161,7 @@ impl FieldAttrs { if !value.is_ascii() { errors.err(long, "Long names must be ASCII"); } - if !value.chars().all(|c| c.is_lowercase()) { + if !value.chars().all(|c| c.is_lowercase() || c == '-') { errors.err(long, "Long names must be lowercase"); } } diff --git a/third_party/rust_crates/vendor/argh_shared/.cargo-checksum.json b/third_party/rust_crates/vendor/argh_shared/.cargo-checksum.json index 11805308c5b5..17b280832eee 100644 --- a/third_party/rust_crates/vendor/argh_shared/.cargo-checksum.json +++ b/third_party/rust_crates/vendor/argh_shared/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"7ab8b47f089f503abf0de18464ab408d9be38ca047c4c8868b945add90227d31","LICENSE":"03b114f53e6587a398931762ee11e2395bfdba252a329940e2c8c9e81813845b","src/lib.rs":"b61c5423e9af692e919118f52e2d3bdaeaf72c4e20d1a4c5776c8b4eab62a78a"},"package":"e1ba68f4276a778591e36a0c348a269888f3a177c8d2054969389e3b59611ff5"} \ No newline at end of file +{"files":{"Cargo.toml":"fd3ee9ce0eeb0f8a1de92d31f52a3aa7bb85a6ac6b4846cafa81b6b5c9955384","LICENSE":"03b114f53e6587a398931762ee11e2395bfdba252a329940e2c8c9e81813845b","src/lib.rs":"b61c5423e9af692e919118f52e2d3bdaeaf72c4e20d1a4c5776c8b4eab62a78a"},"package":"781f336cc9826dbaddb9754cb5db61e64cab4f69668bd19dcc4a0394a86f4cb1"} \ No newline at end of file diff --git a/third_party/rust_crates/vendor/argh_shared/Cargo.toml b/third_party/rust_crates/vendor/argh_shared/Cargo.toml index 271836fd4a51..e2f5f1acea75 100644 --- a/third_party/rust_crates/vendor/argh_shared/Cargo.toml +++ b/third_party/rust_crates/vendor/argh_shared/Cargo.toml @@ -13,8 +13,8 @@ [package] edition = "2018" name = "argh_shared" -version = "0.1.1" -authors = ["Taylor Cramer ", "Benjamin Brittain"] +version = "0.1.4" +authors = ["Taylor Cramer ", "Benjamin Brittain ", "Erick Tryzelaar "] description = "Derive-based argument parsing optimized for code size" license = "BSD-3-Clause" repository = "https://github.com/google/argh"