Skip to content

Commit

Permalink
feat: vsctl add id for ns,eb,sub create
Browse files Browse the repository at this point in the history
Signed-off-by: xdlbdy <xdlbdy@gmail.com>
  • Loading branch information
xdlbdy committed Aug 10, 2023
1 parent 2735bb4 commit adcf895
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions vsctl/command/eventbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package command
import (
"context"
"encoding/json"
"fmt"
"os"
"time"

Expand Down Expand Up @@ -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,
Expand All @@ -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")
Expand Down
12 changes: 12 additions & 0 deletions vsctl/command/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package command
import (
"context"
"encoding/json"
"fmt"
"os"
"time"

Expand All @@ -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"
Expand Down Expand Up @@ -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,
})
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions vsctl/command/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand Down

0 comments on commit adcf895

Please sign in to comment.