package cmd import ( "fmt" "code.gitea.io/sdk/gitea" "github.com/spf13/cobra" ) var notificationUnreadCmd = &cobra.Command{ Use: "unread ", Short: "Mark a notification as unread", Long: "Mark a single notification thread as unread by its ID.", Args: cobra.ExactArgs(1), RunE: runNotificationState(gitea.NotifyStatusUnread, "unread"), } var notificationPinCmd = &cobra.Command{ Use: "pin ", Short: "Pin a notification", Long: "Mark a single notification thread as pinned by its ID.", Args: cobra.ExactArgs(1), RunE: runNotificationState(gitea.NotifyStatusPinned, "pinned"), } var notificationUnpinCmd = &cobra.Command{ Use: "unpin ", Short: "Un-pin a notification", Long: "Un-pin a notification thread (marks it as read).", Args: cobra.ExactArgs(1), RunE: runNotificationState(gitea.NotifyStatusRead, "unpinned"), } func init() { notificationCmd.AddCommand(notificationUnreadCmd) notificationCmd.AddCommand(notificationPinCmd) notificationCmd.AddCommand(notificationUnpinCmd) } func runNotificationState(status gitea.NotifyStatus, verb string) func(*cobra.Command, []string) error { return func(cmd *cobra.Command, args []string) error { id, err := parseIssueArg(args[0]) if err != nil { return fmt.Errorf("invalid notification id %q: %w", args[0], err) } client, err := loadClient() if err != nil { return err } if _, _, err := client.ReadNotification(id, status); err != nil { return fmt.Errorf("failed to mark notification %d as %s: %w", id, verb, err) } cs := ios.ColorScheme() fmt.Fprintf(ios.Out, "%s Marked notification %d as %s\n", cs.SuccessIcon(), id, verb) return nil } }