Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Commitaf2ac67

Browse files
committed
Hide resources command from docs
1 parentb1088fb commitaf2ac67

File tree

6 files changed

+49
-92
lines changed

6 files changed

+49
-92
lines changed

‎ci/steps/gendocs.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ echo "Generating docs..."
77
cd"$(dirname"$0")"
88
cd ../../
99

10+
rm -rf ./docs
11+
mkdir ./docs
1012
go run ./cmd/coder gen-docs ./docs
1113

1214
# remove cobra footer from each file
1315
forfilenamein ./docs/*.md;do
1416
trimmed=$(head -n -1"$filename")
15-
echo"$trimmed">$filename
17+
echo"$trimmed">$filename
1618
done
1719

18-
1920
if [[${CI-}&&$(git ls-files --other --modified --exclude-standard) ]];then
2021
echo"Documentation needs generation:"
2122
git -c color.ui=always status| grep --color=no'\e\[31m'

‎coder-sdk/env.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ func (c Client) CreateEnvironment(ctx context.Context, orgID string, req CreateE
9393
return&env,nil
9494
}
9595

96-
//ListEnvironments lists environments returned by the given filter.
97-
// TODO: add the filter options
98-
func (cClient)ListEnvironments(ctx context.Context) ([]Environment,error) {
96+
//Environments lists environments returned by the given filter.
97+
// TODO: add the filter options, explore performance issues
98+
func (cClient)Environments(ctx context.Context) ([]Environment,error) {
9999
varenvs []Environment
100100
iferr:=c.requestBody(ctx,http.MethodGet,"/api/environments",nil,&envs);err!=nil {
101101
returnnil,err

‎docs/coder.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ coder provides a CLI for working with an existing Coder Enterprise installation
2020
*[coder envs](coder_envs.md) - Interact with Coder environments
2121
*[coder login](coder_login.md) - Authenticate this client for future operations
2222
*[coder logout](coder_logout.md) - Remove local authentication credentials if any exist
23-
*[coder resources](coder_resources.md) - manager Coder resources with platform-level context (users, organizations, environments)
2423
*[coder secrets](coder_secrets.md) - Interact with Coder Secrets
2524
*[coder sh](coder_sh.md) - Open a shell and execute commands in a Coder environment
2625
*[coder sync](coder_sync.md) - Establish a one way directory sync to a Coder environment

‎docs/coder_resources.md

Lines changed: 0 additions & 24 deletions
This file was deleted.

‎docs/coder_resources_top.md

Lines changed: 0 additions & 27 deletions
This file was deleted.

‎internal/cmd/resourcemanager.go

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@ package cmd
22

33
import (
44
"fmt"
5+
"io"
56
"os"
67
"sort"
78
"text/tabwriter"
89

910
"cdr.dev/coder-cli/coder-sdk"
1011
"github.com/spf13/cobra"
12+
"golang.org/x/xerrors"
1113
)
1214

1315
funcmakeResourceCmd()*cobra.Command {
1416
cmd:=&cobra.Command{
15-
Use:"resources",
16-
Short:"manager Coder resources with platform-level context (users, organizations, environments)",
17+
Use:"resources",
18+
Short:"manager Coder resources with platform-level context (users, organizations, environments)",
19+
Hidden:true,
1720
}
1821
cmd.AddCommand(resourceTop())
1922
returncmd
@@ -24,15 +27,16 @@ func resourceTop() *cobra.Command {
2427
Use:"top",
2528
RunE:func(cmd*cobra.Command,args []string)error {
2629
ctx:=cmd.Context()
27-
2830
client,err:=newClient()
2931
iferr!=nil {
3032
returnerr
3133
}
3234

33-
envs,err:=client.ListEnvironments(ctx)
35+
// NOTE: it's not worth parrallelizing these calls yet given that this specific endpoint
36+
// takes about 20x times longer than the other two
37+
envs,err:=client.Environments(ctx)
3438
iferr!=nil {
35-
returnerr
39+
returnxerrors.Errorf("get environments %w",err)
3640
}
3741

3842
userEnvs:=make(map[string][]coder.Environment)
@@ -42,51 +46,55 @@ func resourceTop() *cobra.Command {
4246

4347
users,err:=client.Users(ctx)
4448
iferr!=nil {
45-
returnerr
49+
returnxerrors.Errorf("get users: %w",err)
4650
}
4751

48-
orgs:=make(map[string]coder.Organization)
52+
orgIDMap:=make(map[string]coder.Organization)
4953
orglist,err:=client.Organizations(ctx)
5054
iferr!=nil {
51-
returnerr
55+
returnxerrors.Errorf("get organizations: %w",err)
5256
}
5357
for_,o:=rangeorglist {
54-
orgs[o.ID]=o
55-
}
56-
57-
tabwriter:=tabwriter.NewWriter(os.Stdout,0,0,4,' ',0)
58-
varuserResources []aggregatedUser
59-
for_,u:=rangeusers {
60-
// truncate user names to ensure tabwriter doesn't push our entire table too far
61-
u.Name=truncate(u.Name,20,"...")
62-
userResources=append(userResources,aggregatedUser{User:u,resources:aggregateEnvResources(userEnvs[u.ID])})
63-
}
64-
sort.Slice(userResources,func(i,jint)bool {
65-
returnuserResources[i].cpuAllocation>userResources[j].cpuAllocation
66-
})
67-
68-
for_,u:=rangeuserResources {
69-
_,_=fmt.Fprintf(tabwriter,"%s\t(%s)\t%s",u.Name,u.Email,u.resources)
70-
ifverbose {
71-
iflen(userEnvs[u.ID])>0 {
72-
_,_=fmt.Fprintf(tabwriter,"\f")
73-
}
74-
for_,env:=rangeuserEnvs[u.ID] {
75-
_,_=fmt.Fprintf(tabwriter,"\t")
76-
_,_=fmt.Fprintln(tabwriter,fmtEnvResources(env,orgs))
77-
}
78-
}
79-
fmt.Fprint(tabwriter,"\n")
58+
orgIDMap[o.ID]=o
8059
}
81-
_=tabwriter.Flush()
8260

61+
printResourceTop(os.Stdout,users,orgIDMap,userEnvs)
8362
returnnil
8463
},
8564
}
8665

8766
returncmd
8867
}
8968

69+
funcprintResourceTop(writer io.Writer,users []coder.User,orgIDMapmap[string]coder.Organization,userEnvsmap[string][]coder.Environment) {
70+
tabwriter:=tabwriter.NewWriter(writer,0,0,4,' ',0)
71+
deferfunc() {_=tabwriter.Flush() }()
72+
73+
varuserResources []aggregatedUser
74+
for_,u:=rangeusers {
75+
// truncate user names to ensure tabwriter doesn't push our entire table too far
76+
u.Name=truncate(u.Name,20,"...")
77+
userResources=append(userResources,aggregatedUser{User:u,resources:aggregateEnvResources(userEnvs[u.ID])})
78+
}
79+
sort.Slice(userResources,func(i,jint)bool {
80+
returnuserResources[i].cpuAllocation>userResources[j].cpuAllocation
81+
})
82+
83+
for_,u:=rangeuserResources {
84+
_,_=fmt.Fprintf(tabwriter,"%s\t(%s)\t%s",u.Name,u.Email,u.resources)
85+
ifverbose {
86+
iflen(userEnvs[u.ID])>0 {
87+
_,_=fmt.Fprintf(tabwriter,"\f")
88+
}
89+
for_,env:=rangeuserEnvs[u.ID] {
90+
_,_=fmt.Fprintf(tabwriter,"\t")
91+
_,_=fmt.Fprintln(tabwriter,fmtEnvResources(env,orgIDMap))
92+
}
93+
}
94+
_,_=fmt.Fprint(tabwriter,"\n")
95+
}
96+
}
97+
9098
typeaggregatedUserstruct {
9199
coder.User
92100
resources

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp