diff --git a/go/cmd/vtctlclient/main.go b/go/cmd/vtctlclient/main.go index 49b17e2d0d..cba66b74b7 100644 --- a/go/cmd/vtctlclient/main.go +++ b/go/cmd/vtctlclient/main.go @@ -19,7 +19,6 @@ package main import ( "context" "errors" - "flag" "fmt" "os" "strings" @@ -31,21 +30,27 @@ import ( "vitess.io/vitess/go/trace" "vitess.io/vitess/go/vt/log" "vitess.io/vitess/go/vt/logutil" + "vitess.io/vitess/go/vt/servenv" "vitess.io/vitess/go/vt/vtctl/vtctlclient" logutilpb "vitess.io/vitess/go/vt/proto/logutil" - // Include deprecation warnings for soon-to-be-unsupported flag invocations. - _flag "vitess.io/vitess/go/internal/flag" ) // The default values used by these flags cannot be taken from wrangler and // actionnode modules, as we don't want to depend on them at all. var ( - actionTimeout = flag.Duration("action_timeout", time.Hour, "timeout for the total command") - server = flag.String("server", "", "server to use for connection") + actionTimeout = time.Hour + server string ) +func init() { + servenv.OnParse(func(fs *pflag.FlagSet) { + fs.DurationVar(&actionTimeout, "action_timeout", actionTimeout, "timeout for the total command") + fs.StringVar(&server, "server", server, "server to use for connection") + }) +} + // checkDeprecations runs quick and dirty checks to see whether any command or flag are deprecated. // For any depracated command or flag, the function issues a warning message. // this function will change on each Vitess version. Each depracation message should only last a version. @@ -72,9 +77,7 @@ func checkDeprecations(args []string) { func main() { defer exit.Recover() - fs := pflag.NewFlagSet("vtctlclient", pflag.ExitOnError) - log.RegisterFlags(fs) - _flag.Parse(fs) + args := servenv.ParseFlagsWithArgs("vtctlclient") closer := trace.StartTracing("vtctlclient") defer trace.LogErrorsWhenClosing(closer) @@ -82,28 +85,26 @@ func main() { logger := logutil.NewConsoleLogger() // We can't do much without a --server flag - if *server == "" { + if server == "" { log.Error(errors.New("please specify --server to specify the vtctld server to connect to")) os.Exit(1) } - ctx, cancel := context.WithTimeout(context.Background(), *actionTimeout) + ctx, cancel := context.WithTimeout(context.Background(), actionTimeout) defer cancel() - checkDeprecations(flag.Args()) + checkDeprecations(args) - err := vtctlclient.RunCommandAndWait( - ctx, *server, _flag.Args(), - func(e *logutilpb.Event) { - logutil.LogEvent(logger, e) - }) + err := vtctlclient.RunCommandAndWait(ctx, server, args, func(e *logutilpb.Event) { + logutil.LogEvent(logger, e) + }) if err != nil { if strings.Contains(err.Error(), "flag: help requested") { return } errStr := strings.Replace(err.Error(), "remote error: ", "", -1) - fmt.Printf("%s Error: %s\n", _flag.Arg(0), errStr) + fmt.Printf("%s Error: %s\n", args[0], errStr) log.Error(err) os.Exit(1) } diff --git a/go/flags/endtoend/vtctlclient.txt b/go/flags/endtoend/vtctlclient.txt new file mode 100644 index 0000000000..2c7753eb1a --- /dev/null +++ b/go/flags/endtoend/vtctlclient.txt @@ -0,0 +1,47 @@ +Usage of vtctlclient: + --action_timeout duration timeout for the total command (default 1h0m0s) + --alsologtostderr log to standard error as well as files + --datadog-agent-host string host to send spans to. if empty, no tracing will be done + --datadog-agent-port string port to send spans to. if empty, no tracing will be done + --emit_stats If set, emit stats to push-based monitoring and stats backends + --grpc_auth_static_client_creds string when using grpc_static_auth in the server, this file provides the credentials to use to authenticate with server + --grpc_compression string Which protocol to use for compressing gRPC. Default: nothing. Supported: snappy + --grpc_enable_tracing Enable gRPC tracing. + --grpc_initial_conn_window_size int gRPC initial connection window size + --grpc_initial_window_size int gRPC initial window size + --grpc_keepalive_time duration After a duration of this time, if the client doesn't see any activity, it pings the server to see if the transport is still alive. (default 10s) + --grpc_keepalive_timeout duration After having pinged for keepalive check, the client waits for a duration of Timeout and if no activity is seen even after that the connection is closed. (default 10s) + --grpc_max_message_size int Maximum allowed RPC message size. Larger messages will be rejected by gRPC with the error 'exceeding the max size'. (default 16777216) + --grpc_prometheus Enable gRPC monitoring with Prometheus. + -h, --help display usage and exit + --jaeger-agent-host string host and port to send spans to. if empty, no tracing will be done + --keep_logs duration keep logs for this long (using ctime) (zero to keep forever) + --keep_logs_by_mtime duration keep logs for this long (using mtime) (zero to keep forever) + --log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0) + --log_dir string If non-empty, write log files in this directory + --log_err_stacks log stack traces for errors + --log_rotate_max_size uint size in bytes at which logs are rotated (glog.MaxSize) (default 1887436800) + --logtostderr log to standard error instead of files + --pprof strings enable profiling + --purge_logs_interval duration how often try to remove old logs (default 1h0m0s) + --security_policy string the name of a registered security policy to use for controlling access to URLs - empty means allow all for anyone (built-in policies: deny-all, read-only) + --server string server to use for connection + --stats_backend string The name of the registered push-based monitoring/stats backend to use + --stats_combine_dimensions string List of dimensions to be combined into a single "all" value in exported stats vars + --stats_common_tags string Comma-separated list of common tags for the stats backend. It provides both label and values. Example: label1:value1,label2:value2 + --stats_drop_variables string Variables to be dropped from the list of exported variables. + --stats_emit_period duration Interval between emitting stats to all registered backends (default 1m0s) + --stderrthreshold severity logs at or above this threshold go to stderr (default 1) + --tracer string tracing service to use (default "noop") + --tracing-enable-logging whether to enable logging in the tracing service + --tracing-sampling-rate float sampling rate for the probabilistic jaeger sampler (default 0.1) + --tracing-sampling-type string sampling strategy to use for jaeger. possible values are 'const', 'probabilistic', 'rateLimiting', or 'remote' (default "const") + -v, --v Level log level for V logs + --version print binary version + --vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging + --vtctl_client_protocol string the protocol to use to talk to the vtctl server (default "grpc") + --vtctld_grpc_ca string the server ca to use to validate servers when connecting + --vtctld_grpc_cert string the cert to use to connect + --vtctld_grpc_crl string the server crl to use to validate server certificates when connecting + --vtctld_grpc_key string the key to use to connect + --vtctld_grpc_server_name string the server name to use to validate server certificate