Formatting only (gofmt -w on the 29 non-vendored, non-generated files gofmt -l reported); swag-generated apiserver/docs/docs.go left as is. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
50 lines
1 KiB
Go
Executable file
50 lines
1 KiB
Go
Executable file
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"text/tabwriter"
|
|
"xcecli/common/request"
|
|
"xcecli/config"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// NewListCmd create the list command
|
|
func NewListCmd(configManager *config.ConfigManager) *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "list",
|
|
GroupID: "api",
|
|
Short: "List the API Servers",
|
|
Long: "List all the configured API Servers and the default API Server",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
return runList(configManager)
|
|
|
|
},
|
|
}
|
|
}
|
|
|
|
func runList(cm *config.ConfigManager) error {
|
|
cfg, err := cm.GetConfig()
|
|
if err != nil {
|
|
errMsg := request.ExtractErrorMessage(err)
|
|
return fmt.Errorf("failed to get the config: [%s]", errMsg)
|
|
}
|
|
|
|
// use tabwriter to format the output
|
|
w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
|
|
fmt.Fprintln(w, "Default\tVersion\tURL")
|
|
|
|
for _, server := range cfg.APIServerInfo {
|
|
isDefault := " "
|
|
if server.Token == "" {
|
|
continue
|
|
}
|
|
|
|
fmt.Fprintf(w, "%s\t%s\n",
|
|
isDefault,
|
|
server.URL)
|
|
}
|
|
|
|
return w.Flush()
|
|
}
|