From a3e3079af1bcbf173db29b2569e820022c4c9f65 Mon Sep 17 00:00:00 2001 From: Klesh Wong Date: Mon, 20 Jul 2026 23:36:28 +0800 Subject: [PATCH] feat: refresh all or activated subscriptions --- internal/cli/subscription.go | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/internal/cli/subscription.go b/internal/cli/subscription.go index 8dba9dd..578081f 100644 --- a/internal/cli/subscription.go +++ b/internal/cli/subscription.go @@ -46,22 +46,47 @@ func newSubscriptionAddCmd() *cobra.Command { } func newSubscriptionRefreshCmd() *cobra.Command { - var backup bool + var backup, all bool c := &cobra.Command{ - Use: "refresh ", - Short: "Refresh a subscription", - Args: cobra.ExactArgs(1), + Use: "refresh [name]", + Short: "Refresh a subscription (all active ones if name is omitted)", + Args: cobra.MaximumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { + if all && len(args) > 0 { + return fmt.Errorf("cannot specify a subscription name together with --all") + } + m, err := newManagers("", "", "") if err != nil { return err } - m.Subscription.RefreshSubscription(args[0], backup) + + var names []string + switch { + case len(args) == 1: + names = []string{args[0]} + case all: + names = m.Subscription.Data.OrderedNames() + default: + for _, sub := range m.Subscription.Data.GetActiveSubscriptions() { + names = append(names, sub.Name) + } + } + + if len(names) == 0 { + fmt.Println("❌ No active subscription found") + return nil + } + + for _, name := range names { + m.Subscription.RefreshSubscription(name, backup) + } m.Core.ReloadService() return nil }, } c.Flags().BoolVar(&backup, "backup", false, "Backup the existing file before refreshing") + c.Flags().BoolVarP(&all, "all", "a", false, "Refresh every subscription, not just active ones") return c }