From 7adc312ccfbfb9d155d4197fca94cca57b732ef4 Mon Sep 17 00:00:00 2001 From: Joseph Shearer Date: Mon, 16 Sep 2024 15:23:46 -0400 Subject: [PATCH] refactor: Migrate `clap` to v4 --- Cargo.lock | 33 +++++++---------------- Cargo.toml | 2 +- crates/billing-integrations/src/stripe.rs | 4 +-- crates/flow_cli_common/src/lib.rs | 8 +++--- crates/flow_cli_common/src/logging.rs | 13 ++++----- crates/flowctl/src/auth/roles.rs | 4 +-- crates/flowctl/src/collection/read/mod.rs | 6 ++--- crates/flowctl/src/lib.rs | 8 +----- crates/flowctl/src/raw/mod.rs | 6 ++--- 9 files changed, 33 insertions(+), 51 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 31d7d74b6f..e38af894fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -110,7 +110,7 @@ dependencies = [ "build", "bytes", "chrono", - "clap 3.2.25", + "clap 4.5.17", "colored_json", "derivative", "doc", @@ -844,7 +844,7 @@ dependencies = [ "anyhow", "async-stripe", "chrono", - "clap 3.2.25", + "clap 4.5.17", "futures", "serde", "serde_json", @@ -1239,10 +1239,8 @@ checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" dependencies = [ "atty", "bitflags 1.3.2", - "clap_derive 3.2.25", "clap_lex 0.2.4", "indexmap 1.9.3", - "once_cell", "strsim 0.10.0", "termcolor", "textwrap 0.16.1", @@ -1255,7 +1253,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e5a21b8495e732f1b3c364c9949b201ca7bae518c502c80256c96ad79eaf6ac" dependencies = [ "clap_builder", - "clap_derive 4.5.13", + "clap_derive", ] [[package]] @@ -1270,19 +1268,6 @@ dependencies = [ "strsim 0.11.1", ] -[[package]] -name = "clap_derive" -version = "3.2.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae6371b8bdc8b7d3959e9cf7b22d4435ef3e79e138688421ec654acf8c81b008" -dependencies = [ - "heck 0.4.1", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "clap_derive" version = "4.5.13" @@ -1398,7 +1383,7 @@ dependencies = [ "async-process", "async-trait", "bytes", - "clap 3.2.25", + "clap 4.5.17", "futures", "insta", "ops", @@ -2265,7 +2250,7 @@ version = "0.0.0" dependencies = [ "anyhow", "atty", - "clap 3.2.25", + "clap 4.5.17", "tracing", "tracing-subscriber", ] @@ -2282,7 +2267,7 @@ dependencies = [ "build", "bytelines", "bytes", - "clap 3.2.25", + "clap 4.5.17", "comfy-table", "connector-init", "coroutines", @@ -4181,7 +4166,7 @@ dependencies = [ "caseless", "chardetng", "chrono", - "clap 3.2.25", + "clap 4.5.17", "criterion", "csv", "doc", @@ -5191,7 +5176,7 @@ dependencies = [ "assemble", "async-process", "bytes", - "clap 3.2.25", + "clap 4.5.17", "connector-init", "coroutines", "derive-sqlite", @@ -5429,7 +5414,7 @@ version = "0.0.0" dependencies = [ "anyhow", "bytes", - "clap 3.2.25", + "clap 4.5.17", "doc", "flow_cli_common", "indexmap 1.9.3", diff --git a/Cargo.toml b/Cargo.toml index 1e124c7731..11cb1ca206 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,7 @@ byteorder = "1.4" caseless = "0.2" chardetng = "0.1" chrono = { version = "0.4", features = ["serde"] } -clap = { version = "3.2", features = ["derive", "env"] } +clap = { package = "clap", version = "4", features = ["derive", "env"] } colored_json = "3" comfy-table = "6.1" # The `console_error_panic_hook` crate causes panics in a Rust WASM module to be logged diff --git a/crates/billing-integrations/src/stripe.rs b/crates/billing-integrations/src/stripe.rs index 5c6ff8283d..a9e84b2e2e 100644 --- a/crates/billing-integrations/src/stripe.rs +++ b/crates/billing-integrations/src/stripe.rs @@ -13,7 +13,7 @@ const INVOICE_TYPE_KEY: &str = "estuary.dev/invoice_type"; const BILLING_PERIOD_START_KEY: &str = "estuary.dev/period_start"; const BILLING_PERIOD_END_KEY: &str = "estuary.dev/period_end"; -#[derive(Debug, Clone, Copy, clap::ArgEnum)] +#[derive(Debug, Clone, Copy, clap::ValueEnum)] #[clap(rename_all = "kebab_case")] enum ChargeType { AutoCharge, @@ -37,7 +37,7 @@ pub struct PublishInvoice { #[clap(long, conflicts_with("tenants"))] all_tenants: bool, /// The month to generate invoices for, in format "YYYY-MM-DD" - #[clap(long, parse(try_from_str = parse_date))] + #[clap(long, value_parser = parse_date)] month: NaiveDate, /// Whether to delete and recreate finalized invoices #[clap(long)] diff --git a/crates/flow_cli_common/src/lib.rs b/crates/flow_cli_common/src/lib.rs index 3f5a997407..57185622d2 100644 --- a/crates/flow_cli_common/src/lib.rs +++ b/crates/flow_cli_common/src/lib.rs @@ -1,8 +1,6 @@ //! Contains helpers and things that are used by all Flow rust executables. mod logging; -use clap::AppSettings::NoAutoHelp; - pub use logging::{init_logging, LogArgs, LogFormat, LogLevel}; /// An arguments container that accepts all arguments verbatim. This is used by external @@ -10,7 +8,11 @@ pub use logging::{init_logging, LogArgs, LogFormat, LogLevel}; // These settings prevent clap from automatically using its own help // handling, so that --help and -h are simply forwarded to the external subcommand. #[derive(Debug, clap::Args)] -#[clap(setting = NoAutoHelp, disable_help_flag = true, allow_hyphen_values = true)] +#[clap( + disable_help_subcommand = true, + disable_help_flag = true, + allow_hyphen_values = true +)] pub struct ExternalArgs { pub args: Vec, } diff --git a/crates/flow_cli_common/src/logging.rs b/crates/flow_cli_common/src/logging.rs index 0e9f68f016..85e9d6cf85 100644 --- a/crates/flow_cli_common/src/logging.rs +++ b/crates/flow_cli_common/src/logging.rs @@ -5,20 +5,21 @@ #[derive(Debug, clap::Args)] pub struct LogArgs { /// The log verbosity. Can be one of trace|debug|info|warn|error|off - #[clap( + #[arg( long = "log.level", default_value_t = LogLevel::Warn, group = "logging", - ignore_case(true), - arg_enum, + ignore_case = true, + value_enum, global = true )] pub level: LogLevel, - #[clap(long = "log.format", arg_enum, group = "logging", global = true)] + + #[arg(long = "log.format", value_enum, global = true, group = "logging")] pub format: Option, } -#[derive(Debug, clap::ArgEnum, Clone, Copy)] +#[derive(Debug, clap::ValueEnum, Clone, Copy)] pub enum LogLevel { Trace, Debug, @@ -41,7 +42,7 @@ impl ToString for LogLevel { } /// The format for logs. -#[derive(Debug, clap::ArgEnum, Clone, Copy)] +#[derive(Debug, clap::ValueEnum, Clone, Copy)] pub enum LogFormat { /// Logs are written to stderr in jsonl format. This format is very compatible with Flow's log /// parsing, which means that they will get forwarded with the proper level and will retain the diff --git a/crates/flowctl/src/auth/roles.rs b/crates/flowctl/src/auth/roles.rs index 77372e3a99..132da95a8e 100644 --- a/crates/flowctl/src/auth/roles.rs +++ b/crates/flowctl/src/auth/roles.rs @@ -33,7 +33,7 @@ pub enum Command { Revoke(Revoke), } -#[derive(Debug, Copy, Clone, Serialize, Deserialize, clap::ArgEnum)] +#[derive(Debug, Copy, Clone, Serialize, Deserialize, clap::ValueEnum)] #[serde(rename_all = "camelCase")] enum Capability { Read, @@ -58,7 +58,7 @@ pub struct Grant { #[clap(long)] object_role: String, /// Granted capability of the subject to the object role. - #[clap(long, arg_enum)] + #[clap(long, value_enum)] capability: Capability, /// Free-form details of the grant, such as a reason or audit log message. #[clap(long)] diff --git a/crates/flowctl/src/collection/read/mod.rs b/crates/flowctl/src/collection/read/mod.rs index 81a1f25744..2ebc4ae953 100644 --- a/crates/flowctl/src/collection/read/mod.rs +++ b/crates/flowctl/src/collection/read/mod.rs @@ -54,9 +54,9 @@ pub async fn read_collection(ctx: &mut crate::CliContext, args: &ReadArgs) -> an .output .filter(|ot| *ot != OutputType::Json) { - let name = clap::ValueEnum::to_possible_value(&naughty_output_type) - .expect("possible value cannot be None") - .get_name(); + let clap_enum = clap::ValueEnum::to_possible_value(&naughty_output_type) + .expect("possible value cannot be None"); + let name = clap_enum.get_name(); anyhow::bail!( "cannot use --output {name} when reading collection data (only json is supported)" ); diff --git a/crates/flowctl/src/lib.rs b/crates/flowctl/src/lib.rs index d6fd75dac2..e967436543 100644 --- a/crates/flowctl/src/lib.rs +++ b/crates/flowctl/src/lib.rs @@ -1,7 +1,6 @@ use std::fmt::Debug; use anyhow::Context; -use clap::AppSettings; use clap::Parser; mod auth; @@ -26,12 +25,7 @@ use poll::poll_while_queued; /// A command-line tool for working with Estuary Flow. #[derive(Debug, Parser)] -#[clap( - author, - about, - version, - global_setting = AppSettings::DeriveDisplayOrder -)] +#[command(author, about, version, next_display_order = None)] pub struct Cli { /// Configuration profile to use. /// diff --git a/crates/flowctl/src/raw/mod.rs b/crates/flowctl/src/raw/mod.rs index 356deb26d8..9214e11c12 100644 --- a/crates/flowctl/src/raw/mod.rs +++ b/crates/flowctl/src/raw/mod.rs @@ -72,7 +72,7 @@ pub struct Get { #[clap(long)] table: String, /// Optional query parameters. - #[clap(long, parse(try_from_str = parse_key_val), number_of_values = 1)] + #[clap(long, value_parser = parse_key_val::, number_of_values = 1)] query: Vec<(String, String)>, } @@ -83,7 +83,7 @@ pub struct Update { #[clap(long)] table: String, /// Optional query parameters. - #[clap(long, parse(try_from_str = parse_key_val), number_of_values = 1)] + #[clap(long, value_parser = parse_key_val::, number_of_values = 1)] query: Vec<(String, String)>, /// Serialized JSON argument of the request. #[clap(long)] @@ -97,7 +97,7 @@ pub struct Rpc { #[clap(long)] function: String, /// Optional query parameters. - #[clap(long, parse(try_from_str = parse_key_val), number_of_values = 1)] + #[clap(long, value_parser = parse_key_val::, number_of_values = 1)] query: Vec<(String, String)>, /// Serialized JSON argument of the request. #[clap(long)]