diff --git a/influxdb_iox/src/commands/namespace/mod.rs b/influxdb_iox/src/commands/namespace/mod.rs index 9edb414fbb..47b191f5f2 100644 --- a/influxdb_iox/src/commands/namespace/mod.rs +++ b/influxdb_iox/src/commands/namespace/mod.rs @@ -16,9 +16,6 @@ pub enum Error { #[error("Client error: {0}")] ClientError(#[from] influxdb_iox_client::error::Error), - - #[error("No valid limit was provided")] - InvalidLimit, } pub type Result = std::result::Result; diff --git a/influxdb_iox/src/commands/namespace/update_limit.rs b/influxdb_iox/src/commands/namespace/update_limit.rs index 2aefa70305..7c2734ee0a 100644 --- a/influxdb_iox/src/commands/namespace/update_limit.rs +++ b/influxdb_iox/src/commands/namespace/update_limit.rs @@ -1,7 +1,7 @@ use influxdb_iox_client::connection::Connection; use influxdb_iox_client::namespace::generated_types::LimitUpdate; -use crate::commands::namespace::{Error, Result}; +use crate::commands::namespace::Result; #[derive(Debug, clap::Parser)] pub struct Config { @@ -15,6 +15,12 @@ pub struct Config { #[derive(Debug, clap::Args)] #[clap(group( + // This arg group "limit" links the members of the below struct + // named "max_tables" and "max_columns_per_table" together as + // mutually exclusive flags. As we specify all flags & commands + // using clap-derive rather than the imperative builder, v3 only + // properly supports this kind of behaviour in a macro code block. + // NOTE: It takes the variable names and not the flag long names. clap::ArgGroup::new("limit") .required(true) .args(&["max_tables", "max_columns_per_table"]) @@ -29,22 +35,20 @@ struct Args { max_columns_per_table: Option, } -impl TryFrom for LimitUpdate { - type Error = Error; - fn try_from(args: Args) -> Result { +impl From for LimitUpdate { + fn from(args: Args) -> Self { let Args { max_tables, max_columns_per_table, } = args; if let Some(n) = max_tables { - return Ok(Self::MaxTables(n)); + return Self::MaxTables(n); } if let Some(n) = max_columns_per_table { - return Ok(Self::MaxColumnsPerTable(n)); + return Self::MaxColumnsPerTable(n); } - - Err(Error::InvalidLimit) + unreachable!(); } } @@ -54,7 +58,7 @@ pub async fn command(connection: Connection, config: Config) -> Result<()> { let namespace = client .update_namespace_service_protection_limit( &config.namespace, - LimitUpdate::try_from(config.args)?, + LimitUpdate::from(config.args), ) .await?; println!("{}", serde_json::to_string_pretty(&namespace)?);