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

Commit924ebad

Browse files
author
Faris Huskovic
authored
Merge pull request#151 from cdr/faris/ch1868/coder-envs-edit
Add coder envs edit command
2 parents717ad15 +68dd84c commit924ebad

File tree

3 files changed

+118
-7
lines changed

3 files changed

+118
-7
lines changed

‎go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ require (
1616
github.com/rjeczalik/notifyv0.9.2
1717
github.com/spf13/cobrav1.0.0
1818
github.com/stretchr/testifyv1.6.1
19-
golang.org/x/cryptov0.0.0-20200422194213-44a606286825
20-
golang.org/x/syncv0.0.0-20200317015054-43a5402ce75a
19+
golang.org/x/cryptov0.0.0-20200622213623-75b288015ac9
20+
golang.org/x/netv0.0.0-20200822124328-c89045814202// indirect
21+
golang.org/x/syncv0.0.0-20200625203802-6e8e738ad208
2122
golang.org/x/sysv0.0.0-20201018230417-eeed37f84f13
2223
golang.org/x/timev0.0.0-20191024005414-555d28b269f0
23-
golang.org/x/xerrorsv0.0.0-20191204190536-9bdfabe68543
24+
golang.org/x/xerrorsv0.0.0-20200804184101-5ec99f83aff1
2425
nhooyr.io/websocketv1.8.6
2526
)

‎go.sum

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
273273
golang.org/x/cryptov0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
274274
golang.org/x/cryptov0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
275275
golang.org/x/cryptov0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
276-
golang.org/x/cryptov0.0.0-20200422194213-44a606286825 h1:dSChiwOTvzwbHFTMq2l6uRardHH7/E6SqEkqccinS/o=
277-
golang.org/x/cryptov0.0.0-20200422194213-44a606286825/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
276+
golang.org/x/cryptov0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
277+
golang.org/x/cryptov0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
278278
golang.org/x/expv0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
279279
golang.org/x/expv0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
280280
golang.org/x/expv0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@@ -288,6 +288,7 @@ golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTk
288288
golang.org/x/lintv0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
289289
golang.org/x/lintv0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
290290
golang.org/x/lintv0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
291+
golang.org/x/lintv0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
291292
golang.org/x/lintv0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
292293
golang.org/x/mobilev0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
293294
golang.org/x/mobilev0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
@@ -308,6 +309,8 @@ golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR
308309
golang.org/x/netv0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
309310
golang.org/x/netv0.0.0-20191209160850-c0dbc17a3553 h1:efeOvDhwQ29Dj3SdAV/MJf8oukgn+8D8WgaCaRMchF8=
310311
golang.org/x/netv0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
312+
golang.org/x/netv0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA=
313+
golang.org/x/netv0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
311314
golang.org/x/oauth2v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
312315
golang.org/x/oauth2v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
313316
golang.org/x/oauth2v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -316,8 +319,8 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ
316319
golang.org/x/syncv0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
317320
golang.org/x/syncv0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
318321
golang.org/x/syncv0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
319-
golang.org/x/syncv0.0.0-20200317015054-43a5402ce75a h1:WXEvlFVvvGxCJLG6REjsT03iWnKLEWinaScsxF2Vm2o=
320-
golang.org/x/syncv0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
322+
golang.org/x/syncv0.0.0-20200625203802-6e8e738ad208 h1:qwRHBd0NqMbJxfbotnDhm2ByMI1Shq4Y6oRJo21SGJA=
323+
golang.org/x/syncv0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
321324
golang.org/x/sysv0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
322325
golang.org/x/sysv0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
323326
golang.org/x/sysv0.0.0-20180926160741-c2ed4eda69e7/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -337,6 +340,7 @@ golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7w
337340
golang.org/x/sysv0.0.0-20191210023423-ac6580df4449/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
338341
golang.org/x/sysv0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
339342
golang.org/x/sysv0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
343+
golang.org/x/sysv0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
340344
golang.org/x/sysv0.0.0-20201018230417-eeed37f84f13 h1:5jaG59Zhd+8ZXe8C+lgiAGqkOaZBruqrWclLkgAww34=
341345
golang.org/x/sysv0.0.0-20201018230417-eeed37f84f13/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
342346
golang.org/x/textv0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -363,10 +367,13 @@ golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgw
363367
golang.org/x/toolsv0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
364368
golang.org/x/toolsv0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
365369
golang.org/x/toolsv0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
370+
golang.org/x/toolsv0.0.0-20191115202509-3a792d9c32b2 h1:EtTFh6h4SAKemS+CURDMTDIANuduG5zKEXShyy18bGA=
366371
golang.org/x/toolsv0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
367372
golang.org/x/xerrorsv0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
368373
golang.org/x/xerrorsv0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
369374
golang.org/x/xerrorsv0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
375+
golang.org/x/xerrorsv0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
376+
golang.org/x/xerrorsv0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
370377
google.golang.org/apiv0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
371378
google.golang.org/apiv0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
372379
google.golang.org/apiv0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=

‎internal/cmd/envs.go

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func envsCommand() *cobra.Command {
7272
}
7373
lsCmd.Flags().StringVarP(&outputFmt,"output","o","human","human | json")
7474
cmd.AddCommand(lsCmd)
75+
cmd.AddCommand(editEnvCommand(&user))
7576
cmd.AddCommand(stopEnvCommand(&user))
7677
cmd.AddCommand(watchBuildLogCommand())
7778
cmd.AddCommand(rebuildEnvCommand())
@@ -207,3 +208,105 @@ coder envs create --cpu 4 --disk 100 --memory 8 --image 5f443b16-30652892427b955
207208
cmd.MarkFlagRequired("image")
208209
returncmd
209210
}
211+
212+
funceditEnvCommand(user*string)*cobra.Command {
213+
var (
214+
imgstring
215+
tagstring
216+
cpuCoresfloat32
217+
memGBfloat32
218+
diskGBint
219+
gpusint
220+
followbool
221+
)
222+
223+
cmd:=&cobra.Command{
224+
Use:"edit",
225+
Short:"edit an existing environment owned by the active user.",
226+
Args:cobra.ExactArgs(1),
227+
Hidden:true,
228+
Long:"Edit an existing environment owned by the active user.",
229+
Example:`coder envs edit back-end-env --cpu 4
230+
231+
coder envs edit back-end-env --disk 20`,
232+
RunE:func(cmd*cobra.Command,args []string)error {
233+
// We're explicitly ignoring these errors because if any of these
234+
// fail we are left with the zero value for the corresponding numeric type.
235+
cpuCores,_=cmd.Flags().GetFloat32("cpu")
236+
memGB,_=cmd.Flags().GetFloat32("memory")
237+
diskGB,_=cmd.Flags().GetInt("disk")
238+
gpus,_=cmd.Flags().GetInt("gpus")
239+
240+
client,err:=newClient()
241+
iferr!=nil {
242+
returnerr
243+
}
244+
245+
envName:=args[0]
246+
247+
env,err:=findEnv(cmd.Context(),client,envName,*user)
248+
iferr!=nil {
249+
returnerr
250+
}
251+
252+
varupdateReq coder.UpdateEnvironmentReq
253+
254+
// If any of the flags have defaulted to zero-values, it implies the user does not wish to change that value.
255+
// With that said, we can enforce this by reassigning the request field to the corresponding existing environment value.
256+
ifcpuCores==0 {
257+
updateReq.CPUCores=&env.CPUCores
258+
}else {
259+
updateReq.CPUCores=&cpuCores
260+
}
261+
262+
ifmemGB==0 {
263+
updateReq.MemoryGB=&env.MemoryGB
264+
}else {
265+
updateReq.MemoryGB=&memGB
266+
}
267+
268+
ifdiskGB==0 {
269+
updateReq.DiskGB=&env.DiskGB
270+
}else {
271+
updateReq.DiskGB=&diskGB
272+
}
273+
274+
ifgpus==0 {
275+
updateReq.GPUs=&env.GPUs
276+
}else {
277+
updateReq.GPUs=&gpus
278+
}
279+
280+
ifimg=="" {
281+
updateReq.ImageID=&env.ImageID
282+
}else {
283+
updateReq.ImageID=&img
284+
}
285+
286+
iftag=="" {
287+
updateReq.ImageTag=&env.ImageTag
288+
}else {
289+
updateReq.ImageTag=&tag
290+
}
291+
292+
iferr:=client.EditEnvironment(cmd.Context(),env.ID,updateReq);err!=nil {
293+
returnxerrors.Errorf("failed to apply changes to environment: '%s'",envName)
294+
}
295+
296+
clog.LogSuccess(
297+
"applied changes to the environment, rebuilding...",
298+
clog.BlankLine,
299+
clog.Tip(`run "coder envs watch-build %q" to trail the build logs`,envName),
300+
)
301+
returnnil
302+
},
303+
}
304+
cmd.Flags().StringVarP(&img,"image","i","","image ID of the image you wan't the environment to be based off of.")
305+
cmd.Flags().StringVarP(&tag,"tag","t","latest","image tag of the image you wan't to base the environment off of.")
306+
cmd.Flags().Float32P("cpu","c",cpuCores,"The number of cpu cores the environment should be provisioned with.")
307+
cmd.Flags().Float32P("memory","m",memGB,"The amount of RAM an environment should be provisioned with.")
308+
cmd.Flags().IntP("disk","d",diskGB,"The amount of disk storage an environment should be provisioned with.")
309+
cmd.Flags().IntP("gpu","g",gpus,"The amount of disk storage to provision the environment with.")
310+
cmd.Flags().BoolVar(&follow,"follow",false,"follow buildlog after initiating rebuild")
311+
returncmd
312+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp