From 964a1bbf39961ceee98d0b61c208a5f3e3f0e921 Mon Sep 17 00:00:00 2001 From: Tank Date: Tue, 19 May 2020 10:49:29 +0800 Subject: [PATCH] refine: frpc flags (#1811) --- cmd/frpc/sub/http.go | 10 +--------- cmd/frpc/sub/https.go | 10 +--------- cmd/frpc/sub/root.go | 12 ++++++++++++ cmd/frpc/sub/stcp.go | 10 +--------- cmd/frpc/sub/sudp.go | 10 +--------- cmd/frpc/sub/tcp.go | 10 +--------- cmd/frpc/sub/tcpmux.go | 10 +--------- cmd/frpc/sub/udp.go | 10 +--------- cmd/frpc/sub/xtcp.go | 10 +--------- 9 files changed, 20 insertions(+), 72 deletions(-) diff --git a/cmd/frpc/sub/http.go b/cmd/frpc/sub/http.go index 55aa2e9a..085b03ea 100644 --- a/cmd/frpc/sub/http.go +++ b/cmd/frpc/sub/http.go @@ -26,14 +26,7 @@ import ( ) func init() { - httpCmd.PersistentFlags().StringVarP(&serverAddr, "server_addr", "s", "127.0.0.1:7000", "frp server's address") - httpCmd.PersistentFlags().StringVarP(&user, "user", "u", "", "user") - httpCmd.PersistentFlags().StringVarP(&protocol, "protocol", "p", "tcp", "tcp or kcp or websocket") - httpCmd.PersistentFlags().StringVarP(&token, "token", "t", "", "auth token") - httpCmd.PersistentFlags().StringVarP(&logLevel, "log_level", "", "info", "log level") - httpCmd.PersistentFlags().StringVarP(&logFile, "log_file", "", "console", "console or file path") - httpCmd.PersistentFlags().IntVarP(&logMaxDays, "log_max_days", "", 3, "log file reversed days") - httpCmd.PersistentFlags().BoolVarP(&disableLogColor, "disable_log_color", "", false, "disable log color in console") + RegisterCommonFlags(httpCmd) httpCmd.PersistentFlags().StringVarP(&proxyName, "proxy_name", "n", "", "proxy name") httpCmd.PersistentFlags().StringVarP(&localIp, "local_ip", "i", "127.0.0.1", "local ip") @@ -46,7 +39,6 @@ func init() { httpCmd.PersistentFlags().StringVarP(&hostHeaderRewrite, "host_header_rewrite", "", "", "host header rewrite") httpCmd.PersistentFlags().BoolVarP(&useEncryption, "ue", "", false, "use encryption") httpCmd.PersistentFlags().BoolVarP(&useCompression, "uc", "", false, "use compression") - httpCmd.PersistentFlags().BoolVarP(&tlsEnable, "tls_enable", "", false, "enable frpc tls") rootCmd.AddCommand(httpCmd) } diff --git a/cmd/frpc/sub/https.go b/cmd/frpc/sub/https.go index 039054b4..76d49a94 100644 --- a/cmd/frpc/sub/https.go +++ b/cmd/frpc/sub/https.go @@ -26,14 +26,7 @@ import ( ) func init() { - httpsCmd.PersistentFlags().StringVarP(&serverAddr, "server_addr", "s", "127.0.0.1:7000", "frp server's address") - httpsCmd.PersistentFlags().StringVarP(&user, "user", "u", "", "user") - httpsCmd.PersistentFlags().StringVarP(&protocol, "protocol", "p", "tcp", "tcp or kcp or websocket") - httpsCmd.PersistentFlags().StringVarP(&token, "token", "t", "", "auth token") - httpsCmd.PersistentFlags().StringVarP(&logLevel, "log_level", "", "info", "log level") - httpsCmd.PersistentFlags().StringVarP(&logFile, "log_file", "", "console", "console or file path") - httpsCmd.PersistentFlags().IntVarP(&logMaxDays, "log_max_days", "", 3, "log file reversed days") - httpsCmd.PersistentFlags().BoolVarP(&disableLogColor, "disable_log_color", "", false, "disable log color in console") + RegisterCommonFlags(httpsCmd) httpsCmd.PersistentFlags().StringVarP(&proxyName, "proxy_name", "n", "", "proxy name") httpsCmd.PersistentFlags().StringVarP(&localIp, "local_ip", "i", "127.0.0.1", "local ip") @@ -42,7 +35,6 @@ func init() { httpsCmd.PersistentFlags().StringVarP(&subDomain, "sd", "", "", "sub domain") httpsCmd.PersistentFlags().BoolVarP(&useEncryption, "ue", "", false, "use encryption") httpsCmd.PersistentFlags().BoolVarP(&useCompression, "uc", "", false, "use compression") - httpsCmd.PersistentFlags().BoolVarP(&tlsEnable, "tls_enable", "", false, "enable frpc tls") rootCmd.AddCommand(httpsCmd) } diff --git a/cmd/frpc/sub/root.go b/cmd/frpc/sub/root.go index 14c53b8d..0227ac33 100644 --- a/cmd/frpc/sub/root.go +++ b/cmd/frpc/sub/root.go @@ -83,6 +83,18 @@ func init() { kcpDoneCh = make(chan struct{}) } +func RegisterCommonFlags(cmd *cobra.Command) { + cmd.PersistentFlags().StringVarP(&serverAddr, "server_addr", "s", "127.0.0.1:7000", "frp server's address") + cmd.PersistentFlags().StringVarP(&user, "user", "u", "", "user") + cmd.PersistentFlags().StringVarP(&protocol, "protocol", "p", "tcp", "tcp or kcp or websocket") + cmd.PersistentFlags().StringVarP(&token, "token", "t", "", "auth token") + cmd.PersistentFlags().StringVarP(&logLevel, "log_level", "", "info", "log level") + cmd.PersistentFlags().StringVarP(&logFile, "log_file", "", "console", "console or file path") + cmd.PersistentFlags().IntVarP(&logMaxDays, "log_max_days", "", 3, "log file reversed days") + cmd.PersistentFlags().BoolVarP(&disableLogColor, "disable_log_color", "", false, "disable log color in console") + cmd.PersistentFlags().BoolVarP(&tlsEnable, "tls_enable", "", false, "enable frpc tls") +} + var rootCmd = &cobra.Command{ Use: "frpc", Short: "frpc is the client of frp (https://github.com/fatedier/frp)", diff --git a/cmd/frpc/sub/stcp.go b/cmd/frpc/sub/stcp.go index e51d21f3..02a4f5ae 100644 --- a/cmd/frpc/sub/stcp.go +++ b/cmd/frpc/sub/stcp.go @@ -25,14 +25,7 @@ import ( ) func init() { - stcpCmd.PersistentFlags().StringVarP(&serverAddr, "server_addr", "s", "127.0.0.1:7000", "frp server's address") - stcpCmd.PersistentFlags().StringVarP(&user, "user", "u", "", "user") - stcpCmd.PersistentFlags().StringVarP(&protocol, "protocol", "p", "tcp", "tcp or kcp or websocket") - stcpCmd.PersistentFlags().StringVarP(&token, "token", "t", "", "auth token") - stcpCmd.PersistentFlags().StringVarP(&logLevel, "log_level", "", "info", "log level") - stcpCmd.PersistentFlags().StringVarP(&logFile, "log_file", "", "console", "console or file path") - stcpCmd.PersistentFlags().IntVarP(&logMaxDays, "log_max_days", "", 3, "log file reversed days") - stcpCmd.PersistentFlags().BoolVarP(&disableLogColor, "disable_log_color", "", false, "disable log color in console") + RegisterCommonFlags(stcpCmd) stcpCmd.PersistentFlags().StringVarP(&proxyName, "proxy_name", "n", "", "proxy name") stcpCmd.PersistentFlags().StringVarP(&role, "role", "", "server", "role") @@ -44,7 +37,6 @@ func init() { stcpCmd.PersistentFlags().IntVarP(&bindPort, "bind_port", "", 0, "bind port") stcpCmd.PersistentFlags().BoolVarP(&useEncryption, "ue", "", false, "use encryption") stcpCmd.PersistentFlags().BoolVarP(&useCompression, "uc", "", false, "use compression") - stcpCmd.PersistentFlags().BoolVarP(&tlsEnable, "tls_enable", "", false, "enable frpc tls") rootCmd.AddCommand(stcpCmd) } diff --git a/cmd/frpc/sub/sudp.go b/cmd/frpc/sub/sudp.go index 63da2377..7e174c8b 100644 --- a/cmd/frpc/sub/sudp.go +++ b/cmd/frpc/sub/sudp.go @@ -25,14 +25,7 @@ import ( ) func init() { - sudpCmd.PersistentFlags().StringVarP(&serverAddr, "server_addr", "s", "127.0.0.1:7000", "frp server's address") - sudpCmd.PersistentFlags().StringVarP(&user, "user", "u", "", "user") - sudpCmd.PersistentFlags().StringVarP(&protocol, "protocol", "p", "tcp", "tcp or kcp or websocket") - sudpCmd.PersistentFlags().StringVarP(&token, "token", "t", "", "auth token") - sudpCmd.PersistentFlags().StringVarP(&logLevel, "log_level", "", "info", "log level") - sudpCmd.PersistentFlags().StringVarP(&logFile, "log_file", "", "console", "console or file path") - sudpCmd.PersistentFlags().IntVarP(&logMaxDays, "log_max_days", "", 3, "log file reversed days") - sudpCmd.PersistentFlags().BoolVarP(&disableLogColor, "disable_log_color", "", false, "disable log color in console") + RegisterCommonFlags(sudpCmd) sudpCmd.PersistentFlags().StringVarP(&proxyName, "proxy_name", "n", "", "proxy name") sudpCmd.PersistentFlags().StringVarP(&role, "role", "", "server", "role") @@ -44,7 +37,6 @@ func init() { sudpCmd.PersistentFlags().IntVarP(&bindPort, "bind_port", "", 0, "bind port") sudpCmd.PersistentFlags().BoolVarP(&useEncryption, "ue", "", false, "use encryption") sudpCmd.PersistentFlags().BoolVarP(&useCompression, "uc", "", false, "use compression") - sudpCmd.PersistentFlags().BoolVarP(&tlsEnable, "tls_enable", "", false, "enable frpc tls") rootCmd.AddCommand(sudpCmd) } diff --git a/cmd/frpc/sub/tcp.go b/cmd/frpc/sub/tcp.go index f98945a7..2817a4f0 100644 --- a/cmd/frpc/sub/tcp.go +++ b/cmd/frpc/sub/tcp.go @@ -25,14 +25,7 @@ import ( ) func init() { - tcpCmd.PersistentFlags().StringVarP(&serverAddr, "server_addr", "s", "127.0.0.1:7000", "frp server's address") - tcpCmd.PersistentFlags().StringVarP(&user, "user", "u", "", "user") - tcpCmd.PersistentFlags().StringVarP(&protocol, "protocol", "p", "tcp", "tcp or kcp") - tcpCmd.PersistentFlags().StringVarP(&token, "token", "t", "", "auth token") - tcpCmd.PersistentFlags().StringVarP(&logLevel, "log_level", "", "info", "log level") - tcpCmd.PersistentFlags().StringVarP(&logFile, "log_file", "", "console", "console or file path") - tcpCmd.PersistentFlags().IntVarP(&logMaxDays, "log_max_days", "", 3, "log file reversed days") - tcpCmd.PersistentFlags().BoolVarP(&disableLogColor, "disable_log_color", "", false, "disable log color in console") + RegisterCommonFlags(tcpCmd) tcpCmd.PersistentFlags().StringVarP(&proxyName, "proxy_name", "n", "", "proxy name") tcpCmd.PersistentFlags().StringVarP(&localIp, "local_ip", "i", "127.0.0.1", "local ip") @@ -40,7 +33,6 @@ func init() { tcpCmd.PersistentFlags().IntVarP(&remotePort, "remote_port", "r", 0, "remote port") tcpCmd.PersistentFlags().BoolVarP(&useEncryption, "ue", "", false, "use encryption") tcpCmd.PersistentFlags().BoolVarP(&useCompression, "uc", "", false, "use compression") - tcpCmd.PersistentFlags().BoolVarP(&tlsEnable, "tls_enable", "", false, "enable frpc tls") rootCmd.AddCommand(tcpCmd) } diff --git a/cmd/frpc/sub/tcpmux.go b/cmd/frpc/sub/tcpmux.go index 2e1b5f40..412888c6 100644 --- a/cmd/frpc/sub/tcpmux.go +++ b/cmd/frpc/sub/tcpmux.go @@ -26,14 +26,7 @@ import ( ) func init() { - tcpMuxCmd.PersistentFlags().StringVarP(&serverAddr, "server_addr", "s", "127.0.0.1:7000", "frp server's address") - tcpMuxCmd.PersistentFlags().StringVarP(&user, "user", "u", "", "user") - tcpMuxCmd.PersistentFlags().StringVarP(&protocol, "protocol", "p", "tcp", "tcp or kcp or websocket") - tcpMuxCmd.PersistentFlags().StringVarP(&token, "token", "t", "", "auth token") - tcpMuxCmd.PersistentFlags().StringVarP(&logLevel, "log_level", "", "info", "log level") - tcpMuxCmd.PersistentFlags().StringVarP(&logFile, "log_file", "", "console", "console or file path") - tcpMuxCmd.PersistentFlags().IntVarP(&logMaxDays, "log_max_days", "", 3, "log file reversed days") - tcpMuxCmd.PersistentFlags().BoolVarP(&disableLogColor, "disable_log_color", "", false, "disable log color in console") + RegisterCommonFlags(tcpMuxCmd) tcpMuxCmd.PersistentFlags().StringVarP(&proxyName, "proxy_name", "n", "", "proxy name") tcpMuxCmd.PersistentFlags().StringVarP(&localIp, "local_ip", "i", "127.0.0.1", "local ip") @@ -43,7 +36,6 @@ func init() { tcpMuxCmd.PersistentFlags().StringVarP(&multiplexer, "mux", "", "", "multiplexer") tcpMuxCmd.PersistentFlags().BoolVarP(&useEncryption, "ue", "", false, "use encryption") tcpMuxCmd.PersistentFlags().BoolVarP(&useCompression, "uc", "", false, "use compression") - tcpMuxCmd.PersistentFlags().BoolVarP(&tlsEnable, "tls_enable", "", false, "enable frpc tls") rootCmd.AddCommand(tcpMuxCmd) } diff --git a/cmd/frpc/sub/udp.go b/cmd/frpc/sub/udp.go index 40bd9ae6..ba5988e1 100644 --- a/cmd/frpc/sub/udp.go +++ b/cmd/frpc/sub/udp.go @@ -25,14 +25,7 @@ import ( ) func init() { - udpCmd.PersistentFlags().StringVarP(&serverAddr, "server_addr", "s", "127.0.0.1:7000", "frp server's address") - udpCmd.PersistentFlags().StringVarP(&user, "user", "u", "", "user") - udpCmd.PersistentFlags().StringVarP(&protocol, "protocol", "p", "tcp", "tcp or kcp or websocket") - udpCmd.PersistentFlags().StringVarP(&token, "token", "t", "", "auth token") - udpCmd.PersistentFlags().StringVarP(&logLevel, "log_level", "", "info", "log level") - udpCmd.PersistentFlags().StringVarP(&logFile, "log_file", "", "console", "console or file path") - udpCmd.PersistentFlags().IntVarP(&logMaxDays, "log_max_days", "", 3, "log file reversed days") - udpCmd.PersistentFlags().BoolVarP(&disableLogColor, "disable_log_color", "", false, "disable log color in console") + RegisterCommonFlags(udpCmd) udpCmd.PersistentFlags().StringVarP(&proxyName, "proxy_name", "n", "", "proxy name") udpCmd.PersistentFlags().StringVarP(&localIp, "local_ip", "i", "127.0.0.1", "local ip") @@ -40,7 +33,6 @@ func init() { udpCmd.PersistentFlags().IntVarP(&remotePort, "remote_port", "r", 0, "remote port") udpCmd.PersistentFlags().BoolVarP(&useEncryption, "ue", "", false, "use encryption") udpCmd.PersistentFlags().BoolVarP(&useCompression, "uc", "", false, "use compression") - udpCmd.PersistentFlags().BoolVarP(&tlsEnable, "tls_enable", "", false, "enable frpc tls") rootCmd.AddCommand(udpCmd) } diff --git a/cmd/frpc/sub/xtcp.go b/cmd/frpc/sub/xtcp.go index e0960a1f..38b45181 100644 --- a/cmd/frpc/sub/xtcp.go +++ b/cmd/frpc/sub/xtcp.go @@ -25,14 +25,7 @@ import ( ) func init() { - xtcpCmd.PersistentFlags().StringVarP(&serverAddr, "server_addr", "s", "127.0.0.1:7000", "frp server's address") - xtcpCmd.PersistentFlags().StringVarP(&user, "user", "u", "", "user") - xtcpCmd.PersistentFlags().StringVarP(&protocol, "protocol", "p", "tcp", "tcp or kcp or websocket") - xtcpCmd.PersistentFlags().StringVarP(&token, "token", "t", "", "auth token") - xtcpCmd.PersistentFlags().StringVarP(&logLevel, "log_level", "", "info", "log level") - xtcpCmd.PersistentFlags().StringVarP(&logFile, "log_file", "", "console", "console or file path") - xtcpCmd.PersistentFlags().IntVarP(&logMaxDays, "log_max_days", "", 3, "log file reversed days") - xtcpCmd.PersistentFlags().BoolVarP(&disableLogColor, "disable_log_color", "", false, "disable log color in console") + RegisterCommonFlags(xtcpCmd) xtcpCmd.PersistentFlags().StringVarP(&proxyName, "proxy_name", "n", "", "proxy name") xtcpCmd.PersistentFlags().StringVarP(&role, "role", "", "server", "role") @@ -44,7 +37,6 @@ func init() { xtcpCmd.PersistentFlags().IntVarP(&bindPort, "bind_port", "", 0, "bind port") xtcpCmd.PersistentFlags().BoolVarP(&useEncryption, "ue", "", false, "use encryption") xtcpCmd.PersistentFlags().BoolVarP(&useCompression, "uc", "", false, "use compression") - xtcpCmd.PersistentFlags().BoolVarP(&tlsEnable, "tls_enable", "", false, "enable frpc tls") rootCmd.AddCommand(xtcpCmd) }