()
| 124 | } |
| 125 | |
| 126 | func (r *RootCmd) customNotifications() *serpent.Command { |
| 127 | cmd := &serpent.Command{ |
| 128 | Use: "custom <title> <message>", |
| 129 | Short: "Send a custom notification", |
| 130 | Middleware: serpent.Chain( |
| 131 | serpent.RequireNArgs(2), |
| 132 | ), |
| 133 | Handler: func(inv *serpent.Invocation) error { |
| 134 | client, err := r.InitClient(inv) |
| 135 | if err != nil { |
| 136 | return err |
| 137 | } |
| 138 | err = client.PostCustomNotification(inv.Context(), codersdk.CustomNotificationRequest{ |
| 139 | Content: &codersdk.CustomNotificationContent{ |
| 140 | Title: inv.Args[0], |
| 141 | Message: inv.Args[1], |
| 142 | }, |
| 143 | }) |
| 144 | if err != nil { |
| 145 | return xerrors.Errorf("unable to post custom notification: %w", err) |
| 146 | } |
| 147 | |
| 148 | _, _ = fmt.Fprintln(inv.Stderr, "A custom notification has been sent.") |
| 149 | return nil |
| 150 | }, |
| 151 | } |
| 152 | return cmd |
| 153 | } |
no test coverage detected