diff options
author | sanine-a <sanine.not@pm.me> | 2023-05-10 14:43:35 -0500 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2023-05-10 14:43:35 -0500 |
commit | 2aac43407d7b2699d956b7c626da4f45c802c53c (patch) | |
tree | bb837305076e229e1aabe55a6e9ce5b0c9cf982b | |
parent | c4dbe6328640f8ac43518a642e77dec061bfdd03 (diff) |
add rm command
-rw-r--r-- | conf/delete.go | 54 | ||||
-rw-r--r-- | conf/main.go | 1 |
2 files changed, 55 insertions, 0 deletions
diff --git a/conf/delete.go b/conf/delete.go new file mode 100644 index 0000000..384e392 --- /dev/null +++ b/conf/delete.go @@ -0,0 +1,54 @@ +package main + +import ( + "fmt" + "log" +) + + +var rmUser = &Command{ + Name: "user", + Execute: func(args []string) { + if len(args) < 1 { + fmt.Println("error: username not provided") + return + } + username := args[0] + user, err := p.GetByUsername(username) + if err != nil { log.Fatal(err) } + err = p.DeleteUser(user) + if err != nil { log.Fatal(err) } + fmt.Printf("deleted user %v\n", username) + }, +} + + +var rmEndpoint = &Command{ + Name: "endpoint", + Execute: func(args []string) { + if len(args) < 1 { + fmt.Println("error: endpointname not provided") + return + } + name := args[0] + endpoint, err := p.GetEndpointByName(name) + if err != nil { log.Fatal(err) } + err = p.DeleteEndpoint(endpoint) + if err != nil { log.Fatal(err) } + fmt.Printf("deleted endpoint %v\n", name) + }, +} + + + + +func RmInit(parser *Command) { + rm := &Command{ + Name: "rm", + Branch: true, + } + + rm.AddCommand(rmUser) + rm.AddCommand(rmEndpoint) + parser.AddCommand(rm) +} diff --git a/conf/main.go b/conf/main.go index a768bac..5dc922c 100644 --- a/conf/main.go +++ b/conf/main.go @@ -90,6 +90,7 @@ func main() { parser = &Command{Branch: true} ListInit(parser) CreateInit(parser) + RmInit(parser) parser.Parse(flag.Args()) } |