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

Commitc71c3c9

Browse files
author
Russtopia
committed
Add urls ls subcmd; add -o [human | json] support matching users cmd
1 parent362ddc7 commitc71c3c9

File tree

1 file changed

+62
-28
lines changed

1 file changed

+62
-28
lines changed

‎cmd/coder/urls.go

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,26 @@ import (
1818

1919
typeurlsCmdstruct{}
2020

21+
func (cmd*urlsCmd)Subcommands() []cli.Command {
22+
return []cli.Command{
23+
&listSubCmd{},
24+
&createSubCmd{},
25+
&delSubCmd{},
26+
}
27+
}
28+
29+
func (cmdurlsCmd)Spec() cli.CommandSpec {
30+
return cli.CommandSpec{
31+
Name:"urls",
32+
Usage:"[subcommand] <flags>",
33+
Desc:"interact with environment devurls",
34+
}
35+
}
36+
37+
func (cmdurlsCmd)Run(fl*pflag.FlagSet) {
38+
exitUsage(fl)
39+
}
40+
2141
// DevURL is the parsed json response record for a devURL from cemanager
2242
typeDevURLstruct {
2343
IDstring`json:"id"`
@@ -57,6 +77,48 @@ func accessLevelIsValid(level string) bool {
5777
returnok
5878
}
5979

80+
typelistSubCmdstruct {
81+
outputFmtstring
82+
}
83+
84+
// Run gets the list of active devURLs from the cemanager for the
85+
// specified environment and outputs info to stdout.
86+
func (sublistSubCmd)Run(fl*pflag.FlagSet) {
87+
envName:=fl.Arg(0)
88+
devURLs:=urlList(envName)
89+
90+
switchsub.outputFmt {
91+
case"human":
92+
w:=tabwriter.NewWriter(os.Stdout,0,0,1,' ',tabwriter.TabIndent)
93+
for_,devURL:=rangedevURLs {
94+
fmt.Fprintf(w,"%s\t%d\t%s\n",devURL.URL,devURL.Port,devURL.Access)
95+
}
96+
err:=w.Flush()
97+
iferr!=nil {
98+
flog.Fatal("failed to flush writer: %v",err)
99+
}
100+
case"json":
101+
err:=json.NewEncoder(os.Stdout).Encode(devURLs)
102+
iferr!=nil {
103+
flog.Fatal("failed to encode devurls to json: %v",err)
104+
}
105+
default:
106+
exitUsage(fl)
107+
}
108+
}
109+
110+
func (sub*listSubCmd)RegisterFlags(fl*pflag.FlagSet) {
111+
fl.StringVarP(&sub.outputFmt,"output","o","human","output format (human | json)")
112+
}
113+
114+
func (sub*listSubCmd)Spec() cli.CommandSpec {
115+
return cli.CommandSpec{
116+
Name:"ls",
117+
Usage:"<env> <flags>",
118+
Desc:"list all devurls",
119+
}
120+
}
121+
60122
typecreateSubCmdstruct {
61123
accessstring
62124
urlnamestring
@@ -181,14 +243,6 @@ func (sub delSubCmd) Run(fl *pflag.FlagSet) {
181243
}
182244
}
183245

184-
func (cmdurlsCmd)Spec() cli.CommandSpec {
185-
return cli.CommandSpec{
186-
Name:"urls",
187-
Usage:"<env name>",
188-
Desc:"get all development urls for external access",
189-
}
190-
}
191-
192246
// urlList returns the list of active devURLs from the cemanager.
193247
funcurlList(envNamestring) []DevURL {
194248
entClient:=requireAuth()
@@ -217,23 +271,3 @@ func urlList(envName string) []DevURL {
217271

218272
returndevURLs
219273
}
220-
221-
// Run gets the list of active devURLs from the cemanager for the
222-
// specified environment and outputs info to stdout.
223-
func (cmdurlsCmd)Run(fl*pflag.FlagSet) {
224-
envName:=fl.Arg(0)
225-
devURLs:=urlList(envName)
226-
227-
w:=tabwriter.NewWriter(os.Stdout,0,0,1,' ',tabwriter.TabIndent)
228-
for_,devURL:=rangedevURLs {
229-
fmt.Fprintf(w,"%s\t%d\t%s\n",devURL.URL,devURL.Port,devURL.Access)
230-
}
231-
w.Flush()
232-
}
233-
234-
func (cmd*urlsCmd)Subcommands() []cli.Command {
235-
return []cli.Command{
236-
&createSubCmd{},
237-
&delSubCmd{},
238-
}
239-
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp