From a80f670e07c04537dfd56e13da3c09c3f2bc04d8 Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Fri, 11 Nov 2022 12:34:12 +0100 Subject: [PATCH 1/2] Bump clap to 4.0 --- CHANGELOG.md | 2 ++ Cargo.toml | 2 +- src/cli.rs | 31 ++++++++++++++++++------------- src/logging/mod.rs | 2 +- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index abc2ae97e..3bf4302c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,10 @@ All notable changes to this project will be documented in this file. ### Changed - BREAKING: `get_recommended_labels` and `with_recommended_labels` now takes a struct of named arguments ([#501]). +- Bump clap to 4.0 ([#503]). [#501]: https://github.com/stackabletech/operator-rs/pull/501 +[#503]: https://github.com/stackabletech/operator-rs/pull/503 ## [0.26.1] - 2022-11-08 diff --git a/Cargo.toml b/Cargo.toml index 796650908..49afb2d0b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ repository = "https://github.com/stackabletech/operator-rs" [dependencies] chrono = { version = "0.4.22", default-features = false } -clap = { version = "3.2.23", features = ["derive", "cargo", "env"] } +clap = { version = "4.0.22", features = ["derive", "cargo", "env"] } const_format = "0.2.30" either = "1.8.0" futures = "0.3.25" diff --git a/src/cli.rs b/src/cli.rs index 8106460bb..6ffde607a 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -40,7 +40,7 @@ //! } //! //! #[derive(clap::Parser)] -//! #[clap( +//! #[command( //! name = "Foobar Operator", //! author, //! version, @@ -52,7 +52,7 @@ //! } //! //! # fn main() -> OperatorResult<()> { -//! let opts = Opts::from_args(); +//! let opts = Opts::parse(); //! //! match opts.command { //! cli::Command::Crd => { @@ -75,7 +75,7 @@ //! use stackable_operator::error::OperatorResult; //! //! #[derive(clap::Parser)] -//! #[clap( +//! #[command( //! name = "Foobar Operator", //! author, //! version, @@ -87,7 +87,7 @@ //! } //! //! # fn main() -> OperatorResult<()> { -//! let opts = Opts::from_args(); +//! let opts = Opts::parse(); //! //! match opts.command { //! cli::Command::Crd => { @@ -133,7 +133,7 @@ pub const AUTHOR: &str = "Stackable GmbH - info@stackable.de"; #[derive(clap::Parser, Debug, PartialEq, Eq)] // The enum-level doccomment is intended for developers, not end users // so supress it from being included in --help -#[clap(long_about = "")] +#[command(long_about = "")] pub enum Command { /// Print CRD objects Crd, @@ -174,7 +174,7 @@ pub enum Command { /// # use stackable_operator::cli::{Command, ProductOperatorRun}; /// #[derive(clap::Parser, Debug, PartialEq, Eq)] /// struct Run { -/// #[clap(long)] +/// #[arg(long)] /// name: String, /// } /// use clap::Parser; @@ -184,28 +184,27 @@ pub enum Command { /// })); /// ``` #[derive(clap::Parser, Debug, PartialEq, Eq)] -#[clap(long_about = "")] +#[command(long_about = "")] pub struct ProductOperatorRun { /// Provides the path to a product-config file - #[clap( + #[arg( long, short = 'p', value_name = "FILE", default_value = "", - env, - parse(from_os_str) + env )] pub product_config: ProductConfigPath, /// Provides a specific namespace to watch (instead of watching all namespaces) - #[clap(long, env, default_value = "", parse(from_str))] + #[arg(long, env, default_value = "")] pub watch_namespace: WatchNamespace, /// Tracing log collector system - #[clap(long, env, default_value_t, arg_enum)] + #[arg(long, env, default_value_t, value_enum)] pub tracing_target: TracingTarget, } /// A path to a [`ProductConfigManager`] spec file -#[derive(Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct ProductConfigPath { path: Option, } @@ -274,6 +273,12 @@ mod tests { const DEFAULT_FILE_PATH: &str = "default_file_path_properties.yaml"; const WATCH_NAMESPACE: &str = "WATCH_NAMESPACE"; + #[test] + fn verify_cli() { + use clap::CommandFactory; + ProductOperatorRun::command().debug_assert() + } + #[rstest] #[case( Some(USER_PROVIDED_PATH), diff --git a/src/logging/mod.rs b/src/logging/mod.rs index c87dc1f0d..4fe77872a 100644 --- a/src/logging/mod.rs +++ b/src/logging/mod.rs @@ -4,7 +4,7 @@ use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilte pub mod controller; mod k8s_events; -#[derive(Debug, Clone, clap::ArgEnum, PartialEq, Eq)] +#[derive(Debug, Clone, clap::ValueEnum, PartialEq, Eq)] pub enum TracingTarget { None, Jaeger, From d7665b1cadefa15021997a9f3309732c163d64f3 Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Fri, 11 Nov 2022 12:41:42 +0100 Subject: [PATCH 2/2] format --- src/cli.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 6ffde607a..59353cb6c 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -187,13 +187,7 @@ pub enum Command { #[command(long_about = "")] pub struct ProductOperatorRun { /// Provides the path to a product-config file - #[arg( - long, - short = 'p', - value_name = "FILE", - default_value = "", - env - )] + #[arg(long, short = 'p', value_name = "FILE", default_value = "", env)] pub product_config: ProductConfigPath, /// Provides a specific namespace to watch (instead of watching all namespaces) #[arg(long, env, default_value = "")]