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

Commitb92aaf0

Browse files
authored
Unide envs (create|edit) commands (#168)
1 parent258f3e1 commitb92aaf0

File tree

8 files changed

+164
-101
lines changed

8 files changed

+164
-101
lines changed

‎ci/integration/envs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func TestEnvsCLI(t *testing.T) {
108108
// Successfully output help.
109109
c.Run(ctx,"coder envs create --help").Assert(t,
110110
tcli.Success(),
111-
tcli.StdoutMatches(regexp.QuoteMeta("Create a newenvironment under the active user.")),
111+
tcli.StdoutMatches(regexp.QuoteMeta("Create a newCoder environment.")),
112112
tcli.StderrEmpty(),
113113
)
114114

‎coder-sdk/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"net/url"
77
)
88

9-
// Me is theroute param to access resources of the authenticated user.
9+
// Me is theuser ID of the authenticated user.
1010
constMe="me"
1111

1212
// Client wraps the Coder HTTP API.

‎coder-sdk/error.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"encoding/json"
55
"fmt"
66
"net/http"
7-
"net/http/httputil"
87

98
"golang.org/x/xerrors"
109
)
@@ -34,22 +33,17 @@ type HTTPError struct {
3433
}
3534

3635
func (e*HTTPError)Error()string {
37-
dump,err:=httputil.DumpResponse(e.Response,false)
38-
iferr!=nil {
39-
returnfmt.Sprintf("dump response: %+v",err)
40-
}
41-
4236
varmsgAPIError
4337
// Try to decode the payload as an error, if it fails or if there is no error message,
4438
// return the response URL with the dump.
4539
iferr:=json.NewDecoder(e.Response.Body).Decode(&msg);err!=nil||msg.Err.Msg=="" {
46-
returnfmt.Sprintf("%s\n%s",e.Response.Request.URL,dump)
40+
returnfmt.Sprintf("%s: %d %s",e.Request.URL,e.StatusCode,e.Status)
4741
}
4842

4943
// If the payload was a in the expected error format with a message, include it.
5044
returnmsg.Err.Msg
5145
}
5246

5347
funcbodyError(resp*http.Response)error {
54-
return&HTTPError{resp}
48+
return&HTTPError{Response:resp}
5549
}

‎docs/coder_envs.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Perform operations on the Coder environments owned by the active user.
2222
###SEE ALSO
2323

2424
*[coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
25+
*[coder envs create](coder_envs_create.md) - create a new environment.
26+
*[coder envs edit](coder_envs_edit.md) - edit an existing environment and initiate a rebuild.
2527
*[coder envs ls](coder_envs_ls.md) - list all environments owned by the active user
2628
*[coder envs rebuild](coder_envs_rebuild.md) - rebuild a Coder environment
2729
*[coder envs rm](coder_envs_rm.md) - remove Coder environments by name

‎docs/coder_envs_create.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
##coder envs create
2+
3+
create a new environment.
4+
5+
###Synopsis
6+
7+
Create a new Coder environment.
8+
9+
```
10+
coder envs create [environment_name] [flags]
11+
```
12+
13+
###Examples
14+
15+
```
16+
# create a new environment using default resource amounts
17+
coder envs create my-new-env --image ubuntu
18+
coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ubuntu
19+
```
20+
21+
###Options
22+
23+
```
24+
-c, --cpu float32 number of cpu cores the environment should be provisioned with.
25+
-d, --disk int GB of disk storage an environment should be provisioned with.
26+
--follow follow buildlog after initiating rebuild
27+
-g, --gpus int number GPUs an environment should be provisioned with.
28+
-h, --help help for create
29+
-i, --image string name of the image to base the environment off of.
30+
-m, --memory float32 GB of RAM an environment should be provisioned with.
31+
-o, --org string ID of the organization the environment should be created under.
32+
-t, --tag string tag of the image the environment will be based off of. (default "latest")
33+
```
34+
35+
###Options inherited from parent commands
36+
37+
```
38+
--user string Specify the user whose resources to target (default "me")
39+
-v, --verbose show verbose output
40+
```
41+
42+
###SEE ALSO
43+
44+
*[coder envs](coder_envs.md) - Interact with Coder environments
45+

‎docs/coder_envs_edit.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
##coder envs edit
2+
3+
edit an existing environment and initiate a rebuild.
4+
5+
###Synopsis
6+
7+
Edit an existing environment and initate a rebuild.
8+
9+
```
10+
coder envs edit [flags]
11+
```
12+
13+
###Examples
14+
15+
```
16+
coder envs edit back-end-env --cpu 4
17+
18+
coder envs edit back-end-env --disk 20
19+
```
20+
21+
###Options
22+
23+
```
24+
-c, --cpu float32 The number of cpu cores the environment should be provisioned with.
25+
-d, --disk int The amount of disk storage an environment should be provisioned with.
26+
--follow follow buildlog after initiating rebuild
27+
-g, --gpu int The amount of disk storage to provision the environment with.
28+
-h, --help help for edit
29+
-i, --image string name of the image you want the environment to be based off of.
30+
-m, --memory float32 The amount of RAM an environment should be provisioned with.
31+
-o, --org string name of the organization the environment should be created under.
32+
-t, --tag string image tag of the image you want to base the environment off of. (default "latest")
33+
```
34+
35+
###Options inherited from parent commands
36+
37+
```
38+
--user string Specify the user whose resources to target (default "me")
39+
-v, --verbose show verbose output
40+
```
41+
42+
###SEE ALSO
43+
44+
*[coder envs](coder_envs.md) - Interact with Coder environments
45+

‎internal/cmd/ceapi.go

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,27 +84,23 @@ func findEnv(ctx context.Context, client *coder.Client, envName, userEmail strin
8484
}
8585

8686
typefindImgConfstruct {
87-
client*coder.Client
8887
emailstring
8988
imgNamestring
9089
orgNamestring
9190
}
9291

93-
funcfindImg(ctx context.Context,conffindImgConf) (*coder.Image,error) {
92+
funcfindImg(ctx context.Context,client*coder.Client,conffindImgConf) (*coder.Image,error) {
9493
switch {
9594
caseconf.email=="":
9695
returnnil,xerrors.New("user email unset")
9796
caseconf.imgName=="":
9897
returnnil,xerrors.New("image name unset")
9998
}
10099

101-
imgs,err:=getImgs(ctx,
102-
getImgsConf{
103-
client:conf.client,
104-
email:conf.email,
105-
orgName:conf.orgName,
106-
},
107-
)
100+
imgs,err:=getImgs(ctx,client,getImgsConf{
101+
email:conf.email,
102+
orgName:conf.orgName,
103+
})
108104
iferr!=nil {
109105
returnnil,err
110106
}
@@ -129,38 +125,37 @@ func findImg(ctx context.Context, conf findImgConf) (*coder.Image, error) {
129125
returnnil,xerrors.New("image not found - did you forget to import this image?")
130126
}
131127

132-
lines:= []string{clog.Tipf("Did you mean?")}
128+
lines:= []string{clog.Hintf("Did you mean?")}
133129

134130
for_,img:=rangepossibleMatches {
135-
lines=append(lines,img.Repository)
131+
lines=append(lines,fmt.Sprintf(" %s",img.Repository))
136132
}
137133
returnnil,clog.Fatal(
138-
fmt.Sprintf("Found %d possible matches for %q.",len(possibleMatches),conf.imgName),
134+
fmt.Sprintf("image %s not found",conf.imgName),
139135
lines...,
140136
)
141137
}
142138

143139
typegetImgsConfstruct {
144-
client*coder.Client
145140
emailstring
146141
orgNamestring
147142
}
148143

149-
funcgetImgs(ctx context.Context,confgetImgsConf) ([]coder.Image,error) {
150-
u,err:=conf.client.UserByEmail(ctx,conf.email)
144+
funcgetImgs(ctx context.Context,client*coder.Client,confgetImgsConf) ([]coder.Image,error) {
145+
u,err:=client.UserByEmail(ctx,conf.email)
151146
iferr!=nil {
152147
returnnil,err
153148
}
154149

155-
orgs,err:=conf.client.Organizations(ctx)
150+
orgs,err:=client.Organizations(ctx)
156151
iferr!=nil {
157152
returnnil,err
158153
}
159154

160155
orgs=lookupUserOrgs(u,orgs)
161156

162157
for_,org:=rangeorgs {
163-
imgs,err:=conf.client.OrganizationImages(ctx,org.ID)
158+
imgs,err:=client.OrganizationImages(ctx,org.ID)
164159
iferr!=nil {
165160
returnnil,err
166161
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp