From 803f10f82dee573817b12fb762ee4ea0a281da7d Mon Sep 17 00:00:00 2001 From: Alexander Galibey Date: Fri, 10 Nov 2023 13:12:19 +0400 Subject: [PATCH] add feature guards to support minimal cli version --- Cargo.lock | 1 + crates/fluvio-cli/Cargo.toml | 1 + crates/fluvio-cli/src/profile/add.rs | 14 +++++--- crates/fluvio-cli/src/profile/list.rs | 51 +++++++++++++++++++-------- 4 files changed, 48 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8a8a30d3b6..78a2bd8efc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2586,6 +2586,7 @@ dependencies = [ "async-trait", "atty", "bytesize", + "cfg-if", "clap", "clap_complete", "colored", diff --git a/crates/fluvio-cli/Cargo.toml b/crates/fluvio-cli/Cargo.toml index bcdc356e39..e4bb500f73 100644 --- a/crates/fluvio-cli/Cargo.toml +++ b/crates/fluvio-cli/Cargo.toml @@ -75,6 +75,7 @@ tokio = { workspace = true, features = ["macros"] } tracing = { workspace = true } which = { workspace = true } url = { workspace = true } +cfg-if = { workspace = true } # Fluvio dependencies k8-config = { workspace = true, optional = true } diff --git a/crates/fluvio-cli/src/profile/add.rs b/crates/fluvio-cli/src/profile/add.rs index 51b653e91e..b01426e964 100644 --- a/crates/fluvio-cli/src/profile/add.rs +++ b/crates/fluvio-cli/src/profile/add.rs @@ -2,7 +2,6 @@ use clap::Parser; use anyhow::Result; use fluvio::config::{ConfigFile, TlsPolicy}; -use fluvio_cluster::InstallationType; #[derive(Debug, Parser)] pub struct ManualAddOpt { @@ -13,7 +12,8 @@ pub struct ManualAddOpt { cluster_address: String, /// Installation type of cluster, e.g. local, local-k8, k8 - installation_type: Option, + #[cfg(feature = "k8s")] + installation_type: Option, } // todo: p2 add tls config, p1 is default disabled for manual add @@ -27,9 +27,13 @@ impl ManualAddOpt { &self.cluster_address, &def_tls, )?; - let config = config_file.mut_config().current_cluster_mut()?; - self.installation_type.unwrap_or_default().save_to(config)?; - config_file.save()?; + cfg_if::cfg_if! { + if #[cfg(feature = "k8s")] { + let config = config_file.mut_config().current_cluster_mut()?; + self.installation_type.unwrap_or_default().save_to(config)?; + config_file.save()?; + } + } println!("Switched to profile {}", &self.profile_name); } Err(_) => println!("no profile can be found"), diff --git a/crates/fluvio-cli/src/profile/list.rs b/crates/fluvio-cli/src/profile/list.rs index ba1da68a45..8906965df9 100644 --- a/crates/fluvio-cli/src/profile/list.rs +++ b/crates/fluvio-cli/src/profile/list.rs @@ -1,6 +1,5 @@ use std::sync::Arc; -use fluvio_cluster::InstallationType; use serde::Serialize; use comfy_table::Row; use clap::Parser; @@ -50,10 +49,16 @@ fn format_tls(tls: &TlsPolicy) -> &'static str { } impl TableOutputHandler for ListConfig<'_> { + #[cfg(feature = "k8s")] fn header(&self) -> Row { Row::from(["", "PROFILE", "CLUSTER", "ADDRESS", "TLS", "INSTALLATION"]) } + #[cfg(not(feature = "k8s"))] + fn header(&self) -> Row { + Row::from(["", "PROFILE", "CLUSTER", "ADDRESS", "TLS"]) + } + fn content(&self) -> Vec { self.0 .profile @@ -66,20 +71,38 @@ impl TableOutputHandler for ListConfig<'_> { .map(|active| if active { "*" } else { "" }) .unwrap_or(""); - let (cluster, addr, tls, installation_type) = self - .0 - .cluster(&profile.cluster) - .map(|it| { - ( - &*profile.cluster, - &*it.endpoint, - format_tls(&it.tls), - InstallationType::load_or_default(it).to_string(), - ) - }) - .unwrap_or(("", "", "", "".to_string())); + cfg_if::cfg_if! { + if #[cfg(feature = "k8s")] { + let (cluster, addr, tls, installation_type) = self + .0 + .cluster(&profile.cluster) + .map(|it| { + ( + &*profile.cluster, + &*it.endpoint, + format_tls(&it.tls), + fluvio_cluster::InstallationType::load_or_default(it).to_string(), + ) + }) + .unwrap_or(("", "", "", "".to_string())); + + Row::from([active, profile_name, cluster, addr, tls, &installation_type]) + } else { + let (cluster, addr, tls) = self + .0 + .cluster(&profile.cluster) + .map(|it| { + ( + &*profile.cluster, + &*it.endpoint, + format_tls(&it.tls), + ) + }) + .unwrap_or(("", "", "")); - Row::from([active, profile_name, cluster, addr, tls, &installation_type]) + Row::from([active, profile_name, cluster, addr, tls]) + } + } }) .collect() }