12 |
12 |
13 "github.com/McKael/madon" |
13 "github.com/McKael/madon" |
14 ) |
14 ) |
15 |
15 |
16 var notificationsOpts struct { |
16 var notificationsOpts struct { |
17 list, clear bool |
17 list, clear, dismiss bool |
18 notifID int |
18 notifID int |
19 } |
19 } |
20 |
20 |
21 // notificationsCmd represents the notifications subcommand |
21 // notificationsCmd represents the notifications subcommand |
22 var notificationsCmd = &cobra.Command{ |
22 var notificationsCmd = &cobra.Command{ |
23 Use: "notifications", // XXX |
23 Use: "notifications", // XXX |
24 Aliases: []string{"notification", "notif"}, |
24 Aliases: []string{"notification", "notif"}, |
25 Short: "Manage notifications", |
25 Short: "Manage notifications", |
26 Example: ` madonctl accounts notifications --list |
26 Example: ` madonctl accounts notifications --list |
27 madonctl accounts notifications --list --clear |
27 madonctl accounts notifications --list --clear |
|
28 madonctl accounts notifications --dismiss --notification-id N |
28 madonctl accounts notifications --notification-id N`, |
29 madonctl accounts notifications --notification-id N`, |
29 //Long: `TBW...`, |
30 //Long: `TBW...`, |
30 RunE: notificationRunE, |
31 RunE: notificationRunE, |
31 } |
32 } |
32 |
33 |
33 func init() { |
34 func init() { |
34 accountsCmd.AddCommand(notificationsCmd) |
35 accountsCmd.AddCommand(notificationsCmd) |
35 |
36 |
36 notificationsCmd.Flags().BoolVar(¬ificationsOpts.list, "list", false, "List all current notifications") |
37 notificationsCmd.Flags().BoolVar(¬ificationsOpts.list, "list", false, "List all current notifications") |
37 notificationsCmd.Flags().BoolVar(¬ificationsOpts.clear, "clear", false, "Clear all current notifications") |
38 notificationsCmd.Flags().BoolVar(¬ificationsOpts.clear, "clear", false, "Clear all current notifications") |
|
39 notificationsCmd.Flags().BoolVar(¬ificationsOpts.dismiss, "dismiss", false, "Delete a notification") |
38 notificationsCmd.Flags().IntVar(¬ificationsOpts.notifID, "notification-id", 0, "Get a notification") |
40 notificationsCmd.Flags().IntVar(¬ificationsOpts.notifID, "notification-id", 0, "Get a notification") |
39 } |
41 } |
40 |
42 |
41 func notificationRunE(cmd *cobra.Command, args []string) error { |
43 func notificationRunE(cmd *cobra.Command, args []string) error { |
42 opt := notificationsOpts |
44 opt := notificationsOpts |
58 if accountsOpts.limit > 0 { |
60 if accountsOpts.limit > 0 { |
59 notifications = notifications[:accountsOpts.limit] |
61 notifications = notifications[:accountsOpts.limit] |
60 } |
62 } |
61 obj = notifications |
63 obj = notifications |
62 } else if opt.notifID > 0 { |
64 } else if opt.notifID > 0 { |
63 obj, err = gClient.GetNotification(opt.notifID) |
65 if opt.dismiss { |
|
66 err = gClient.DismissNotification(opt.notifID) |
|
67 } else { |
|
68 obj, err = gClient.GetNotification(opt.notifID) |
|
69 } |
64 } |
70 } |
65 |
71 |
66 if err == nil && opt.clear { |
72 if err == nil && opt.clear { |
67 err = gClient.ClearNotifications() |
73 err = gClient.ClearNotifications() |
68 } |
74 } |