diff --git a/vsctl/command/eventbus.go b/vsctl/command/eventbus.go index 2bf1157ff..dfb83fb76 100644 --- a/vsctl/command/eventbus.go +++ b/vsctl/command/eventbus.go @@ -17,6 +17,7 @@ package command import ( "context" "encoding/json" + "fmt" "os" "time" @@ -58,7 +59,16 @@ func createEventbusCommand() *cobra.Command { if eventbus == "" { cmdFailedf(cmd, "the --name flag MUST be set") } + var id uint64 + if idStr != "" { + vID, err := vanus.NewIDFromString(idStr) + if err != nil { + cmdFailedWithHelpNotice(cmd, fmt.Sprintf("invalid eventbus id: %s\n", err.Error())) + } + id = vID.Uint64() + } eb, err := client.CreateEventbus(context.Background(), &ctrlpb.CreateEventbusRequest{ + Id: id, Name: eventbus, LogNumber: eventlogNum, Description: description, @@ -84,6 +94,7 @@ func createEventbusCommand() *cobra.Command { } }, } + cmd.Flags().StringVar(&idStr, "id", "", "eventbus id to create") cmd.Flags().StringVar(&namespace, "namespace", "default", "namespace name to create eventbus, default name is default") cmd.Flags().StringVar(&eventbus, "name", "", "eventbus name to create") cmd.Flags().Int32Var(&eventlogNum, "eventlog", 1, "number of eventlog") diff --git a/vsctl/command/namespace.go b/vsctl/command/namespace.go index 5429e9b85..529dfec94 100644 --- a/vsctl/command/namespace.go +++ b/vsctl/command/namespace.go @@ -17,6 +17,7 @@ package command import ( "context" "encoding/json" + "fmt" "os" "time" @@ -26,6 +27,7 @@ import ( "github.com/spf13/cobra" "google.golang.org/protobuf/types/known/emptypb" + "github.com/vanus-labs/vanus/internal/primitive/vanus" ctrlpb "github.com/vanus-labs/vanus/proto/pkg/controller" "github.com/vanus-labs/vanus/proto/pkg/meta" metapb "github.com/vanus-labs/vanus/proto/pkg/meta" @@ -59,7 +61,16 @@ func createNamespaceCommand() *cobra.Command { if namespace == "" { cmdFailedf(cmd, "the --name flag MUST be set") } + var id uint64 + if idStr != "" { + vID, err := vanus.NewIDFromString(idStr) + if err != nil { + cmdFailedWithHelpNotice(cmd, fmt.Sprintf("invalid namespace id: %s\n", err.Error())) + } + id = vID.Uint64() + } _, err := client.CreateNamespace(context.Background(), &ctrlpb.CreateNamespaceRequest{ + Id: id, Name: namespace, Description: description, }) @@ -82,6 +93,7 @@ func createNamespaceCommand() *cobra.Command { } }, } + cmd.Flags().StringVar(&idStr, "id", "", "namespace id to create") cmd.Flags().StringVar(&namespace, "name", "", "namespace name to creating") cmd.Flags().StringVar(&description, "description", "", "namespace description") return cmd diff --git a/vsctl/command/subscription.go b/vsctl/command/subscription.go index e6f57e14a..ad0238f45 100644 --- a/vsctl/command/subscription.go +++ b/vsctl/command/subscription.go @@ -88,7 +88,16 @@ func createSubscriptionCommand() *cobra.Command { DisableDeadLetter: disableDeadLetter, } getSubscriptionConfig(cmd, config) + var id uint64 + if idStr != "" { + vID, err := vanus.NewIDFromString(idStr) + if err != nil { + cmdFailedWithHelpNotice(cmd, fmt.Sprintf("invalid subscription id: %s\n", err.Error())) + } + id = vID.Uint64() + } res, err := client.CreateSubscription(context.Background(), &ctrlpb.CreateSubscriptionRequest{ + Id: id, Subscription: &ctrlpb.SubscriptionRequest{ Config: config, Filters: filter, @@ -109,6 +118,7 @@ func createSubscriptionCommand() *cobra.Command { printSubscription(cmd, false, false, false, res) }, } + cmd.Flags().StringVar(&idStr, "id", "", "subscription id to create") cmd.Flags().StringVar(&namespace, "namespace", "default", "namespace name, default name is default") cmd.Flags().StringVar(&eventbus, "eventbus", "", "eventbus name to consuming") cmd.Flags().StringVar(&sink, "sink", "", "the event you want to send to")