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

Commit30126a3

Browse files
author
Faris Huskovic
committed
implement coder images ls
1 parentce06c53 commit30126a3

File tree

8 files changed

+207
-13
lines changed

8 files changed

+207
-13
lines changed

‎ci/integration/images_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package integration
2+
3+
import (
4+
"context"
5+
"regexp"
6+
"testing"
7+
8+
"cdr.dev/coder-cli/coder-sdk"
9+
"cdr.dev/coder-cli/pkg/tcli"
10+
)
11+
12+
funcTestImagesCLI(t*testing.T) {
13+
t.Parallel()
14+
15+
run(t,"coder-cli-images-tests",func(t*testing.T,ctx context.Context,c*tcli.ContainerRunner) {
16+
headlessLogin(ctx,t,c)
17+
18+
// Successfully output help.
19+
c.Run(ctx,"coder images --help").Assert(t,
20+
tcli.Success(),
21+
tcli.StdoutMatches(regexp.QuoteMeta("Manage existing images and/or import new ones.")),
22+
tcli.StderrEmpty(),
23+
)
24+
25+
// OK - human output
26+
c.Run(ctx,"coder images ls").Assert(t,
27+
tcli.Success(),
28+
)
29+
30+
imgs:= []coder.Image{}
31+
// OK - json output
32+
c.Run(ctx,"coder images ls --output json").Assert(t,
33+
tcli.Success(),
34+
tcli.StdoutJSONUnmarshal(&imgs),
35+
)
36+
37+
// Org not found
38+
c.Run(ctx,"coder images ls --org doesntexist").Assert(t,
39+
tcli.Error(),
40+
tcli.StderrMatches(regexp.QuoteMeta("org name\"doesntexist\" not found\n\n")),
41+
)
42+
})
43+
}

‎coder-sdk/image.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ import (
88

99
// Image describes a Coder Image.
1010
typeImagestruct {
11-
IDstring`json:"id"`
12-
OrganizationIDstring`json:"organization_id"`
13-
Repositorystring`json:"repository"`
14-
Descriptionstring`json:"description"`
15-
URLstring`json:"url"`// User-supplied URL for image.
16-
Registry*Registry`json:"registry"`
17-
DefaultTag*ImageTag`json:"default_tag"`
18-
DefaultCPUCoresfloat32`json:"default_cpu_cores"`
19-
DefaultMemoryGBfloat32`json:"default_memory_gb"`
20-
DefaultDiskGBint`json:"default_disk_gb"`
21-
Deprecatedbool`json:"deprecated"`
22-
CreatedAt time.Time`json:"created_at"`
23-
UpdatedAt time.Time`json:"updated_at"`
11+
IDstring`json:"id" table:"-"`
12+
OrganizationIDstring`json:"organization_id" table:"-"`
13+
Repositorystring`json:"repository" table:"Repository"`
14+
Descriptionstring`json:"description" table:"-"`
15+
URLstring`json:"url" table:"-"`// User-supplied URL for image.
16+
Registry*Registry`json:"registry" table:"-"`
17+
DefaultTag*ImageTag`json:"default_tag" table:"DefaultTag"`
18+
DefaultCPUCoresfloat32`json:"default_cpu_cores" table:"DefaultCPUCores"`
19+
DefaultMemoryGBfloat32`json:"default_memory_gb" table:"DefaultMemoryGB"`
20+
DefaultDiskGBint`json:"default_disk_gb" table:"DefaultDiskGB"`
21+
Deprecatedbool`json:"deprecated" table:"-"`
22+
CreatedAt time.Time`json:"created_at" table:"-"`
23+
UpdatedAt time.Time`json:"updated_at" table:"-"`
2424
}
2525

2626
// NewRegistryRequest describes a docker registry used in importing an image.

‎coder-sdk/tags.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ type ImageTag struct {
1818
CreatedAt time.Time`json:"created_at" table:"-"`
1919
}
2020

21+
func (iImageTag)String()string {
22+
returni.Tag
23+
}
24+
2125
// OSRelease is the marshalled /etc/os-release file.
2226
typeOSReleasestruct {
2327
IDstring`json:"id"`

‎docs/coder.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ coder provides a CLI for working with an existing Coder Enterprise installation
1414
*[coder completion](coder_completion.md) - Generate completion script
1515
*[coder config-ssh](coder_config-ssh.md) - Configure SSH to access Coder environments
1616
*[coder envs](coder_envs.md) - Interact with Coder environments
17+
*[coder images](coder_images.md) - Manage Coder images
1718
*[coder login](coder_login.md) - Authenticate this client for future operations
1819
*[coder logout](coder_logout.md) - Remove local authentication credentials if any exist
1920
*[coder sh](coder_sh.md) - Open a shell and execute commands in a Coder environment

‎docs/coder_images.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
##coder images
2+
3+
Manage Coder images
4+
5+
###Synopsis
6+
7+
Manage existing images and/or import new ones.
8+
9+
###Options
10+
11+
```
12+
-h, --help help for images
13+
--user string Specifies the user by email (default "me")
14+
```
15+
16+
###Options inherited from parent commands
17+
18+
```
19+
-v, --verbose show verbose output
20+
```
21+
22+
###SEE ALSO
23+
24+
*[coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
25+
*[coder images ls](coder_images_ls.md) - list all images available to the active user
26+

‎docs/coder_images_ls.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
##coder images ls
2+
3+
list all images available to the active user
4+
5+
###Synopsis
6+
7+
List all Coder images available to the active user.
8+
9+
```
10+
coder images ls [flags]
11+
```
12+
13+
###Options
14+
15+
```
16+
-h, --help help for ls
17+
--org string organization name
18+
--output string human | json (default "human")
19+
```
20+
21+
###Options inherited from parent commands
22+
23+
```
24+
--user string Specifies the user by email (default "me")
25+
-v, --verbose show verbose output
26+
```
27+
28+
###SEE ALSO
29+
30+
*[coder images](coder_images.md) - Manage Coder images
31+

‎internal/cmd/cmd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func Make() *cobra.Command {
3535
tokensCmd(),
3636
resourceCmd(),
3737
completionCmd(),
38+
imgsCmd(),
3839
genDocsCmd(app),
3940
)
4041
app.PersistentFlags().BoolVarP(&verbose,"verbose","v",false,"show verbose output")

‎internal/cmd/images.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package cmd
2+
3+
import (
4+
"encoding/json"
5+
"os"
6+
7+
"cdr.dev/coder-cli/coder-sdk"
8+
"cdr.dev/coder-cli/pkg/clog"
9+
"cdr.dev/coder-cli/pkg/tablewriter"
10+
"github.com/spf13/cobra"
11+
"golang.org/x/xerrors"
12+
)
13+
14+
funcimgsCmd()*cobra.Command {
15+
varuserstring
16+
17+
cmd:=&cobra.Command{
18+
Use:"images",
19+
Short:"Manage Coder images",
20+
Long:"Manage existing images and/or import new ones.",
21+
}
22+
23+
cmd.PersistentFlags().StringVar(&user,"user",coder.Me,"Specifies the user by email")
24+
cmd.AddCommand(lsImgsCommand(&user))
25+
returncmd
26+
}
27+
28+
funclsImgsCommand(user*string)*cobra.Command {
29+
var (
30+
orgNamestring
31+
outputFmtstring
32+
)
33+
34+
cmd:=&cobra.Command{
35+
Use:"ls",
36+
Short:"list all images available to the active user",
37+
Long:"List all Coder images available to the active user.",
38+
RunE:func(cmd*cobra.Command,args []string)error {
39+
ctx:=cmd.Context()
40+
41+
client,err:=newClient(ctx)
42+
iferr!=nil {
43+
returnerr
44+
}
45+
46+
imgs,err:=getImgs(ctx,client,
47+
getImgsConf{
48+
email:*user,
49+
orgName:orgName,
50+
},
51+
)
52+
53+
iferr!=nil {
54+
returnerr
55+
}
56+
57+
iflen(imgs)<1 {
58+
clog.LogInfo("no images found")
59+
imgs= []coder.Image{}// ensures that json output still marshals
60+
}
61+
62+
switchoutputFmt {
63+
casejsonOutput:
64+
enc:=json.NewEncoder(os.Stdout)
65+
// pretty print the json
66+
enc.SetIndent("","\t")
67+
68+
iferr:=enc.Encode(imgs);err!=nil {
69+
returnxerrors.Errorf("write images as JSON: %w",err)
70+
}
71+
returnnil
72+
casehumanOutput:
73+
err=tablewriter.WriteTable(len(imgs),func(iint)interface{} {
74+
returnimgs[i]
75+
})
76+
iferr!=nil {
77+
returnxerrors.Errorf("write table: %w",err)
78+
}
79+
returnnil
80+
default:
81+
returnxerrors.Errorf("%q is not a supported value for --output",outputFmt)
82+
}
83+
},
84+
}
85+
cmd.Flags().StringVar(&orgName,"org","","organization name")
86+
cmd.Flags().StringVar(&outputFmt,"output",humanOutput,"human | json")
87+
returncmd
88+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp