feat: refresh all or activated subscriptions
This commit is contained in:
@ -46,22 +46,47 @@ func newSubscriptionAddCmd() *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newSubscriptionRefreshCmd() *cobra.Command {
|
func newSubscriptionRefreshCmd() *cobra.Command {
|
||||||
var backup bool
|
var backup, all bool
|
||||||
c := &cobra.Command{
|
c := &cobra.Command{
|
||||||
Use: "refresh <name>",
|
Use: "refresh [name]",
|
||||||
Short: "Refresh a subscription",
|
Short: "Refresh a subscription (all active ones if name is omitted)",
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.MaximumNArgs(1),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
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("", "", "")
|
m, err := newManagers("", "", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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()
|
m.Core.ReloadService()
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
c.Flags().BoolVar(&backup, "backup", false, "Backup the existing file before refreshing")
|
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
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user