Skip to content

Commit

Permalink
Convert to use table printer, to match the context cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Omar committed Oct 10, 2023
1 parent 58f0128 commit 17107a7
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions cli/cli/commands/cluster/ls/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +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 @@ -36,20 +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 {
activeClusterFlag := getActiveClusterFlag(clusterName)
out.PrintOutLn(activeClusterFlag + clusterName)
currentClusterStr := ""
if isCurrentCluster(clusterName) {
currentClusterStr = isCurrentClusterStrIndicator
}
tablePrinter.AddRow(currentClusterStr, clusterName)

Check failure on line 54 in cli/cli/commands/cluster/ls/ls.go

View workflow job for this annotation

GitHub Actions / golang-lint

Error return value of `tablePrinter.AddRow` is not checked (errcheck)
}
tablePrinter.Print()
return nil
}

func getActiveClusterFlag(clusterName string) string {
func isCurrentCluster(clusterName string) bool {
clusterSettingStore := kurtosis_cluster_setting.GetKurtosisClusterSettingStore()
activeClusterName, _ := clusterSettingStore.GetClusterSetting()
currentClusterName, _ := clusterSettingStore.GetClusterSetting()

activeClusterFlag := " "
if clusterName == activeClusterName {
activeClusterFlag = "* "
if clusterName == currentClusterName {

Check failure on line 64 in cli/cli/commands/cluster/ls/ls.go

View workflow job for this annotation

GitHub Actions / golang-lint

S1008: should use 'return clusterName == currentClusterName' instead of 'if clusterName == currentClusterName { return true }; return false' (gosimple)
return true
}
return activeClusterFlag
return false
}

0 comments on commit 17107a7

Please sign in to comment.