Skip to content

Commit 1870ee0

Browse files
authored
Merge pull request #150 from ferryproxy/clean/verfiy
Verify args
2 parents 50c748d + 7d0bfbf commit 1870ee0

File tree

3 files changed

+4
-23
lines changed

3 files changed

+4
-23
lines changed

pkg/ferryctl/cmd/ferryctl/control_plane/init/init.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package init
1818

1919
import (
20-
"fmt"
2120
"strings"
2221

2322
"github.com/ferryproxy/ferry/pkg/ferryctl/control_plane"
@@ -46,9 +45,6 @@ func NewCommand(logger log.Logger) *cobra.Command {
4645
Short: "Control plane init commands",
4746
Long: `Control plane init commands is used to initialize the control plane`,
4847
RunE: func(cmd *cobra.Command, args []string) error {
49-
if len(args) > 0 {
50-
return fmt.Errorf("too many arguments")
51-
}
5248

5349
kctl := kubectl.NewKubectl()
5450

pkg/ferryctl/cmd/ferryctl/local/forward/dial/forward_dial.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,20 @@ limitations under the License.
1717
package dial
1818

1919
import (
20-
"fmt"
21-
2220
"github.com/ferryproxy/ferry/pkg/ferryctl/local"
2321
"github.com/ferryproxy/ferry/pkg/ferryctl/log"
2422
"github.com/spf13/cobra"
2523
)
2624

2725
func NewCommand(logger log.Logger) *cobra.Command {
2826
cmd := &cobra.Command{
29-
Use: "dial <local address port> <remote service port>",
27+
Use: "dial <local address port> <remote service port>",
28+
Args: cobra.ExactArgs(2),
3029
Aliases: []string{
3130
"d",
3231
},
3332
Short: "local forward dial commands",
3433
RunE: func(cmd *cobra.Command, args []string) error {
35-
if len(args) < 2 {
36-
return fmt.Errorf("too few arguments")
37-
}
38-
if len(args) > 2 {
39-
return fmt.Errorf("too many arguments")
40-
}
4134

4235
return local.ForwardDial(cmd.Context(), args[0], args[1])
4336
},

pkg/ferryctl/cmd/ferryctl/local/forward/listen/forward_listen.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,20 @@ limitations under the License.
1717
package listen
1818

1919
import (
20-
"fmt"
21-
2220
"github.com/ferryproxy/ferry/pkg/ferryctl/local"
2321
"github.com/ferryproxy/ferry/pkg/ferryctl/log"
2422
"github.com/spf13/cobra"
2523
)
2624

2725
func NewCommand(logger log.Logger) *cobra.Command {
2826
cmd := &cobra.Command{
29-
Use: "listen <remote service port> <local address port>",
27+
Use: "listen <remote service port> <local address port>",
28+
Args: cobra.ExactArgs(2),
3029
Aliases: []string{
3130
"l",
3231
},
3332
Short: "local forward listen commands",
3433
RunE: func(cmd *cobra.Command, args []string) error {
35-
if len(args) < 2 {
36-
return fmt.Errorf("too few arguments")
37-
}
38-
if len(args) > 2 {
39-
return fmt.Errorf("too many arguments")
40-
}
41-
4234
return local.ForwardListen(cmd.Context(), args[0], args[1])
4335
},
4436
}

0 commit comments

Comments
 (0)