mirror of
https://github.com/jech/galene.git
synced 2024-12-22 15:25:48 +01:00
Implement create- and delete-group.
This commit is contained in:
parent
5ef4bcb427
commit
c785b9b3f1
1 changed files with 60 additions and 0 deletions
|
@ -53,6 +53,14 @@ var commands = map[string]command{
|
|||
command: deletePasswordCmd,
|
||||
description: "delete a user's password",
|
||||
},
|
||||
"create-group": {
|
||||
command: createGroupCmd,
|
||||
description: "create a group",
|
||||
},
|
||||
"delete-group": {
|
||||
command: deleteGroupCmd,
|
||||
description: "delete a group",
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -451,3 +459,55 @@ func deletePasswordCmd(cmdname string, args []string) {
|
|||
log.Fatalf("Delete password: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func createGroupCmd(cmdname string, args []string) {
|
||||
cmd := flag.NewFlagSet(cmdname, flag.ExitOnError)
|
||||
setUsage(cmd, cmdname,
|
||||
"%v [option...] %v [option...] group\n",
|
||||
os.Args[0], cmdname,
|
||||
)
|
||||
cmd.Parse(args)
|
||||
|
||||
if cmd.NArg() != 1 {
|
||||
cmd.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
url, err := url.JoinPath(
|
||||
serverURL, "/galene-api/v0/.groups", cmd.Args()[0],
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("Build URL: %v", err)
|
||||
}
|
||||
|
||||
err = putJSON(url, map[string]any{}, false)
|
||||
if err != nil {
|
||||
log.Fatalf("Create group: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func deleteGroupCmd(cmdname string, args []string) {
|
||||
cmd := flag.NewFlagSet(cmdname, flag.ExitOnError)
|
||||
setUsage(cmd, cmdname,
|
||||
"%v [option...] %v [option...] group\n",
|
||||
os.Args[0], cmdname,
|
||||
)
|
||||
cmd.Parse(args)
|
||||
|
||||
if cmd.NArg() != 1 {
|
||||
cmd.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
url, err := url.JoinPath(
|
||||
serverURL, "/galene-api/v0/.groups", cmd.Args()[0],
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("Build URL: %v", err)
|
||||
}
|
||||
|
||||
err = deleteValue(url)
|
||||
if err != nil {
|
||||
log.Fatalf("Delete group: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue