From 67e0111af7483efdab14743f5e10897054db96a2 Mon Sep 17 00:00:00 2001 From: Omar Ali <524542+omar711@users.noreply.github.com> Date: Wed, 11 Oct 2023 23:18:44 +0100 Subject: [PATCH] feat: highlight the active cluster in kurtosis cluster ls (#1514) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description: Adds a `* ` string in front of the active cluster, if a cluster has been set. Running on a new install, where `kurtosis cluster set` has never been run: ``` √ kurtosis % ./cli/cli/scripts/launch-cli.sh cluster ls Name docker minikube ``` Once a cluster has been set: ``` √ kurtosis % ./cli/cli/scripts/launch-cli.sh cluster ls Name * docker minikube ``` I've used the `table_printer` to match what `context cli ls` does. ## Is this change user facing? YES ## References (if applicable): https://github.com/kurtosis-tech/kurtosis/issues/1508 --------- Co-authored-by: Omar --- cli/cli/commands/cluster/ls/ls.go | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/cli/cli/commands/cluster/ls/ls.go b/cli/cli/commands/cluster/ls/ls.go index c95def040e..403466b74e 100644 --- a/cli/cli/commands/cluster/ls/ls.go +++ b/cli/cli/commands/cluster/ls/ls.go @@ -6,12 +6,20 @@ import ( "github.com/kurtosis-tech/kurtosis/cli/cli/command_framework/lowlevel/args" "github.com/kurtosis-tech/kurtosis/cli/cli/command_framework/lowlevel/flags" "github.com/kurtosis-tech/kurtosis/cli/cli/command_str_consts" + "github.com/kurtosis-tech/kurtosis/cli/cli/helpers/output_printers" + "github.com/kurtosis-tech/kurtosis/cli/cli/kurtosis_cluster_setting" "github.com/kurtosis-tech/kurtosis/cli/cli/kurtosis_config" - "github.com/kurtosis-tech/kurtosis/cli/cli/out" "github.com/kurtosis-tech/stacktrace" "sort" ) +const ( + clusterCurrentColumnHeader = "" + clusterNameColumnHeader = "Name" + + isCurrentClusterStrIndicator = "*" +) + var LsCmd = &lowlevel.LowlevelKurtosisCommand{ CommandStr: command_str_consts.ClusterLsCmdStr, ShortDescription: "List valid clusters", @@ -35,8 +43,26 @@ func run(ctx context.Context, flags *flags.ParsedFlags, args *args.ParsedArgs) e clusterList = append(clusterList, clusterName) } sort.Strings(clusterList) + + tablePrinter := output_printers.NewTablePrinter(clusterCurrentColumnHeader, clusterNameColumnHeader) + for _, clusterName := range clusterList { - out.PrintOutLn(clusterName) + currentClusterStr := "" + if isCurrentCluster(clusterName) { + currentClusterStr = isCurrentClusterStrIndicator + } + + if err = tablePrinter.AddRow(currentClusterStr, clusterName); err != nil { + return stacktrace.Propagate(err, "Error adding cluster to the table to be displayed") + } } + tablePrinter.Print() return nil } + +func isCurrentCluster(clusterName string) bool { + clusterSettingStore := kurtosis_cluster_setting.GetKurtosisClusterSettingStore() + currentClusterName, _ := clusterSettingStore.GetClusterSetting() + + return clusterName == currentClusterName +}