feat: reorder subscriptions

This commit is contained in:
2026-07-20 09:17:38 +08:00
parent 087869d84f
commit ad49c3d2cb
6 changed files with 339 additions and 13 deletions

View File

@ -1,6 +1,10 @@
package cli
import "github.com/spf13/cobra"
import (
"fmt"
"github.com/spf13/cobra"
)
func newSubscriptionCmd() *cobra.Command {
cmd := &cobra.Command{
@ -17,6 +21,7 @@ func newSubscriptionCmd() *cobra.Command {
newSubscriptionGetURLCmd(),
newSubscriptionActivateCmd(),
newSubscriptionDeactivateCmd(),
newSubscriptionMoveCmd(),
newSubscriptionListCmd(),
newSubscriptionStorageCmd(),
)
@ -162,6 +167,37 @@ func newSubscriptionDeactivateCmd() *cobra.Command {
}
}
func newSubscriptionMoveCmd() *cobra.Command {
var before, after string
c := &cobra.Command{
Use: "move <name> --before|--after <target>",
Short: "Move a subscription before or after another in the list (affects display and config apply merge order)",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if (before == "") == (after == "") {
return fmt.Errorf("specify exactly one of --before or --after")
}
target := before
isBefore := true
if after != "" {
target = after
isBefore = false
}
m, err := newManagers("", "", "")
if err != nil {
return err
}
m.Subscription.MoveSubscription(args[0], target, isBefore)
return nil
},
}
c.Flags().StringVar(&before, "before", "", "Move the subscription immediately before this one")
c.Flags().StringVar(&after, "after", "", "Move the subscription immediately after this one")
return c
}
func newSubscriptionListCmd() *cobra.Command {
return &cobra.Command{
Use: "list",