From be814f41344872c1a43f6104a68c258fdecabdfa Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Thu, 19 Oct 2023 13:05:46 +0100 Subject: Upgrade argh_shared to 0.1.12 This project was upgraded with external_updater. Usage: tools/external_updater/updater.sh update rust/crates/argh_shared For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md Bug: 306205011 Test: TreeHugger Change-Id: I8202b08548faf43f50b44fa51b489d23444a774c --- .cargo_vcs_info.json | 2 +- Android.bp | 5 ++- Cargo.toml | 6 ++- Cargo.toml.orig | 5 ++- METADATA | 10 ++--- src/lib.rs | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 127 insertions(+), 9 deletions(-) diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 18c719f..7d20ae0 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "3f3c29726a21c4b541bb2b9aa2c592461897ded0" + "sha1": "e8efc8285f632a4ebedfe4377e0f1d78276f8e19" }, "path_in_vcs": "argh_shared" } \ No newline at end of file diff --git a/Android.bp b/Android.bp index e82a725..81f57ce 100644 --- a/Android.bp +++ b/Android.bp @@ -23,9 +23,12 @@ rust_library { host_supported: true, crate_name: "argh_shared", cargo_env_compat: true, - cargo_pkg_version: "0.1.10", + cargo_pkg_version: "0.1.12", srcs: ["src/lib.rs"], edition: "2018", + rustlibs: [ + "libserde", + ], apex_available: [ "//apex_available:platform", "com.android.virt", diff --git a/Cargo.toml b/Cargo.toml index 6dd113e..2463da8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ [package] edition = "2018" name = "argh_shared" -version = "0.1.10" +version = "0.1.12" authors = [ "Taylor Cramer ", "Benjamin Brittain ", @@ -22,3 +22,7 @@ description = "Derive-based argument parsing optimized for code size" readme = "README.md" license = "BSD-3-Clause" repository = "https://github.com/google/argh" + +[dependencies.serde] +version = "1" +features = ["derive"] diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 0f4478a..8e07308 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,9 +1,12 @@ [package] name = "argh_shared" -version = "0.1.10" +version = "0.1.12" authors = ["Taylor Cramer ", "Benjamin Brittain ", "Erick Tryzelaar "] edition = "2018" license = "BSD-3-Clause" description = "Derive-based argument parsing optimized for code size" repository = "https://github.com/google/argh" readme = "README.md" + +[dependencies] +serde = { version = "1", features = ["derive"] } diff --git a/METADATA b/METADATA index 0e881d1..1d5719e 100644 --- a/METADATA +++ b/METADATA @@ -1,6 +1,6 @@ # This project was upgraded with external_updater. # Usage: tools/external_updater/updater.sh update rust/crates/argh_shared -# For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md +# For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md name: "argh_shared" description: "Derive-based argument parsing optimized for code size" @@ -11,13 +11,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/argh_shared/argh_shared-0.1.10.crate" + value: "https://static.crates.io/crates/argh_shared/argh_shared-0.1.12.crate" } - version: "0.1.10" + version: "0.1.12" license_type: NOTICE last_upgrade_date { year: 2023 - month: 2 - day: 1 + month: 10 + day: 19 } } diff --git a/src/lib.rs b/src/lib.rs index c6e7a5c..20383a4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,114 @@ pub struct CommandInfo<'a> { pub description: &'a str, } +/// Information about the command line arguments for a given command. +#[derive(Debug, Default, PartialEq, Eq, Clone, serde::Serialize)] +pub struct CommandInfoWithArgs<'a> { + /// The name of the command. + pub name: &'a str, + /// A short description of the command's functionality. + pub description: &'a str, + /// Examples of usage + pub examples: &'a [&'a str], + /// Flags + pub flags: &'a [FlagInfo<'a>], + /// Notes about usage + pub notes: &'a [&'a str], + /// The subcommands. + pub commands: Vec>, + /// Positional args + pub positionals: &'a [PositionalInfo<'a>], + /// Error code information + pub error_codes: &'a [ErrorCodeInfo<'a>], +} + +/// Information about a documented error code. +#[derive(Debug, PartialEq, Eq, serde::Serialize)] +pub struct ErrorCodeInfo<'a> { + /// The code value. + pub code: i32, + /// Short description about what this code indicates. + pub description: &'a str, +} + +/// Information about positional arguments +#[derive(Debug, PartialEq, Eq, serde::Serialize)] +pub struct PositionalInfo<'a> { + /// Name of the argument. + pub name: &'a str, + /// Description of the argument. + pub description: &'a str, + /// Optionality of the argument. + pub optionality: Optionality, + /// Visibility in the help for this argument. + /// `false` indicates this argument will not appear + /// in the help message. + pub hidden: bool, +} + +/// Information about a subcommand. +/// Dynamic subcommands do not implement +/// get_args_info(), so the command field +/// only contains the name and description. +#[derive(Debug, Default, PartialEq, Eq, Clone, serde::Serialize)] +pub struct SubCommandInfo<'a> { + /// The subcommand name. + pub name: &'a str, + /// The information about the subcommand. + pub command: CommandInfoWithArgs<'a>, +} + +/// Information about a flag or option. +#[derive(Debug, Default, PartialEq, Eq, serde::Serialize)] +pub struct FlagInfo<'a> { + /// The kind of flag. + pub kind: FlagInfoKind<'a>, + /// The optionality of the flag. + pub optionality: Optionality, + /// The long string of the flag. + pub long: &'a str, + /// The single character short indicator + /// for trhis flag. + pub short: Option, + /// The description of the flag. + pub description: &'a str, + /// Visibility in the help for this argument. + /// `false` indicates this argument will not appear + /// in the help message. + pub hidden: bool, +} + +/// The kind of flags. +#[derive(Debug, Default, PartialEq, Eq, serde::Serialize)] +pub enum FlagInfoKind<'a> { + /// switch represents a boolean flag, + #[default] + Switch, + /// option is a flag that also has an associated + /// value. This value is named `arg_name`. + Option { arg_name: &'a str }, +} + +/// The optionality defines the requirments related +/// to the presence of the argument on the command line. +#[derive(Debug, Default, PartialEq, Eq, serde::Serialize)] +pub enum Optionality { + /// Required indicates the argument is required + /// exactly once. + #[default] + Required, + /// Optional indicates the argument may or may not + /// be present. + Optional, + /// Repeating indicates the argument may appear zero + /// or more times. + Repeating, + /// Greedy is used for positional arguments which + /// capture the all command line input upto the next flag or + /// the end of the input. + Greedy, +} + pub const INDENT: &str = " "; const DESCRIPTION_INDENT: usize = 20; const WRAP_WIDTH: usize = 80; -- cgit v1.2.3