-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdelete.go
More file actions
41 lines (33 loc) · 958 Bytes
/
delete.go
File metadata and controls
41 lines (33 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package events
import (
"fmt"
"net/http"
"os"
"github.com/spf13/cobra"
"github.com/acmcsufoss/api.acmcsuf.com/internal/cli/client"
"github.com/acmcsufoss/api.acmcsuf.com/internal/cli/config"
"github.com/acmcsufoss/api.acmcsuf.com/utils"
)
var DeleteEvent = &cobra.Command{
Use: "delete",
Short: "Delete an event with its id",
Run: func(cmd *cobra.Command, args []string) {
uuid, _ := cmd.Flags().GetString("id")
deleteEvent(uuid, config.Cfg)
},
}
func init() {
DeleteEvent.Flags().String("id", "", "Delete the identified event")
DeleteEvent.MarkFlagRequired("id")
}
func deleteEvent(id string, cfg *config.Config) {
deleteURL := config.GetBaseURL(cfg).JoinPath("v1", "events", id)
if body, err := client.SendRequestAndReadResponse(deleteURL, true, http.MethodDelete, nil); err != nil {
fmt.Fprintln(os.Stderr, "Error:", err)
if body != nil {
utils.PrettyPrintJSONErr(body)
}
} else {
utils.PrettyPrintJSON(body)
}
}