Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
domainCmd "github.com/zeabur/cli/internal/cmd/domain"
profileCmd "github.com/zeabur/cli/internal/cmd/profile"
projectCmd "github.com/zeabur/cli/internal/cmd/project"
serverCmd "github.com/zeabur/cli/internal/cmd/server"
serviceCmd "github.com/zeabur/cli/internal/cmd/service"
templateCmd "github.com/zeabur/cli/internal/cmd/template"
uploadCmd "github.com/zeabur/cli/internal/cmd/upload"
Expand Down Expand Up @@ -120,6 +121,7 @@ func NewCmdRoot(f *cmdutil.Factory, version, commit, date string) (*cobra.Comman
cmd.AddCommand(versionCmd.NewCmdVersion(f, version, commit, date))
cmd.AddCommand(authCmd.NewCmdAuth(f))
cmd.AddCommand(projectCmd.NewCmdProject(f))
cmd.AddCommand(serverCmd.NewCmdServer(f))
cmd.AddCommand(serviceCmd.NewCmdService(f))
cmd.AddCommand(deploymentCmd.NewCmdDeployment(f))
cmd.AddCommand(templateCmd.NewCmdTemplate(f))
Expand Down
35 changes: 35 additions & 0 deletions internal/cmd/server/list/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package list

import (
"context"

"github.com/spf13/cobra"

"github.com/zeabur/cli/internal/cmdutil"
"github.com/zeabur/cli/pkg/model"
)

func NewCmdList(f *cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "List dedicated servers",
Aliases: []string{"ls"},
RunE: func(cmd *cobra.Command, args []string) error {
return runList(f)
},
}

return cmd
}

func runList(f *cmdutil.Factory) error {
servers, err := f.ApiClient.GetServers(context.Background())
if err != nil {
return err
}

s := model.Servers(servers)
f.Printer.Table(s.Header(), s.Rows())

return nil
}
22 changes: 22 additions & 0 deletions internal/cmd/server/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Package server contains the cmd for managing dedicated servers
package server

import (
"github.com/spf13/cobra"

"github.com/zeabur/cli/internal/cmdutil"

serverListCmd "github.com/zeabur/cli/internal/cmd/server/list"
)

// NewCmdServer creates the server command
func NewCmdServer(f *cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "server",
Short: "Manage dedicated servers",
}

cmd.AddCommand(serverListCmd.NewCmdList(f))

return cmd
}
21 changes: 21 additions & 0 deletions pkg/model/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,24 @@ func (s Server) String() string {
func (s Server) IsAvailable() bool {
return true
}

type Servers []Server

func (s Servers) Header() []string {
return []string{"ID", "Name", "Location", "IP"}
}

func (s Servers) Rows() [][]string {
rows := make([][]string, len(s))
for i, server := range s {
location := server.IP
if server.Country != nil {
location = *server.Country
if server.City != nil {
location = fmt.Sprintf("%s, %s", *server.City, *server.Country)
}
}
rows[i] = []string{server.GetID(), server.Name, location, server.IP}
}
Comment on lines +45 to +53
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Location is initialized with server.IP, and the row also prints server.IP in the IP column. This makes the Location column duplicate the IP (and can be misleading when country/city is unknown). Consider using an explicit placeholder (e.g. "-"/empty) when Country is nil, and/or extracting a shared LocationString() helper so this formatting logic isn't duplicated with Server.String().

Copilot uses AI. Check for mistakes.
return rows
}