This repository was archived by the owner on Aug 30, 2024. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork18
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
2 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
24 changes: 24 additions & 0 deletionsci/integration/integration_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletioncmd/coder/envs.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletioncmd/coder/logout.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionscmd/coder/main.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -42,6 +42,7 @@ func (r *rootCmd) Subcommands() []cli.Command { | ||
&urlsCmd{}, | ||
&versionCmd{}, | ||
&configSSHCmd{}, | ||
&usersCmd{}, | ||
} | ||
} | ||
2 changes: 1 addition & 1 deletioncmd/coder/shell.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletionscmd/coder/users.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package main | ||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"reflect" | ||
"strings" | ||
"text/tabwriter" | ||
"github.com/spf13/pflag" | ||
"go.coder.com/cli" | ||
"go.coder.com/flog" | ||
) | ||
type usersCmd struct { | ||
} | ||
func (cmd usersCmd) Spec() cli.CommandSpec { | ||
return cli.CommandSpec{ | ||
Name: "users", | ||
Usage: "[subcommand] <flags>", | ||
Desc: "interact with user accounts", | ||
} | ||
} | ||
func (cmd usersCmd) Run(fl *pflag.FlagSet) { | ||
exitUsage(fl) | ||
} | ||
func (cmd *usersCmd) Subcommands() []cli.Command { | ||
return []cli.Command{ | ||
&listCmd{}, | ||
} | ||
} | ||
type listCmd struct { | ||
outputFmt string | ||
} | ||
func tabDelimited(data interface{}) string { | ||
v := reflect.ValueOf(data) | ||
s := &strings.Builder{} | ||
for i := 0; i < v.NumField(); i++ { | ||
s.WriteString(fmt.Sprintf("%s\t", v.Field(i).Interface())) | ||
} | ||
return s.String() | ||
} | ||
func (cmd *listCmd) Run(fl *pflag.FlagSet) { | ||
entClient := requireAuth() | ||
users, err := entClient.Users() | ||
if err != nil { | ||
flog.Fatal("failed to get users: %v", err) | ||
} | ||
switch cmd.outputFmt { | ||
case "human": | ||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0) | ||
for _, u := range users { | ||
_, err = fmt.Fprintln(w, tabDelimited(u)) | ||
if err != nil { | ||
flog.Fatal("failed to write: %v", err) | ||
} | ||
} | ||
err = w.Flush() | ||
if err != nil { | ||
flog.Fatal("failed to flush writer: %v", err) | ||
} | ||
case "json": | ||
err = json.NewEncoder(os.Stdout).Encode(users) | ||
if err != nil { | ||
flog.Fatal("failed to encode users to json: %v", err) | ||
} | ||
default: | ||
exitUsage(fl) | ||
} | ||
} | ||
func (cmd *listCmd) RegisterFlags(fl *pflag.FlagSet) { | ||
fl.StringVarP(&cmd.outputFmt, "output", "o", "human", "output format (human | json)") | ||
} | ||
func (cmd *listCmd) Spec() cli.CommandSpec { | ||
return cli.CommandSpec{ | ||
Name: "ls", | ||
Usage: "<flags>", | ||
Desc: "list all users", | ||
cmoog marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
} | ||
} |
2 changes: 1 addition & 1 deletioncmd/coder/version.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
12 changes: 9 additions & 3 deletionsinternal/entclient/me.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletionsinternal/entclient/users.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package entclient | ||
// Users gets the list of user accounts | ||
func (c Client) Users() ([]User, error) { | ||
var u []User | ||
err := c.requestBody("GET", "/api/users", nil, &u) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return u, nil | ||
} |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.