diff --git a/src/go/rpk/pkg/cli/args.go b/src/go/rpk/pkg/cli/args.go deleted file mode 100644 index 468b7983ae3c7..0000000000000 --- a/src/go/rpk/pkg/cli/args.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2020 Vectorized, Inc. -// -// Use of this software is governed by the Business Source License -// included in the file licenses/BSL.md -// -// As of the Change Date specified in that file, in accordance with -// the Business Source License, use of this software will be governed -// by the Apache License, Version 2.0 - -package cli - -import ( - "fmt" - - "github.com/spf13/cobra" -) - -// Wrapping cobra's matchAll function and return an error including usage String. -// MatchAll allows combining several PositionalArgs to work in concert. -func MatchAll(checks ...cobra.PositionalArgs) cobra.PositionalArgs { - return func(cmd *cobra.Command, args []string) error { - for _, check := range checks { - if err := check(cmd, args); err != nil { - return fmt.Errorf("%v\n\n%v", err, cmd.UsageString()) - } - } - return nil - } -} diff --git a/src/go/rpk/pkg/cli/args_test.go b/src/go/rpk/pkg/cli/args_test.go deleted file mode 100644 index 9b2e4778a7d79..0000000000000 --- a/src/go/rpk/pkg/cli/args_test.go +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2020 Vectorized, Inc. -// -// Use of this software is governed by the Business Source License -// included in the file licenses/BSL.md -// -// As of the Change Date specified in that file, in accordance with -// the Business Source License, use of this software will be governed -// by the Apache License, Version 2.0 - -package cli - -import ( - "bytes" - "fmt" - "testing" - - "github.com/spf13/cobra" - "github.com/stretchr/testify/require" -) - -func newRootCmd(pargs cobra.PositionalArgs) *cobra.Command { - return &cobra.Command{Use: "test", Args: pargs, Run: func(cmd *cobra.Command, args []string) { - fmt.Fprintf(cmd.OutOrStdout(), "ok") - }} -} - -func executeCommand(cmd *cobra.Command, args []string) (out string, err error) { - b := new(bytes.Buffer) - cmd.SetOut(b) - cmd.SetErr(b) - cmd.SetArgs(args) - _, e := cmd.ExecuteC() - - return b.String(), e -} - -func TestMatchAll(t *testing.T) { - // Arranged example to show the capability of MatchAll function, any kind of positional arguments - // validation can be used in the function. - positionalArgs := MatchAll(cobra.MinimumNArgs(1), cobra.MaximumNArgs(2)) - cmd := newRootCmd(positionalArgs) - - tests := []struct { - name string - args []string - output string - fail bool - }{ - { - name: "Should validate with 1 argument", - args: []string{"foo"}, - output: "ok", - fail: false, - }, - { - name: "Should validate with 2 argument", - args: []string{"foo", "bar"}, - output: "ok", - fail: false, - }, - { - name: "Should show validation error and display usage when positional arguments are incorrect", - args: []string{"foo", "bar", "baz"}, - output: "Error: accepts at most 2 arg(s), received 3\n\nUsage:", - fail: true, - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - out, err := executeCommand(cmd, test.args) - - if err != nil && !test.fail { - t.Errorf("Unexpected error: %v\n", err) - } - - require.Contains(t, out, test.output) - }) - } -} diff --git a/src/go/rpk/pkg/cli/cmd/acl.go b/src/go/rpk/pkg/cli/cmd/acl.go index d2e4bfd1ae265..31ddf5a7efae5 100644 --- a/src/go/rpk/pkg/cli/cmd/acl.go +++ b/src/go/rpk/pkg/cli/cmd/acl.go @@ -14,7 +14,6 @@ import ( "github.com/spf13/afero" "github.com/spf13/cobra" - "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli/cmd/acl" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli/cmd/common" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/config" @@ -43,7 +42,7 @@ func NewACLCommand(fs afero.Fs, mgr config.Manager) *cobra.Command { Short: "Manage ACLs and SASL users.", Long: helpACLs, SilenceUsage: true, - Args: cli.MatchAll(cobra.ExactArgs(0)), + Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, _ []string) { if helpOperations { fmt.Println(helpACLOperations) diff --git a/src/go/rpk/pkg/cli/cmd/acl/create.go b/src/go/rpk/pkg/cli/cmd/acl/create.go index c6ef5d8f06cb0..37c71a54299ab 100644 --- a/src/go/rpk/pkg/cli/cmd/acl/create.go +++ b/src/go/rpk/pkg/cli/cmd/acl/create.go @@ -16,7 +16,6 @@ import ( "github.com/spf13/afero" "github.com/spf13/cobra" "github.com/twmb/types" - "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/config" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/kafka" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/out" @@ -46,7 +45,7 @@ Allow write permissions to user buzz to transactional id "txn": --allow-principal User:buzz --operation write --transactional-id txn `, - Args: cli.MatchAll(cobra.ExactArgs(0)), + Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, _ []string) { p := config.ParamsFromCommand(cmd) cfg, err := p.Load(fs) diff --git a/src/go/rpk/pkg/cli/cmd/acl/delete.go b/src/go/rpk/pkg/cli/cmd/acl/delete.go index 35265e05f7c86..aebb40545220b 100644 --- a/src/go/rpk/pkg/cli/cmd/acl/delete.go +++ b/src/go/rpk/pkg/cli/cmd/acl/delete.go @@ -17,7 +17,6 @@ import ( "github.com/spf13/cobra" "github.com/twmb/franz-go/pkg/kadm" "github.com/twmb/types" - "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/config" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/kafka" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/out" @@ -55,7 +54,7 @@ resource names: * "prefix" returns prefix patterns that match your input (prefix "fo" matches "foo") * "literal" returns exact name matches `, - Args: cli.MatchAll(cobra.ExactArgs(0)), + Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, _ []string) { p := config.ParamsFromCommand(cmd) cfg, err := p.Load(fs) diff --git a/src/go/rpk/pkg/cli/cmd/acl/list.go b/src/go/rpk/pkg/cli/cmd/acl/list.go index 65d7ed7bf4aca..d07aef9e76126 100644 --- a/src/go/rpk/pkg/cli/cmd/acl/list.go +++ b/src/go/rpk/pkg/cli/cmd/acl/list.go @@ -17,7 +17,6 @@ import ( "github.com/spf13/cobra" "github.com/twmb/franz-go/pkg/kadm" "github.com/twmb/types" - "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/config" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/kafka" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/out" @@ -49,7 +48,7 @@ resource names: * "prefix" returns prefix patterns that match your input (prefix "fo" matches "foo") * "literal" returns exact name matches `, - Args: cli.MatchAll(cobra.ExactArgs(0)), + Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, _ []string) { p := config.ParamsFromCommand(cmd) cfg, err := p.Load(fs) diff --git a/src/go/rpk/pkg/cli/cmd/acl/user.go b/src/go/rpk/pkg/cli/cmd/acl/user.go index 463603bf1cf11..b0552516509b9 100644 --- a/src/go/rpk/pkg/cli/cmd/acl/user.go +++ b/src/go/rpk/pkg/cli/cmd/acl/user.go @@ -16,7 +16,6 @@ import ( "github.com/spf13/afero" "github.com/spf13/cobra" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/api/admin" - "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/config" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/out" ) @@ -77,7 +76,7 @@ ACLs to grant the account access to certain resources in your cluster. See the acl help text for more info. `, - Args: cli.MatchAll(cobra.MaximumNArgs(1)), // when the deprecated user flag is removed, change this to cobra.ExactArgs(1) + Args: cobra.MaximumNArgs(1), // when the deprecated user flag is removed, change this to cobra.ExactArgs(1) Run: func(cmd *cobra.Command, args []string) { p := config.ParamsFromCommand(cmd) cfg, err := p.Load(fs) @@ -147,7 +146,7 @@ func NewDeleteUserCommand(fs afero.Fs) *cobra.Command { This command deletes the specified SASL account from Redpanda. This does not delete any ACLs that may exist for this user. `, - Args: cli.MatchAll(cobra.MaximumNArgs(1)), + Args: cobra.MaximumNArgs(1), Run: func(cmd *cobra.Command, args []string) { p := config.ParamsFromCommand(cmd) cfg, err := p.Load(fs) diff --git a/src/go/rpk/pkg/cli/cmd/cluster/config/config.go b/src/go/rpk/pkg/cli/cmd/cluster/config/config.go index cb002ce25b8e9..8e974c028ebba 100644 --- a/src/go/rpk/pkg/cli/cmd/cluster/config/config.go +++ b/src/go/rpk/pkg/cli/cmd/cluster/config/config.go @@ -12,7 +12,6 @@ package config import ( "github.com/spf13/afero" "github.com/spf13/cobra" - "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli/cmd/common" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/config" ) @@ -29,7 +28,7 @@ func NewConfigCommand(fs afero.Fs) *cobra.Command { command := &cobra.Command{ Use: "config", - Args: cli.MatchAll(cobra.ExactArgs(0)), + Args: cobra.ExactArgs(0), Short: "Interact with cluster configuration properties.", Long: `Interact with cluster configuration properties. diff --git a/src/go/rpk/pkg/cli/cmd/cluster/config/edit.go b/src/go/rpk/pkg/cli/cmd/cluster/config/edit.go index 73dcf68d3c0e7..366d17a5f5deb 100644 --- a/src/go/rpk/pkg/cli/cmd/cluster/config/edit.go +++ b/src/go/rpk/pkg/cli/cmd/cluster/config/edit.go @@ -17,7 +17,6 @@ import ( "github.com/spf13/afero" "github.com/spf13/cobra" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/api/admin" - "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/config" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/out" ) @@ -41,7 +40,7 @@ values. By default, low level tunables are excluded: use the '--all' flag to edit all properties including these tunables. `, - Args: cli.MatchAll(cobra.ExactArgs(0)), + Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, _ []string) { p := config.ParamsFromCommand(cmd) cfg, err := p.Load(fs) diff --git a/src/go/rpk/pkg/cli/cmd/debug/info.go b/src/go/rpk/pkg/cli/cmd/debug/info.go index c90e0af3cd048..0408730281284 100644 --- a/src/go/rpk/pkg/cli/cmd/debug/info.go +++ b/src/go/rpk/pkg/cli/cmd/debug/info.go @@ -20,7 +20,6 @@ import ( "github.com/spf13/cobra" "github.com/twmb/franz-go/pkg/kadm" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/api" - "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/config" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/kafka" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/out" @@ -38,7 +37,7 @@ func NewInfoCommand(fs afero.Fs) *cobra.Command { Short: "Send usage stats to Vectorized.", Hidden: true, Aliases: []string{"status"}, - Args: cli.MatchAll(cobra.ExactArgs(0)), + Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, _ []string) { if !send { return diff --git a/src/go/rpk/pkg/cli/cmd/group/describe.go b/src/go/rpk/pkg/cli/cmd/group/describe.go index 0ad1f757df263..e4ad4041585de 100644 --- a/src/go/rpk/pkg/cli/cmd/group/describe.go +++ b/src/go/rpk/pkg/cli/cmd/group/describe.go @@ -18,7 +18,6 @@ import ( "github.com/spf13/afero" "github.com/spf13/cobra" "github.com/twmb/franz-go/pkg/kadm" - "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/config" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/kafka" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/out" @@ -33,7 +32,7 @@ func NewDescribeCommand(fs afero.Fs) *cobra.Command { This command describes group members, calculates their lag, and prints detailed information about the members. `, - Args: cli.MatchAll(cobra.MinimumNArgs(1)), + Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, groups []string) { p := config.ParamsFromCommand(cmd) cfg, err := p.Load(fs) diff --git a/src/go/rpk/pkg/cli/cmd/group/group.go b/src/go/rpk/pkg/cli/cmd/group/group.go index 33432710ff7c7..a2543dc56ea17 100644 --- a/src/go/rpk/pkg/cli/cmd/group/group.go +++ b/src/go/rpk/pkg/cli/cmd/group/group.go @@ -15,7 +15,6 @@ import ( "github.com/spf13/afero" "github.com/spf13/cobra" - "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli/cmd/common" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/config" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/kafka" @@ -67,7 +66,7 @@ deploy, and restart the members with a patch. This command allows you to list all groups, describe a group (to view the members and their lag), and manage offsets. `, - Args: cli.MatchAll(cobra.ExactArgs(0)), + Args: cobra.ExactArgs(0), } var ( @@ -117,7 +116,7 @@ groups that have not yet expired. The BROKER column is which broker node is the coordinator for the group. This command can be used to track down unknown groups, or to list groups that need to be cleaned up. `, - Args: cli.MatchAll(cobra.ExactArgs(0)), + Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, _ []string) { p := config.ParamsFromCommand(cmd) cfg, err := p.Load(fs) @@ -165,7 +164,7 @@ You may want to delete groups to clean up offsets sooner than when they automatically are cleaned up, such as when you create temporary groups for quick investigation or testing. This command helps you do that. `, - Args: cli.MatchAll(cobra.MinimumNArgs(1)), + Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { p := config.ParamsFromCommand(cmd) cfg, err := p.Load(fs) diff --git a/src/go/rpk/pkg/cli/cmd/group/seek.go b/src/go/rpk/pkg/cli/cmd/group/seek.go index 18a3e67beb0a5..8c468aa6c2ba7 100644 --- a/src/go/rpk/pkg/cli/cmd/group/seek.go +++ b/src/go/rpk/pkg/cli/cmd/group/seek.go @@ -19,7 +19,6 @@ import ( "github.com/spf13/afero" "github.com/spf13/cobra" "github.com/twmb/franz-go/pkg/kadm" - "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/config" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/kafka" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/out" @@ -83,7 +82,7 @@ Seek group G's topics foo, bar, and biz to the end: Seek group G to the beginning of a topic it was not previously consuming: rpk group seek G --to start --topics foo --allow-new-topics `, - Args: cli.MatchAll(cobra.ExactArgs(1)), + Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { p := config.ParamsFromCommand(cmd) cfg, err := p.Load(fs) diff --git a/src/go/rpk/pkg/cli/cmd/plugin/plugin.go b/src/go/rpk/pkg/cli/cmd/plugin/plugin.go index ed9631952001c..e8cca1fc7f234 100644 --- a/src/go/rpk/pkg/cli/cmd/plugin/plugin.go +++ b/src/go/rpk/pkg/cli/cmd/plugin/plugin.go @@ -8,7 +8,6 @@ import ( "github.com/spf13/afero" "github.com/spf13/cobra" - "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/out" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/plugin" ) @@ -62,7 +61,7 @@ following: where "path" is an underscore delimited argument path to a command. For example, "foo_bar_baz" corresponds to the command "rpk foo bar baz". `, - Args: cli.MatchAll(cobra.ExactArgs(0)), + Args: cobra.ExactArgs(0), } cmd.AddCommand( newListCommand(fs), @@ -90,7 +89,7 @@ You can specify --local to print all locally installed plugins, as well as whether you have "shadowed" plugins (the same plugin specified multiple times). `, - Args: cli.MatchAll(cobra.ExactArgs(0)), + Args: cobra.ExactArgs(0), Run: func(*cobra.Command, []string) { installed := plugin.ListPlugins(fs, plugin.UserPaths()) @@ -164,7 +163,7 @@ An rpk plugin must be saved in a directory that is in your $PATH. By default, this command installs plugins to the first directory in your $PATH. This can be overridden by specifying the --bin-dir flag. `, - Args: cli.MatchAll(cobra.ExactArgs(1)), + Args: cobra.ExactArgs(1), Run: func(_ *cobra.Command, args []string) { name := args[0] @@ -256,7 +255,7 @@ matches the requested removal. If --include-shadowed is specified, this command also removes all shadowed plugins of the same name. `, - Args: cli.MatchAll(cobra.ExactArgs(1)), + Args: cobra.ExactArgs(1), Run: func(_ *cobra.Command, args []string) { name := args[0] diff --git a/src/go/rpk/pkg/cli/cmd/redpanda/admin/admin.go b/src/go/rpk/pkg/cli/cmd/redpanda/admin/admin.go index db920581f4faa..bc774786c071e 100644 --- a/src/go/rpk/pkg/cli/cmd/redpanda/admin/admin.go +++ b/src/go/rpk/pkg/cli/cmd/redpanda/admin/admin.go @@ -13,7 +13,6 @@ package admin import ( "github.com/spf13/afero" "github.com/spf13/cobra" - "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli/cmd/common" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli/cmd/redpanda/admin/brokers" configcmd "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli/cmd/redpanda/admin/config" @@ -25,7 +24,7 @@ func NewCommand(fs afero.Fs) *cobra.Command { cmd := &cobra.Command{ Use: "admin", Short: "Talk to the Redpanda admin listener.", - Args: cli.MatchAll(cobra.ExactArgs(0)), + Args: cobra.ExactArgs(0), } var ( diff --git a/src/go/rpk/pkg/cli/cmd/redpanda/admin/brokers/brokers.go b/src/go/rpk/pkg/cli/cmd/redpanda/admin/brokers/brokers.go index 9633d8b9d270e..eb7d2401575f8 100644 --- a/src/go/rpk/pkg/cli/cmd/redpanda/admin/brokers/brokers.go +++ b/src/go/rpk/pkg/cli/cmd/redpanda/admin/brokers/brokers.go @@ -18,7 +18,6 @@ import ( "github.com/spf13/afero" "github.com/spf13/cobra" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/api/admin" - "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/config" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/out" ) @@ -28,7 +27,7 @@ func NewCommand(fs afero.Fs) *cobra.Command { cmd := &cobra.Command{ Use: "brokers", Short: "View and configure Redpanda brokers through the admin listener.", - Args: cli.MatchAll(cobra.ExactArgs(0)), + Args: cobra.ExactArgs(0), } cmd.AddCommand( newListCommand(fs), @@ -43,7 +42,7 @@ func newListCommand(fs afero.Fs) *cobra.Command { Use: "list", Aliases: []string{"ls"}, Short: "List the brokers in your cluster.", - Args: cli.MatchAll(cobra.ExactArgs(0)), + Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, _ []string) { p := config.ParamsFromCommand(cmd) cfg, err := p.Load(fs) @@ -75,7 +74,7 @@ Decommissioning a broker removes it from the cluster. A decommission request is sent to every broker in the cluster, only the cluster leader handles the request. `, - Args: cli.MatchAll(cobra.ExactArgs(1)), + Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { broker, err := strconv.Atoi(args[0]) out.MaybeDie(err, "invalid broker %s: %v", args[0], err) @@ -113,7 +112,7 @@ A recommission request is sent to every broker in the cluster, only the cluster leader handles the request. `, - Args: cli.MatchAll(cobra.ExactArgs(1)), + Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { broker, err := strconv.Atoi(args[0]) out.MaybeDie(err, "invalid broker %s: %v", args[0], err) diff --git a/src/go/rpk/pkg/cli/cmd/redpanda/admin/config/config.go b/src/go/rpk/pkg/cli/cmd/redpanda/admin/config/config.go index 48e7f7a58f4a4..9319b9eadd251 100644 --- a/src/go/rpk/pkg/cli/cmd/redpanda/admin/config/config.go +++ b/src/go/rpk/pkg/cli/cmd/redpanda/admin/config/config.go @@ -12,7 +12,6 @@ import ( "github.com/spf13/afero" "github.com/spf13/cobra" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/api/admin" - "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/config" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/out" ) @@ -22,7 +21,7 @@ func NewCommand(fs afero.Fs) *cobra.Command { cmd := &cobra.Command{ Use: "config", Short: "View or modify Redpanda configuration through the admin listener.", - Args: cli.MatchAll(cobra.ExactArgs(0)), + Args: cobra.ExactArgs(0), } cmd.AddCommand( newPrintCommand(fs), @@ -37,7 +36,7 @@ func newPrintCommand(fs afero.Fs) *cobra.Command { Use: "print", Aliases: []string{"dump", "list", "ls", "display"}, Short: "Display the current Redpanda configuration.", - Args: cli.MatchAll(cobra.ExactArgs(0)), + Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, _ []string) { p := config.ParamsFromCommand(cmd) cfg, err := p.Load(fs) @@ -67,7 +66,7 @@ func newLogLevelCommand(fs afero.Fs) *cobra.Command { cmd := &cobra.Command{ Use: "log-level", Short: "Manage a broker's log level.", - Args: cli.MatchAll(cobra.ExactArgs(0)), + Args: cobra.ExactArgs(0), } cmd.AddCommand( newLogLevelSetCommand(fs), diff --git a/src/go/rpk/pkg/cli/cmd/root.go b/src/go/rpk/pkg/cli/cmd/root.go index 593944b7c3750..0bbf0ef3981d5 100644 --- a/src/go/rpk/pkg/cli/cmd/root.go +++ b/src/go/rpk/pkg/cli/cmd/root.go @@ -60,9 +60,9 @@ func Execute() { Long: "", Args: cobra.OnlyValidArgs, } - rootCmd.SilenceUsage = true rootCmd.PersistentFlags().BoolVarP(&verbose, config.FlagVerbose, "v", false, "Enable verbose logging (default: false).") + rootCmd.AddCommand(NewGenerateCommand(mgr)) rootCmd.AddCommand(NewVersionCommand()) rootCmd.AddCommand(NewWasmCommand(fs, mgr)) diff --git a/src/go/rpk/pkg/cli/cmd/topic/add_partitions.go b/src/go/rpk/pkg/cli/cmd/topic/add_partitions.go index a6daf5a02f2c9..7fa35c31f4520 100644 --- a/src/go/rpk/pkg/cli/cmd/topic/add_partitions.go +++ b/src/go/rpk/pkg/cli/cmd/topic/add_partitions.go @@ -14,7 +14,6 @@ import ( "github.com/spf13/afero" "github.com/spf13/cobra" - "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/config" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/kafka" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/out" @@ -25,7 +24,7 @@ func NewAddPartitionsCommand(fs afero.Fs) *cobra.Command { cmd := &cobra.Command{ Use: "add-partitions [TOPICS...] --num [#]", Short: "Add partitions to existing topics.", - Args: cli.MatchAll(cobra.MinimumNArgs(1)), + Args: cobra.MinimumNArgs(1), Long: `Add partitions to existing topics.`, Run: func(cmd *cobra.Command, topics []string) { p := config.ParamsFromCommand(cmd) diff --git a/src/go/rpk/pkg/cli/cmd/topic/config.go b/src/go/rpk/pkg/cli/cmd/topic/config.go index 27c055eb37dbd..1f035b2c6a39c 100644 --- a/src/go/rpk/pkg/cli/cmd/topic/config.go +++ b/src/go/rpk/pkg/cli/cmd/topic/config.go @@ -16,7 +16,6 @@ import ( "github.com/spf13/cobra" "github.com/twmb/franz-go/pkg/kerr" "github.com/twmb/franz-go/pkg/kmsg" - "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/config" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/kafka" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/out" @@ -50,7 +49,7 @@ Incremental altering supports four operations: The --dry option will validate whether the requested configuration change is valid, but does not apply it. `, - Args: cli.MatchAll(cobra.MinimumNArgs(1)), + Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, topics []string) { p := config.ParamsFromCommand(cmd) cfg, err := p.Load(fs) diff --git a/src/go/rpk/pkg/cli/cmd/topic/consume.go b/src/go/rpk/pkg/cli/cmd/topic/consume.go index 13f788f756e19..a6cd22cb67054 100644 --- a/src/go/rpk/pkg/cli/cmd/topic/consume.go +++ b/src/go/rpk/pkg/cli/cmd/topic/consume.go @@ -25,7 +25,6 @@ import ( "github.com/spf13/afero" "github.com/spf13/cobra" "github.com/twmb/franz-go/pkg/kgo" - "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/config" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/kafka" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/out" @@ -66,7 +65,7 @@ func NewConsumeCommand(fs afero.Fs) *cobra.Command { Use: "consume TOPICS...", Short: "Consume records from topics.", Long: helpConsume, - Args: cli.MatchAll(cobra.MinimumNArgs(1)), + Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { err := c.parseOffset(offset) out.MaybeDie(err, "invalid --offset: %v", err) diff --git a/src/go/rpk/pkg/cli/cmd/topic/create.go b/src/go/rpk/pkg/cli/cmd/topic/create.go index 7c575aff3ef84..6dc94a38a9979 100644 --- a/src/go/rpk/pkg/cli/cmd/topic/create.go +++ b/src/go/rpk/pkg/cli/cmd/topic/create.go @@ -16,7 +16,6 @@ import ( "github.com/spf13/cobra" "github.com/twmb/franz-go/pkg/kerr" "github.com/twmb/franz-go/pkg/kmsg" - "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/config" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/kafka" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/out" @@ -33,7 +32,7 @@ func NewCreateCommand(fs afero.Fs) *cobra.Command { cmd := &cobra.Command{ Use: "create [TOPICS...]", Short: "Create topics.", - Args: cli.MatchAll(cobra.MinimumNArgs(1)), + Args: cobra.MinimumNArgs(1), Long: `Create topics. All topics created with this command will have the same number of partitions, diff --git a/src/go/rpk/pkg/cli/cmd/topic/delete.go b/src/go/rpk/pkg/cli/cmd/topic/delete.go index 1c50297266a08..41dfceeffc8dc 100644 --- a/src/go/rpk/pkg/cli/cmd/topic/delete.go +++ b/src/go/rpk/pkg/cli/cmd/topic/delete.go @@ -14,7 +14,6 @@ import ( "github.com/spf13/afero" "github.com/spf13/cobra" - "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/config" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/kafka" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/out" @@ -48,7 +47,7 @@ For example, `, - Args: cli.MatchAll(cobra.MinimumNArgs(1)), + Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, topics []string) { p := config.ParamsFromCommand(cmd) cfg, err := p.Load(fs) diff --git a/src/go/rpk/pkg/cli/cmd/topic/describe.go b/src/go/rpk/pkg/cli/cmd/topic/describe.go index 7aa4307c1af39..05cc7f8839194 100644 --- a/src/go/rpk/pkg/cli/cmd/topic/describe.go +++ b/src/go/rpk/pkg/cli/cmd/topic/describe.go @@ -22,7 +22,6 @@ import ( "github.com/twmb/franz-go/pkg/kgo" "github.com/twmb/franz-go/pkg/kmsg" "github.com/twmb/types" - "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/config" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/kafka" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/out" @@ -46,7 +45,7 @@ potential sections: a summary of the topic, the topic configs, and a detailed partitions section. By default, the summary and configs sections are printed. `, - Args: cli.MatchAll(cobra.ExactArgs(1)), + Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, topicArg []string) { p := config.ParamsFromCommand(cmd) cfg, err := p.Load(fs) diff --git a/src/go/rpk/pkg/cli/cmd/topic/produce.go b/src/go/rpk/pkg/cli/cmd/topic/produce.go index af89d68fdf69d..ea3dcdf54d435 100644 --- a/src/go/rpk/pkg/cli/cmd/topic/produce.go +++ b/src/go/rpk/pkg/cli/cmd/topic/produce.go @@ -19,7 +19,6 @@ import ( "github.com/spf13/afero" "github.com/spf13/cobra" "github.com/twmb/franz-go/pkg/kgo" - "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/config" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/kafka" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/out" @@ -43,7 +42,7 @@ func NewProduceCommand(fs afero.Fs) *cobra.Command { Use: "produce [TOPIC]", Short: "Produce records to a topic.", Long: helpProduce, - Args: cli.MatchAll(cobra.MaximumNArgs(1)), + Args: cobra.MaximumNArgs(1), Run: func(cmd *cobra.Command, args []string) { // A few of our flags require up front handling before // the kgo client is initialized: compression, acks, diff --git a/src/go/rpk/pkg/cli/cmd/wasm/deploy.go b/src/go/rpk/pkg/cli/cmd/wasm/deploy.go index dca3a9fc0e98f..582e9d423516d 100644 --- a/src/go/rpk/pkg/cli/cmd/wasm/deploy.go +++ b/src/go/rpk/pkg/cli/cmd/wasm/deploy.go @@ -6,7 +6,6 @@ import ( "github.com/spf13/afero" "github.com/spf13/cobra" - "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/config" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/kafka" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/out" @@ -21,7 +20,7 @@ func NewDeployCommand(fs afero.Fs) *cobra.Command { cmd := &cobra.Command{ Use: "deploy [PATH]", Short: "Deploy inline WASM function.", - Args: cli.MatchAll(cobra.ExactArgs(1)), + Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { p := config.ParamsFromCommand(cmd) cfg, err := p.Load(fs) diff --git a/src/go/rpk/pkg/cli/cmd/wasm/generate.go b/src/go/rpk/pkg/cli/cmd/wasm/generate.go index 8437f1a8cff38..30c3b4e780edf 100644 --- a/src/go/rpk/pkg/cli/cmd/wasm/generate.go +++ b/src/go/rpk/pkg/cli/cmd/wasm/generate.go @@ -21,7 +21,6 @@ import ( log "github.com/sirupsen/logrus" "github.com/spf13/afero" "github.com/spf13/cobra" - "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli/cmd/wasm/template" vos "github.com/vectorizedio/redpanda/src/go/rpk/pkg/os" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/out" @@ -35,7 +34,7 @@ func NewGenerateCommand(fs afero.Fs) *cobra.Command { Use: "generate [PROJECT DIRECTORY]", Short: "Create an npm template project for inline WASM engine.", SilenceUsage: true, - Args: cli.MatchAll(cobra.ExactArgs(1)), + Args: cobra.ExactArgs(1), Run: func(_ *cobra.Command, args []string) { path, err := filepath.Abs(args[0]) out.MaybeDie(err, "unable to get absolute path for %q: %v", args[0], err) diff --git a/src/go/rpk/pkg/cli/cmd/wasm/remove.go b/src/go/rpk/pkg/cli/cmd/wasm/remove.go index a399d7fdc1635..d9f381d98176f 100644 --- a/src/go/rpk/pkg/cli/cmd/wasm/remove.go +++ b/src/go/rpk/pkg/cli/cmd/wasm/remove.go @@ -5,7 +5,6 @@ import ( "github.com/spf13/afero" "github.com/spf13/cobra" - "github.com/vectorizedio/redpanda/src/go/rpk/pkg/cli" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/config" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/kafka" "github.com/vectorizedio/redpanda/src/go/rpk/pkg/out" @@ -17,7 +16,7 @@ func NewRemoveCommand(fs afero.Fs) *cobra.Command { cmd := &cobra.Command{ Use: "remove [NAME]", Short: "Remove inline WASM function.", - Args: cli.MatchAll(cobra.ExactArgs(1)), + Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { p := config.ParamsFromCommand(cmd) cfg, err := p.Load(fs)