Skip to content

Commit f5105a0

Browse files
authored
fix(BRE2-829): external nodes should not be part of ls by default (#327)
* fix(BRE2-829): external nodes should not be part of the ls command by default * review feedback: don't print deviceId, fix tests
1 parent fa8d938 commit f5105a0

2 files changed

Lines changed: 432 additions & 24 deletions

File tree

pkg/cmd/ls/ls.go

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,17 @@ func NewCmdLs(t *terminal.Terminal, loginLsStore LsStore, noLoginLsStore LsStore
5858
Short: "List instances within active org",
5959
Long: `List instances within your active org. List all instances if no active org is set.
6060
61+
Subcommands:
62+
instances List cloud instances
63+
nodes List external nodes only
64+
orgs List organizations
65+
6166
When stdout is piped, outputs instance names only (one per line) for easy chaining
6267
with other commands like stop, start, or delete.`,
6368
Example: `
6469
brev ls
70+
brev ls instances
71+
brev ls nodes
6572
brev ls --json
6673
brev ls | grep running | brev stop
6774
brev ls orgs
@@ -110,7 +117,7 @@ with other commands like stop, start, or delete.`,
110117
return nil
111118
},
112119
Args: cmderrors.TransformToValidationError(cobra.MinimumNArgs(0)),
113-
ValidArgs: []string{"orgs", "workspaces", "nodes"},
120+
ValidArgs: []string{"orgs", "workspaces", "nodes", "instances"},
114121
RunE: func(cmd *cobra.Command, args []string) error {
115122
err := RunLs(t, loginLsStore, args, org, showAll, jsonOutput)
116123
if err != nil {
@@ -243,6 +250,12 @@ func handleLsArg(ls *Ls, arg string, user *entity.User, org *entity.Organization
243250
return breverrors.WrapAndTrace(err)
244251
}
245252
return nil
253+
} else if util.IsSingularOrPlural(arg, "instance") {
254+
err := ls.RunInstances(org, user, showAll)
255+
if err != nil {
256+
return breverrors.WrapAndTrace(err)
257+
}
258+
return nil
246259
}
247260
return nil
248261
}
@@ -480,9 +493,13 @@ func (ls Ls) RunWorkspaces(org *entity.Organization, user *entity.User, showAll
480493
ls.ShowUserWorkspaces(org, orgs, user, allWorkspaces, gpuLookup)
481494
}
482495

483-
// Also show external nodes in the default listing
484-
ls.showNodesSection(org)
496+
return nil
497+
}
485498

499+
func (ls Ls) RunInstances(org *entity.Organization, user *entity.User, showAll bool) error {
500+
if err := ls.RunWorkspaces(org, user, showAll); err != nil {
501+
return err
502+
}
486503
return nil
487504
}
488505

@@ -712,7 +729,6 @@ func getStatusColoredText(t *terminal.Terminal, status string) string {
712729
type NodeInfo struct {
713730
Name string `json:"name"`
714731
ExternalNodeID string `json:"external_node_id"`
715-
DeviceID string `json:"device_id"`
716732
OrgID string `json:"org_id"`
717733
Status string `json:"status"`
718734
}
@@ -760,32 +776,12 @@ func (ls Ls) RunNodes(org *entity.Organization) error {
760776
return nil
761777
}
762778

763-
// showNodesSection appends external nodes to the default `brev ls` output.
764-
// Errors are silently ignored so that a ListNodes failure doesn't break the
765-
// workspace listing.
766-
func (ls Ls) showNodesSection(org *entity.Organization) {
767-
nodes, err := ls.listNodes(org)
768-
if err != nil || len(nodes) == 0 {
769-
return
770-
}
771-
772-
if ls.jsonOutput || ls.piped {
773-
// JSON and piped modes are already handled per-section; skip here to
774-
// avoid duplicating output when the user runs `brev ls nodes` explicitly.
775-
return
776-
}
777-
778-
ls.terminal.Vprintf("\nExternal Nodes (%d):\n", len(nodes))
779-
displayNodesTable(ls.terminal, nodes)
780-
}
781-
782779
func (ls Ls) outputNodesJSON(nodes []*nodev1.ExternalNode) error {
783780
var infos []NodeInfo
784781
for _, n := range nodes {
785782
infos = append(infos, NodeInfo{
786783
Name: n.GetName(),
787784
ExternalNodeID: n.GetExternalNodeId(),
788-
DeviceID: n.GetDeviceId(),
789785
OrgID: n.GetOrganizationId(),
790786
Status: nodeConnectionStatus(n),
791787
})

0 commit comments

Comments
 (0)