Skip to content

Commit

Permalink
Merge branch 'main' into lporoli/replace-wit-local-dependency-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
leoporoli committed Oct 12, 2023
2 parents 64aff44 + 67e0111 commit 5754867
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions cli/cli/commands/cluster/ls/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
}

0 comments on commit 5754867

Please sign in to comment.