Skip to content

Commit

Permalink
Various small stacklet command output improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Techassi committed Sep 26, 2023
1 parent 0f35450 commit 6afb3d8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
3 changes: 2 additions & 1 deletion extra/completions/_stackablectl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion extra/completions/stackablectl.bash

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion extra/completions/stackablectl.fish

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 14 additions & 13 deletions rust/stackablectl/src/cmds/stacklet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use crate::{
utils::use_colored_output,
};

const CREDENTIALS_HINT: &str = "Use \"stackablectl stacklet credentials [OPTIONS] <PRODUCT_NAME> <STACKLET_NAME>\" to display credentials for deployed stacklets.";

#[derive(Debug, Args)]
pub struct StackletArgs {
#[command(subcommand)]
Expand All @@ -41,13 +43,13 @@ pub struct StackletCredentialsArgs {
/// The name of the product, for example 'superset'.
product_name: String,

/// The name of the stacklet, for example 'superset'. Doesn't need to be passed if
/// the product and stacklet name are the same.
stacklet_name: Option<String>,
/// The name of the stacklet, for example 'superset'.
stacklet_name: String,

/// Namespace in the cluster used to deploy the products.
#[arg(
long,
short = 'n',
global = true,
default_value = DEFAULT_PRODUCT_NAMESPACE,
visible_aliases(["product-ns"]),
Expand Down Expand Up @@ -173,7 +175,7 @@ async fn list_cmd(args: &StackletListArgs, common_args: &Cli) -> Result<String,

// Only output the error list if there are errors to report.
Ok(format!(
"{table}{errors}",
"{table}{errors}\n\n{CREDENTIALS_HINT}",
errors = if !error_list.is_empty() {
format!("\n\n{}", error_list.join("\n"))
} else {
Expand All @@ -190,14 +192,13 @@ async fn list_cmd(args: &StackletListArgs, common_args: &Cli) -> Result<String,
async fn credentials_cmd(args: &StackletCredentialsArgs) -> Result<String, CmdError> {
info!("Displaying stacklet credentials");

let stacklet_name = args
.stacklet_name
.clone()
.unwrap_or(args.product_name.clone());

match get_credentials_for_product(&args.product_namespace, &stacklet_name, &args.product_name)
.await
.context(StackletCredentialsSnafu)?
match get_credentials_for_product(
&args.product_namespace,
&args.stacklet_name,
&args.product_name,
)
.await
.context(StackletCredentialsSnafu)?
{
Some(credentials) => {
let mut table = Table::new();
Expand All @@ -210,7 +211,7 @@ async fn credentials_cmd(args: &StackletCredentialsArgs) -> Result<String, CmdEr

let output = format!(
"Credentials for {} ({}) in namespace '{}':",
args.product_name, stacklet_name, args.product_namespace
args.product_name, args.stacklet_name, args.product_namespace
);

Ok(format!("{}\n\n{}", output, table))
Expand Down

0 comments on commit 6afb3d8

Please sign in to comment.