Merge Go frontend (apiserver + xcecli) into meson build

This commit is contained in:
Rongsong Shen 2026-04-14 11:20:17 +08:00
parent 43dc12a36c
commit c9dc8c4676
205 changed files with 30793 additions and 328 deletions

View file

@ -0,0 +1,50 @@
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()
}