Skip to content

Commit beaecb3

Browse files
committed
[archerctl] add IN_USE column for service list
1 parent 5e605b5 commit beaecb3

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

internal/client/service.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ type ServiceList struct {
3535
}
3636

3737
func (*ServiceList) Execute(_ []string) error {
38+
type serviceWithEndpoints struct {
39+
*models.Service
40+
Endpoints int `json:"in_use"`
41+
}
42+
3843
params := service.NewGetServiceParams().
3944
WithTags(ServiceOptions.ServiceList.Tags).
4045
WithTagsAny(ServiceOptions.ServiceList.AnyTags).
@@ -45,8 +50,22 @@ func (*ServiceList) Execute(_ []string) error {
4550
if err != nil {
4651
return err
4752
}
48-
DefaultColumns = []string{"id", "name", "ports", "enabled", "provider", "status", "visibility", "availability_zone", "project_id"}
49-
return WriteTable(resp.GetPayload().Items)
53+
DefaultColumns = []string{"id", "name", "ports", "enabled", "provider", "status", "visibility", "availability_zone", "project_id", "in_use"}
54+
items := resp.GetPayload().Items
55+
56+
// Build enriched list with endpoint counts
57+
enriched := make([]serviceWithEndpoints, 0, len(items))
58+
for _, svc := range items {
59+
epParams := service.NewGetServiceServiceIDEndpointsParams().WithServiceID(svc.ID)
60+
epResp, epErr := ArcherClient.Service.GetServiceServiceIDEndpoints(epParams, nil)
61+
count := 0
62+
if epErr == nil {
63+
count = len(epResp.GetPayload().Items)
64+
}
65+
enriched = append(enriched, serviceWithEndpoints{Service: svc, Endpoints: count})
66+
}
67+
68+
return WriteTable(enriched)
5069
}
5170

5271
type ServiceShow struct {

0 commit comments

Comments
 (0)