Browse Source

cmd: use hyphen instead of underscore (#3898)

fatedier 1 year ago
parent
commit
d01f4a3ec1
7 changed files with 23 additions and 9 deletions
  1. 2 2
      Release.md
  2. 1 0
      cmd/frpc/sub/root.go
  3. 1 0
      cmd/frps/root.go
  4. 10 0
      pkg/config/flags.go
  5. 2 0
      pkg/ssh/server.go
  6. 2 2
      test/e2e/v1/basic/cmd.go
  7. 5 5
      test/e2e/v1/features/ssh_tunnel.go

+ 2 - 2
Release.md

@@ -1,3 +1,3 @@
-### Fixes
+### Deprecation Notices
 
-* frpc has a certain chance to panic when login: close of closed channel.
+* Using an underscore in a flag name is deprecated and has been replaced by a hyphen. The underscore format will remain compatible for some time, until it is completely removed in a future version. For example, `--remote_port` is replaced with `--remote-port`.

+ 1 - 0
cmd/frpc/sub/root.go

@@ -97,6 +97,7 @@ func runMultipleClients(cfgDir string) error {
 }
 
 func Execute() {
+	rootCmd.SetGlobalNormalizationFunc(config.WordSepNormalizeFunc)
 	if err := rootCmd.Execute(); err != nil {
 		os.Exit(1)
 	}

+ 1 - 0
cmd/frps/root.go

@@ -92,6 +92,7 @@ var rootCmd = &cobra.Command{
 }
 
 func Execute() {
+	rootCmd.SetGlobalNormalizationFunc(config.WordSepNormalizeFunc)
 	if err := rootCmd.Execute(); err != nil {
 		os.Exit(1)
 	}

+ 10 - 0
pkg/config/flags.go

@@ -17,14 +17,24 @@ package config
 import (
 	"fmt"
 	"strconv"
+	"strings"
 
 	"github.com/spf13/cobra"
+	"github.com/spf13/pflag"
 
 	"github.com/fatedier/frp/pkg/config/types"
 	v1 "github.com/fatedier/frp/pkg/config/v1"
 	"github.com/fatedier/frp/pkg/config/v1/validation"
 )
 
+// WordSepNormalizeFunc changes all flags that contain "_" separators
+func WordSepNormalizeFunc(f *pflag.FlagSet, name string) pflag.NormalizedName {
+	if strings.Contains(name, "_") {
+		return pflag.NormalizedName(strings.ReplaceAll(name, "_", "-"))
+	}
+	return pflag.NormalizedName(name)
+}
+
 type RegisterFlagOption func(*registerFlagOptions)
 
 type registerFlagOptions struct {

+ 2 - 0
pkg/ssh/server.go

@@ -254,6 +254,8 @@ func (s *TunnelServer) parseClientAndProxyConfigurer(_ *tcpipForward, extraPaylo
 		Short: "ssh v0@{address} [command]",
 		Run:   func(*cobra.Command, []string) {},
 	}
+	cmd.SetGlobalNormalizationFunc(config.WordSepNormalizeFunc)
+
 	args := strings.Split(extraPayload, " ")
 	if len(args) < 1 {
 		return nil, nil, helpMessage, fmt.Errorf("invalid extra payload")

+ 2 - 2
test/e2e/v1/basic/cmd.go

@@ -90,12 +90,12 @@ var _ = ginkgo.Describe("[Feature: Cmd]", func() {
 		ginkgo.It("HTTP", func() {
 			serverPort := f.AllocPort()
 			vhostHTTPPort := f.AllocPort()
-			_, _, err := f.RunFrps("-t", "123", "-p", strconv.Itoa(serverPort), "--vhost_http_port", strconv.Itoa(vhostHTTPPort))
+			_, _, err := f.RunFrps("-t", "123", "-p", strconv.Itoa(serverPort), "--vhost-http-port", strconv.Itoa(vhostHTTPPort))
 			framework.ExpectNoError(err)
 
 			_, _, err = f.RunFrpc("http", "-s", "127.0.0.1", "-P", strconv.Itoa(serverPort), "-t", "123", "-u", "test",
 				"-n", "udp_test", "-l", strconv.Itoa(f.PortByName(framework.HTTPSimpleServerPort)),
-				"--custom_domain", "test.example.com")
+				"--custom-domain", "test.example.com")
 			framework.ExpectNoError(err)
 
 			framework.NewRequestExpect(f).Port(vhostHTTPPort).

+ 5 - 5
test/e2e/v1/features/ssh_tunnel.go

@@ -32,7 +32,7 @@ var _ = ginkgo.Describe("[Feature: SSH Tunnel]", func() {
 		tc := ssh.NewTunnelClient(
 			fmt.Sprintf("127.0.0.1:%d", localPort),
 			fmt.Sprintf("127.0.0.1:%d", sshPort),
-			fmt.Sprintf("tcp --remote_port %d", remotePort),
+			fmt.Sprintf("tcp --remote-port %d", remotePort),
 		)
 		framework.ExpectNoError(tc.Start())
 		defer tc.Close()
@@ -55,7 +55,7 @@ var _ = ginkgo.Describe("[Feature: SSH Tunnel]", func() {
 		tc := ssh.NewTunnelClient(
 			fmt.Sprintf("127.0.0.1:%d", localPort),
 			fmt.Sprintf("127.0.0.1:%d", sshPort),
-			"http --custom_domain test.example.com",
+			"http --custom-domain test.example.com",
 		)
 		framework.ExpectNoError(tc.Start())
 		defer tc.Close()
@@ -83,7 +83,7 @@ var _ = ginkgo.Describe("[Feature: SSH Tunnel]", func() {
 		tc := ssh.NewTunnelClient(
 			fmt.Sprintf("127.0.0.1:%d", localPort),
 			fmt.Sprintf("127.0.0.1:%d", sshPort),
-			fmt.Sprintf("https --custom_domain %s", testDomain),
+			fmt.Sprintf("https --custom-domain %s", testDomain),
 		)
 		framework.ExpectNoError(tc.Start())
 		defer tc.Close()
@@ -125,7 +125,7 @@ var _ = ginkgo.Describe("[Feature: SSH Tunnel]", func() {
 		tc := ssh.NewTunnelClient(
 			fmt.Sprintf("127.0.0.1:%d", localPort),
 			fmt.Sprintf("127.0.0.1:%d", sshPort),
-			fmt.Sprintf("tcpmux --mux=httpconnect --custom_domain %s", testDomain),
+			fmt.Sprintf("tcpmux --mux=httpconnect --custom-domain %s", testDomain),
 		)
 		framework.ExpectNoError(tc.Start())
 		defer tc.Close()
@@ -179,7 +179,7 @@ var _ = ginkgo.Describe("[Feature: SSH Tunnel]", func() {
 		tc := ssh.NewTunnelClient(
 			fmt.Sprintf("127.0.0.1:%d", localPort),
 			fmt.Sprintf("127.0.0.1:%d", sshPort),
-			"stcp -n stcp-test --sk=abcdefg --allow_users=\"*\"",
+			"stcp -n stcp-test --sk=abcdefg --allow-users=\"*\"",
 		)
 		framework.ExpectNoError(tc.Start())
 		defer tc.Close()