mirror of
https://github.com/jech/galene.git
synced 2024-12-27 17:55:47 +01:00
Implement list-users command.
This commit is contained in:
parent
06e6b14391
commit
8446a39efc
1 changed files with 40 additions and 0 deletions
|
@ -64,6 +64,10 @@ var commands = map[string]command{
|
|||
command: deleteGroupCmd,
|
||||
description: "delete a group",
|
||||
},
|
||||
"list-users": {
|
||||
command: listUsersCmd,
|
||||
description: "list users",
|
||||
},
|
||||
"create-user": {
|
||||
command: createUserCmd,
|
||||
description: "create a user",
|
||||
|
@ -681,6 +685,42 @@ func parsePermissions(p string, expand bool) (any, error) {
|
|||
return pp.Permissions(nil), nil
|
||||
}
|
||||
|
||||
func listUsersCmd(cmdname string, args []string) {
|
||||
var groupname string
|
||||
cmd := flag.NewFlagSet(cmdname, flag.ExitOnError)
|
||||
setUsage(cmd, cmdname,
|
||||
"%v [option...] %v [option...]\n",
|
||||
os.Args[0], cmdname,
|
||||
)
|
||||
cmd.StringVar(&groupname, "group", "", "group")
|
||||
cmd.Parse(args)
|
||||
|
||||
if cmd.NArg() != 0 {
|
||||
cmd.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if groupname == "" {
|
||||
fmt.Fprintf(cmd.Output(),
|
||||
"Option \"-group\" is required\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
u, err := url.JoinPath(serverURL, "/galene-api/v0/.groups/", groupname,
|
||||
".users/")
|
||||
if err != nil {
|
||||
log.Fatalf("Build URL: %v", err)
|
||||
}
|
||||
var users []string
|
||||
err = getJSON(u, &users)
|
||||
if err != nil {
|
||||
log.Fatalf("Get users: %v", err)
|
||||
}
|
||||
for _, user := range users {
|
||||
fmt.Println(user)
|
||||
}
|
||||
}
|
||||
|
||||
func createUserCmd(cmdname string, args []string) {
|
||||
var groupname, username string
|
||||
var wildcard bool
|
||||
|
|
Loading…
Reference in a new issue