Skip to content

Commit

Permalink
Changes from self review
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <mattalord@gmail.com>
  • Loading branch information
mattlord committed Feb 18, 2025
1 parent 71439f8 commit 6ebd054
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
30 changes: 15 additions & 15 deletions go/cmd/vtctldclient/cli/pflag.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,25 @@ func (v *KeyspaceTypeFlag) Type() string {
return "cli.KeyspaceTypeFlag"
}

// VerbosityLevelFlag implements the pflag.Value interface, for parsing a command-line value
// into a vtctldatapb.VerbosityLevel.
// VerbosityLevelFlag implements the pflag.Value interface, for parsing a command-line
// string value into a vtctldatapb.VerbosityLevel.
type VerbosityLevelFlag vtctldatapb.VerbosityLevel

// String is part of the pflag.Value interfaces.
// String is part of the pflag.Value interface.
func (vlf *VerbosityLevelFlag) String() string {
return vtctldatapb.VerbosityLevel(*vlf).String()
}

// Set is part of the pflag.Value interface.
func (vlf *VerbosityLevelFlag) Set(v string) error {
t, err := ParseVerbosityLevelFlag(v)
*vlf = VerbosityLevelFlag(t)
return err
}

// Type is part of the pflag.Value interface.
func (*VerbosityLevelFlag) Type() string { return "vtctldata.VerbosityLevel" }

// ParseVerbosityLevelFlag parses the string value into the enum type.
func ParseVerbosityLevelFlag(param string) (vtctldatapb.VerbosityLevel, error) {
value, ok := vtctldatapb.VerbosityLevel_value[strings.ToUpper(param)]
Expand All @@ -76,8 +86,8 @@ func ParseVerbosityLevelFlag(param string) (vtctldatapb.VerbosityLevel, error) {
return vtctldatapb.VerbosityLevel(value), nil
}

// GetVerbosityLevelFlagOptions returns a list of valid values which can be provided for
// the VerbosityLevelFlag.
// GetVerbosityLevelFlagOptions returns a logically sorted list of valid values which
// can be provided for the VerbosityLevelFlag.
func GetVerbosityLevelFlagOptions() []string {
enumVals := maps.Values(vtctldatapb.VerbosityLevel_value)
slices.Sort(enumVals)
Expand All @@ -87,13 +97,3 @@ func GetVerbosityLevelFlagOptions() []string {
}
return strVals
}

// Set is part of the pflag.Value interfaces.
func (vlf *VerbosityLevelFlag) Set(v string) error {
t, err := ParseVerbosityLevelFlag(v)
*vlf = VerbosityLevelFlag(t)
return err
}

// Type is part of the pflag.Value interface.
func (*VerbosityLevelFlag) Type() string { return "vtctldatapb.VerbosityLevel" }
4 changes: 3 additions & 1 deletion go/cmd/vtctldclient/command/vreplication/common/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package common

import (
"fmt"
"strings"

"github.com/spf13/cobra"

Expand All @@ -43,7 +44,8 @@ func GetShowCommand(opts *SubCommandsOpts) *cobra.Command {
RunE: commandShow,
}
cmd.Flags().BoolVar(&ShowOptions.IncludeLogs, "include-logs", true, "Include recent logs for the workflow.")
cmd.Flags().Var((*cli.VerbosityLevelFlag)(&ShowOptions.Verbosity), "verbosity-level", "How much detail to include in the results.")
cmd.Flags().Var((*cli.VerbosityLevelFlag)(&ShowOptions.Verbosity), "verbosity-level", fmt.Sprintf("How much detail to include in the results. Valid values are: %s.",
strings.Join(cli.GetVerbosityLevelFlagOptions(), ",")))
return cmd
}

Expand Down
9 changes: 7 additions & 2 deletions go/cmd/vtctldclient/command/vreplication/workflow/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ limitations under the License.
package workflow

import (
"fmt"
"strings"

"github.com/spf13/cobra"

"vitess.io/vitess/go/cmd/vtctldclient/cli"
Expand Down Expand Up @@ -59,7 +62,8 @@ func registerCommands(root *cobra.Command) {

getWorkflows.Flags().BoolVar(&workflowShowOptions.IncludeLogs, "include-logs", true, "Include recent logs for the workflows.")
getWorkflows.Flags().BoolVarP(&getWorkflowsOptions.ShowAll, "show-all", "a", false, "Show all workflows instead of just active workflows.")
getWorkflows.Flags().Var((*cli.VerbosityLevelFlag)(&getWorkflowsOptions.Verbosity), "verbosity-level", "How much detail to include in the results.")
getWorkflows.Flags().Var((*cli.VerbosityLevelFlag)(&getWorkflowsOptions.Verbosity), "verbosity-level", fmt.Sprintf("How much detail to include in the results. Valid values are: %s.",
strings.Join(cli.GetVerbosityLevelFlagOptions(), ",")))
root.AddCommand(getWorkflows) // Yes this is supposed to be root as GetWorkflows is a top-level command.

delete.Flags().StringVarP(&baseOptions.Workflow, "workflow", "w", "", "The workflow you want to delete.")
Expand All @@ -76,7 +80,8 @@ func registerCommands(root *cobra.Command) {
show.Flags().StringVarP(&baseOptions.Workflow, "workflow", "w", "", "The workflow you want the details for.")
show.MarkFlagRequired("workflow")
show.Flags().BoolVar(&workflowShowOptions.IncludeLogs, "include-logs", true, "Include recent logs for the workflow.")
show.Flags().Var((*cli.VerbosityLevelFlag)(&workflowShowOptions.Verbosity), "verbosity-level", "How much detail to include in the results.")
show.Flags().Var((*cli.VerbosityLevelFlag)(&workflowShowOptions.Verbosity), "verbosity-level", fmt.Sprintf("How much detail to include in the results. Valid values are: %s.",
strings.Join(cli.GetVerbosityLevelFlagOptions(), ",")))
common.AddShardSubsetFlag(show, &baseOptions.Shards)
base.AddCommand(show)

Expand Down
1 change: 1 addition & 0 deletions go/test/endtoend/vreplication/wrappers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/stretchr/testify/require"

"vitess.io/vitess/go/vt/log"

vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
)

Expand Down

0 comments on commit 6ebd054

Please sign in to comment.