Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 37ade46

Browse files
committed
fixup! Initial prototype of resources command
1 parent 166ed14 commit 37ade46

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

coder-sdk/env.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (c Client) CreateEnvironment(ctx context.Context, orgID string, req CreateE
9595

9696
// ListEnvironments lists environments returned by the given filter.
9797
// TODO: add the filter options
98-
func (c Client) ListEnvironments(ctx context.Context) ([]Environment, error) {
98+
func (c Client) ListEnvironments(ctx context.Context) ([]Environment, error) {
9999
var envs []Environment
100100
if err := c.requestBody(ctx, http.MethodGet, "/api/environments", nil, &envs); err != nil {
101101
return nil, err

coder-sdk/org.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88

99
// Org describes an Organization in Coder
1010
type Org struct {
11-
ID string `json:"id"`
12-
Name string `json:"name"`
11+
ID string `json:"id"`
12+
Name string `json:"name"`
1313
Members []OrganizationUser `json:"members"`
1414
}
1515

@@ -22,8 +22,8 @@ type OrganizationUser struct {
2222
type Role string
2323

2424
const (
25-
RoleOrgMember Role = "organization-member"
26-
RoleOrgAdmin Role = "organization-admin"
25+
RoleOrgMember Role = "organization-member"
26+
RoleOrgAdmin Role = "organization-admin"
2727
RoleOrgManager Role = "organization-manager"
2828
)
2929

internal/cmd/resourcemanager.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
func makeResourceCmd() *cobra.Command {
1313
cmd := &cobra.Command{
14-
Use: "resources",
14+
Use: "resources",
1515
Short: "manager Coder resources with platform-level context (users, organizations, environments)",
1616
}
1717
cmd.AddCommand(resourceTop)
@@ -54,8 +54,8 @@ var resourceTop = &cobra.Command{
5454

5555
tabwriter := tabwriter.NewWriter(os.Stdout, 0, 0, 4, ' ', 0)
5656
for _, u := range users {
57-
_, _ = fmt.Fprintf(tabwriter, "%s\t(%s)\t%s", u.Name, u.Email, aggregateEnvResources(userEnvs[u.ID]))
58-
if len(userEnvs[u.ID]) >0 {
57+
_, _ = fmt.Fprintf(tabwriter, "%s\t(%s)\t%s", u.Name, u.Email, aggregateEnvResources(userEnvs[u.ID]))
58+
if len(userEnvs[u.ID]) > 0 {
5959
_, _ = fmt.Fprintf(tabwriter, "\f")
6060
}
6161
for _, env := range userEnvs[u.ID] {
@@ -71,19 +71,19 @@ var resourceTop = &cobra.Command{
7171
}
7272

7373
func resourcesFromEnv(env coder.Environment) resources {
74-
return resources{
75-
cpuAllocation: env.CPUCores,
76-
cpuUtilization: env.LatestStat.CPUUsage,
77-
memAllocation: env.MemoryGB,
78-
memUtilization: env.LatestStat.MemoryUsage,
79-
}
74+
return resources{
75+
cpuAllocation: env.CPUCores,
76+
cpuUtilization: env.LatestStat.CPUUsage,
77+
memAllocation: env.MemoryGB,
78+
memUtilization: env.LatestStat.MemoryUsage,
79+
}
8080
}
8181

8282
func fmtEnvResources(env coder.Environment, orgs map[string]coder.Org) string {
83-
return fmt.Sprintf("%s\t%s\t[org: %s]", env.Name, resourcesFromEnv(env), orgs[env.OrganizationID].Name)
83+
return fmt.Sprintf("%s\t%s\t[org: %s]", env.Name, resourcesFromEnv(env), orgs[env.OrganizationID].Name)
8484
}
8585

86-
func aggregateEnvResources(envs []coder.Environment) (resources) {
86+
func aggregateEnvResources(envs []coder.Environment) resources {
8787
var aggregate resources
8888
for _, e := range envs {
8989
aggregate.cpuAllocation += e.CPUCores

0 commit comments

Comments
 (0)