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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ createos sandbox create --shape s-1vcpu-1gb --name my-box --ssh-key ~/.ssh/id_ed
createos sandbox create --shape s-1vcpu-512mb --ingress --auto-pause 1h
createos sandbox list
createos sandbox list --all
createos sandbox list --wide
createos sandbox list --status paused --quiet | xargs createos sandbox rm --force
createos sandbox get <id>
createos sandbox exec my-box -- uname -a
Expand Down
2 changes: 1 addition & 1 deletion cmd/cronjobs/activities.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func newCronjobsActivitiesCommand() *cli.Command {
log,
})
}
_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render() //nolint:errcheck
_ = output.RenderTable(tableData) //nolint:errcheck
fmt.Println()
})
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/cronjobs/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func newCronjobsListCommand() *cli.Command {
cj.CreatedAt.Local().Format("2006-01-02 15:04:05"),
})
}
_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render() //nolint:errcheck
_ = output.RenderTable(tableData) //nolint:errcheck
fmt.Println()
})
return nil
Expand Down
3 changes: 2 additions & 1 deletion cmd/deployments/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/NodeOps-app/createos-cli/internal/api"
"github.com/NodeOps-app/createos-cli/internal/cmdutil"
"github.com/NodeOps-app/createos-cli/internal/output"
"github.com/NodeOps-app/createos-cli/internal/terminal"
)

Expand Down Expand Up @@ -82,7 +83,7 @@ func pickDeployment(client *api.APIClient, projectID string, statusFilter []stri
})
}
fmt.Println()
if err = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render(); err != nil {
if err = output.RenderTable(tableData); err != nil {
pterm.Error.Println("could not display table")
}
fmt.Println()
Expand Down
2 changes: 1 addition & 1 deletion cmd/deployments/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func newDeploymentsListCommand() *cli.Command {
d.CreatedAt.Local().Format("2006-01-02 15:04:05"),
})
}
if err := pterm.DefaultTable.WithHasHeader().WithData(tableData).Render(); err != nil {
if err := output.RenderTable(tableData); err != nil {
pterm.Error.Println("could not display table")
}
})
Expand Down
3 changes: 2 additions & 1 deletion cmd/domains/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/NodeOps-app/createos-cli/internal/api"
"github.com/NodeOps-app/createos-cli/internal/cmdutil"
"github.com/NodeOps-app/createos-cli/internal/output"
)

func newDomainsCreateCommand() *cli.Command {
Expand Down Expand Up @@ -82,6 +83,6 @@ func printDNSRecords(d api.Domain) {
tableData = append(tableData, []string{"TXT", txt.Name + "." + d.Name, txt.Value})
}

_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render() //nolint:errcheck
_ = output.RenderTable(tableData) //nolint:errcheck
fmt.Println()
}
2 changes: 1 addition & 1 deletion cmd/domains/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func newDomainsListCommand() *cli.Command {
}
tableData = append(tableData, []string{d.ID, d.Name, env, icon + " " + d.Status, msg})
}
_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render() //nolint:errcheck
_ = output.RenderTable(tableData) //nolint:errcheck
fmt.Println()
})
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/env/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func newEnvListCommand() *cli.Command {
tableData = append(tableData, []string{k, val})
}

if err := pterm.DefaultTable.WithHasHeader().WithData(tableData).Render(); err != nil {
if err := output.RenderTable(tableData); err != nil {
return err
}
fmt.Println()
Expand Down
2 changes: 1 addition & 1 deletion cmd/environments/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func newEnvironmentsListCommand() *cli.Command {
env.CreatedAt.Local().Format("2006-01-02 15:04:05"),
})
}
if err := pterm.DefaultTable.WithHasHeader().WithData(tableData).Render(); err != nil {
if err := output.RenderTable(tableData); err != nil {
pterm.Error.Println("could not display table")
}
fmt.Println()
Expand Down
2 changes: 1 addition & 1 deletion cmd/oauth/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func newListCommand() *cli.Command {
item.CreatedAt.Local().Format("2006-01-02 15:04:05"),
})
}
if err := pterm.DefaultTable.WithHasHeader().WithData(tableData).Render(); err != nil {
if err := output.RenderTable(tableData); err != nil {
pterm.Error.Println("could not display table")
}
fmt.Println()
Expand Down
2 changes: 1 addition & 1 deletion cmd/projects/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func newListCommand() *cli.Command {
p.CreatedAt.Local().Format("2006-01-02 15:04:05"),
})
}
_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render() //nolint:errcheck
_ = output.RenderTable(tableData) //nolint:errcheck
})
return nil
},
Expand Down
6 changes: 3 additions & 3 deletions cmd/sandbox/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func runShapes(c *cli.Context) error {
fmt.Sprintf("%d MB", s.DefaultDiskMib),
})
}
_ = pterm.DefaultTable.WithHasHeader().WithData(table).Render() //nolint:errcheck
_ = output.RenderTable(table) //nolint:errcheck
pterm.Println()
pterm.Println(pterm.Gray(" Pick one when creating: createos sandbox create --shape <id>"))
})
Expand Down Expand Up @@ -93,7 +93,7 @@ func runRootfs(c *cli.Context) error {
}
table = append(table, []string{e.Name, e.Description, status})
}
_ = pterm.DefaultTable.WithHasHeader().WithData(table).Render() //nolint:errcheck
_ = output.RenderTable(table) //nolint:errcheck
} else {
table := pterm.TableData{{"Name", "Default"}}
for _, name := range cat.Rootfs {
Expand All @@ -103,7 +103,7 @@ func runRootfs(c *cli.Context) error {
}
table = append(table, []string{name, def})
}
_ = pterm.DefaultTable.WithHasHeader().WithData(table).Render() //nolint:errcheck
_ = output.RenderTable(table) //nolint:errcheck
}
pterm.Println()
pterm.Println(pterm.Gray(" Pick one when creating: createos sandbox create --rootfs <name>"))
Expand Down
2 changes: 1 addition & 1 deletion cmd/sandbox/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func runDeviceList(c *cli.Context) error {
}
rows = append(rows, []string{d.Name, d.ClientIP, d.OS, d.ID, mark})
}
return pterm.DefaultTable.WithHasHeader().WithData(rows).Render()
return output.RenderTable(rows)
}

func newDevicesRemoveCommand() *cli.Command {
Expand Down
2 changes: 1 addition & 1 deletion cmd/sandbox/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func runDiskList(c *cli.Context) error {
d.CreatedAt.Local().Format("2006-01-02 15:04"),
})
}
_ = pterm.DefaultTable.WithHasHeader().WithData(table).Render() //nolint:errcheck
_ = output.RenderTable(table) //nolint:errcheck
})
return nil
}
Expand Down
57 changes: 42 additions & 15 deletions cmd/sandbox/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ Examples:
createos sandbox list --status paused

# Pipe-friendly: IDs only
createos sandbox list --quiet`,
createos sandbox list --quiet

# Include lower-priority columns
createos sandbox list --wide`,
Flags: []cli.Flag{
&cli.IntFlag{
Name: "limit",
Expand All @@ -55,6 +58,10 @@ Examples:
Aliases: []string{"q"},
Usage: "Show only the IDs (great for scripting)",
},
&cli.BoolFlag{
Name: "wide",
Usage: "Show extra columns",
},
},
Action: runList,
}
Expand Down Expand Up @@ -129,24 +136,44 @@ func runList(c *cli.Context) error {
pterm.Println(pterm.Gray(" Create one with: createos sandbox create"))
return
}
tableData := pterm.TableData{
{"ID", "Name", "Status", "Size", "IP", "Created"},
}
for _, r := range rows {
tableData = append(tableData, []string{
r.ID,
strOrDash(r.Name),
r.Status,
r.Shape,
ptrOrDash(r.IP),
r.CreatedAt.Local().Format("2006-01-02 15:04"),
})
}
_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render() //nolint:errcheck
tableData := sandboxListTable(rows, output.TerminalWidth(), c.Bool("wide"))
_ = output.RenderTable(tableData) //nolint:errcheck
})
return nil
}

func sandboxListTable(rows []api.SandboxView, width int, wide bool) pterm.TableData {
columns := []string{"ID", "Name", "Status", "Size", "IP"}
if wide {
columns = append(columns, "Created")
}
switch {
case width < 70:
columns = []string{"Name", "Status", "Size"}
case width < 90:
columns = []string{"ID", "Name", "Status", "Size"}
}

tableData := make(pterm.TableData, 0, 1+len(rows))
tableData = append(tableData, columns)
for _, r := range rows {
values := map[string]string{
"ID": r.ID,
"Name": strOrDash(r.Name),
"Status": r.Status,
"Size": r.Shape,
"IP": ptrOrDash(r.IP),
"Created": r.CreatedAt.Local().Format("2006-01-02 15:04"),
}
row := make([]string, 0, len(columns))
for _, col := range columns {
row = append(row, values[col])
}
tableData = append(tableData, row)
}
return tableData
}

// strOrDash collapses a nullable pointer to "-" when empty so the
// table doesn't show ugly blank cells.
func strOrDash(s *string) string {
Expand Down
50 changes: 50 additions & 0 deletions cmd/sandbox/list_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package sandbox

import (
"testing"
"time"

"github.com/NodeOps-app/createos-cli/internal/api"
)

func TestSandboxListTableBreakpoints(t *testing.T) {
name := "demo"
ip := "10.0.0.1"
rows := []api.SandboxView{{
ID: "sb-01m0example",
Name: &name,
Status: "running",
Shape: "s-1vcpu-1gb",
IP: &ip,
CreatedAt: time.Date(2026, 8, 25, 17, 59, 0, 0, time.UTC),
}}

tests := []struct {
name string
width int
wide bool
headers []string
}{
{name: "compact", width: 69, headers: []string{"Name", "Status", "Size"}},
{name: "medium", width: 89, headers: []string{"ID", "Name", "Status", "Size"}},
{name: "default", width: 120, headers: []string{"ID", "Name", "Status", "Size", "IP"}},
{name: "wide", width: 120, wide: true, headers: []string{"ID", "Name", "Status", "Size", "IP", "Created"}},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
table := sandboxListTable(rows, tt.width, tt.wide)
if len(table) == 0 {
t.Fatal("expected table data")
}
if len(table[0]) != len(tt.headers) {
t.Fatalf("header count = %d, want %d: %#v", len(table[0]), len(tt.headers), table[0])
}
for i, want := range tt.headers {
if table[0][i] != want {
t.Fatalf("header[%d] = %q, want %q; headers = %#v", i, table[0][i], want, table[0])
}
}
})
}
}
4 changes: 2 additions & 2 deletions cmd/sandbox/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func runNetworkList(c *cli.Context) error {
n.CreatedAt.Local().Format("2006-01-02 15:04"),
})
}
_ = pterm.DefaultTable.WithHasHeader().WithData(table).Render() //nolint:errcheck
_ = output.RenderTable(table) //nolint:errcheck
})
return nil
}
Expand Down Expand Up @@ -177,7 +177,7 @@ func runNetworkShow(c *cli.Context) error {
}
table = append(table, []string{m.SandboxID, m.Name, m.Status, m.IP, reachable})
}
_ = pterm.DefaultTable.WithHasHeader().WithData(table).Render() //nolint:errcheck
_ = output.RenderTable(table) //nolint:errcheck
pterm.Println(pterm.Gray(" Tip: inside any of these sandboxes you can `ping <name>` or curl by name."))
}
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/sandbox/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ func runProcessList(c *cli.Context) error {
processLocalDateTime(p.CreatedAt),
})
}
_ = pterm.DefaultTable.WithHasHeader().WithData(table).Render() //nolint:errcheck
_ = output.RenderTable(table) //nolint:errcheck
})
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/sandbox/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func runTemplateList(c *cli.Context) error {
t.CreatedAt.Local().Format("2006-01-02 15:04"),
})
}
_ = pterm.DefaultTable.WithHasHeader().WithData(table).Render() //nolint:errcheck
_ = output.RenderTable(table) //nolint:errcheck
pterm.Println()
pterm.Println(pterm.Gray(" Spawn from a ready template: createos sandbox create --rootfs <name>"))
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/scale/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func updateScale(c *cli.Context, client *api.APIClient, projectID, envID string)
{"CPU", fmt.Sprintf("%dm", current.CPU), fmt.Sprintf("%dm", req.CPU)},
{"Memory", fmt.Sprintf("%dMB", current.Memory), fmt.Sprintf("%dMB", req.Memory)},
}
if err := pterm.DefaultTable.WithHasHeader().WithData(tableData).Render(); err != nil {
if err := output.RenderTable(tableData); err != nil {
return err
}
fmt.Println()
Expand Down
2 changes: 1 addition & 1 deletion cmd/templates/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func newTemplatesListCommand() *cli.Command {
})
}

if err := pterm.DefaultTable.WithHasHeader().WithData(tableData).Render(); err != nil {
if err := output.RenderTable(tableData); err != nil {
return err
}
fmt.Println()
Expand Down
2 changes: 1 addition & 1 deletion cmd/users/consents_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func newOAuthConsentsListCommand() *cli.Command {
}
tableData = append(tableData, []string{clientID, clientName, clientURI})
}
if err := pterm.DefaultTable.WithHasHeader().WithData(tableData).Render(); err != nil {
if err := output.RenderTable(tableData); err != nil {
pterm.Error.Println("could not display table")
}
fmt.Println()
Expand Down
2 changes: 1 addition & 1 deletion cmd/vms/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func newVMListCommand() *cli.Command {
vm.CreatedAt.Local().Format("2006-01-02 15:04:05"),
})
}
_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render() //nolint:errcheck
_ = output.RenderTable(tableData) //nolint:errcheck
fmt.Println()
})
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/webhooks/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func newWebhooksGetCommand() *cli.Command {
d.CreatedAt.Local().Format("2006-01-02 15:04"),
})
}
_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render() //nolint:errcheck
_ = output.RenderTable(tableData) //nolint:errcheck
fmt.Println()
})
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/webhooks/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func newWebhooksListCommand() *cli.Command {
ep.ID, ep.URL, events, status, fmt.Sprintf("%d", ep.FailureCount),
})
}
_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render() //nolint:errcheck
_ = output.RenderTable(tableData) //nolint:errcheck
fmt.Println()
})
return nil
Expand Down
Loading