atharvalade commented on code in PR #3096: URL: https://github.com/apache/iggy/pull/3096#discussion_r3190970917
########## core/cli/src/commands/binary_context/show_context.rs: ########## @@ -0,0 +1,114 @@ +/* Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +use anyhow::bail; +use async_trait::async_trait; +use comfy_table::Table; +use tracing::{Level, event}; + +use crate::commands::cli_command::{CliCommand, PRINT_TARGET}; +use iggy_common::Client; + +use super::common::{ContextConfig, ContextManager}; + +const MASKED_VALUE: &str = "********"; + +pub struct ShowContextCmd { + context_name: String, +} + +impl ShowContextCmd { + pub fn new(context_name: String) -> Self { + Self { context_name } + } + + fn build_table(name: &str, is_active: bool, config: &ContextConfig) -> Table { + let mut table = Table::new(); + table.set_header(vec!["Property", "Value"]); + + let display_name = if is_active { + format!("{name}*") + } else { + name.to_string() + }; + table.add_row(vec!["Name", &display_name]); + + if let Some(ref transport) = config.iggy.transport { + table.add_row(vec!["Transport", transport]); + } + if let Some(ref addr) = config.iggy.tcp_server_address { + table.add_row(vec!["TCP Server Address", addr]); + } + if let Some(ref url) = config.iggy.http_api_url { + table.add_row(vec!["HTTP API URL", url]); + } + if let Some(ref addr) = config.iggy.quic_server_address { + table.add_row(vec!["QUIC Server Address", addr]); + } + if let Some(tls) = config.iggy.tcp_tls_enabled { + table.add_row(vec!["TCP TLS Enabled", &tls.to_string()]); + } + if let Some(ref username) = config.username { + table.add_row(vec!["Username", username]); + } + if config.password.is_some() { + table.add_row(vec!["Password", MASKED_VALUE]); + } + if config.token.is_some() { + table.add_row(vec!["Token", MASKED_VALUE]); + } + if let Some(ref token_name) = config.token_name { + table.add_row(vec!["Token Name", token_name]); + } + + table + } +} + +#[async_trait] +impl CliCommand for ShowContextCmd { + fn explain(&self) -> String { + format!("show context \"{}\"", self.context_name) Review Comment: Switched to unquoted `format!("show context {context_name}")` to match siblings -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
