diff --git a/CHANGELOG.md b/CHANGELOG.md index e160e64e4..35d89f8d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,9 +8,11 @@ All notable changes to this project will be documented in this file. - BREAKING: `get_recommended_labels` and `with_recommended_labels` now takes a struct of named arguments ([#501]). - Bump opentelemetry crates ([#502]). +- Bump clap to 4.0 ([#503]). [#501]: https://github.com/stackabletech/operator-rs/pull/501 [#502]: https://github.com/stackabletech/operator-rs/pull/502 +[#503]: https://github.com/stackabletech/operator-rs/pull/503 ## [0.26.1] - 2022-11-08 diff --git a/Cargo.toml b/Cargo.toml index 8b422ab20..8ccc53bf0 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..59353cb6c 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,21 @@ 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( - long, - short = 'p', - value_name = "FILE", - default_value = "", - env, - parse(from_os_str) - )] + #[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) - #[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 +267,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 f85ad1005..99f197f7b 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,