Skip to content

Commit

Permalink
refactor: code refactor and beta tag added to mongo command
Browse files Browse the repository at this point in the history
* docs update
  • Loading branch information
shyam-cb authored Mar 15, 2024
1 parent 2393321 commit aae36e7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ cbmigrate [command]

### Available Commands
- `help` - Displays help information about any command.
- `mongo` - Specific commands for migrating data from MongoDB.
- `mongo` - Migrate data from MongoDB to Couchbase

### Flags
- `-h, --help` - help for `cbmigrate`.
Expand Down
2 changes: 1 addition & 1 deletion cmd/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Execute() {
Usage: "Displays the version of this tool.",
},
}
cmd := common.NewCommand("cbmigrate", nil, nil, "", "", flags)
cmd := common.NewCommand(common.CBMigrate, nil, nil, "", "", flags)
cmd.AddCommand(completionCommand())
cmd.AddCommand(mongo.GetMongoMigrateCommand())
cmd.RunE = func(cmd *cobra.Command, args []string) error {
Expand Down
25 changes: 23 additions & 2 deletions cmd/common/command.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
package common

import (
"slices"
"strings"

"github.com/couchbaselabs/cbmigrate/cmd/flag"
"github.com/spf13/cobra"
)

type Command string

const (
Mongo = "mongo"
CBMigrate = "cbmigrate"
)

var BetaCommands = []Command{
Mongo,
}

// Example command example
type Example struct {
Value string
Usage string
}

// NewCommand command constructor
func NewCommand(name string, alias []string, examples []Example, short string, long string, flags []flag.Flag) *cobra.Command {
func NewCommand(name Command, alias []string, examples []Example, short string, long string, flags []flag.Flag) *cobra.Command {

var example strings.Builder
exsLen := len(examples)
Expand All @@ -40,8 +52,17 @@ func NewCommand(name string, alias []string, examples []Example, short string, l
flagUsages = append(flagUsages, "[--help HELP]")
flagUsage := strings.Join(flagUsages, " ")

if slices.Index(BetaCommands, name) > -1 {
if short != "" {
short = "[Beta] " + short
}
if long != "" {
long = "[Beta] " + long
}
}

cmd := &cobra.Command{
Use: name + " " + flagUsage,
Use: string(name) + " " + flagUsage,
Aliases: alias,
Example: example.String(),
Short: short,
Expand Down
3 changes: 2 additions & 1 deletion cmd/mongo/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,5 +208,6 @@ func NewCommand() *cobra.Command {
Usage: "Imports the data from mongo to couchbase.",
},
}
return common.NewCommand("mongo", []string{"m"}, examples, "", "", flags)
usage := "Migrate data from MongoDB to Couchbase"
return common.NewCommand(common.Mongo, []string{"m"}, examples, usage, usage, flags)
}

0 comments on commit aae36e7

Please sign in to comment.