mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: filter users by github user id in the users list CLI command (#17029)
Add the `--github-user-id` option to `coder users list`, which makes the command only return users with a matching GitHub user id. This will enable https://github.com/coder/start-workspace-action to find a Coder user that corresponds to a GitHub user requesting to start a workspace.
This commit is contained in:
+3
@@ -9,6 +9,9 @@ OPTIONS:
|
||||
-c, --column [id|username|email|created at|updated at|status] (default: username,email,created at,status)
|
||||
Columns to display in table output.
|
||||
|
||||
--github-user-id int
|
||||
Filter users by their GitHub user ID.
|
||||
|
||||
-o, --output table|json (default: table)
|
||||
Output format.
|
||||
|
||||
|
||||
+17
-1
@@ -19,6 +19,7 @@ func (r *RootCmd) userList() *serpent.Command {
|
||||
cliui.JSONFormat(),
|
||||
)
|
||||
client := new(codersdk.Client)
|
||||
var githubUserID int64
|
||||
|
||||
cmd := &serpent.Command{
|
||||
Use: "list",
|
||||
@@ -27,8 +28,23 @@ func (r *RootCmd) userList() *serpent.Command {
|
||||
serpent.RequireNArgs(0),
|
||||
r.InitClient(client),
|
||||
),
|
||||
Options: serpent.OptionSet{
|
||||
{
|
||||
Name: "github-user-id",
|
||||
Description: "Filter users by their GitHub user ID.",
|
||||
Default: "",
|
||||
Flag: "github-user-id",
|
||||
Required: false,
|
||||
Value: serpent.Int64Of(&githubUserID),
|
||||
},
|
||||
},
|
||||
Handler: func(inv *serpent.Invocation) error {
|
||||
res, err := client.Users(inv.Context(), codersdk.UsersRequest{})
|
||||
req := codersdk.UsersRequest{}
|
||||
if githubUserID != 0 {
|
||||
req.Search = fmt.Sprintf("github_com_user_id:%d", githubUserID)
|
||||
}
|
||||
|
||||
res, err := client.Users(inv.Context(), req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user