diff --git a/go/flags/endtoend/mysqlctl.txt b/go/flags/endtoend/mysqlctl.txt index cd2758007e2..6041bdd538e 100644 --- a/go/flags/endtoend/mysqlctl.txt +++ b/go/flags/endtoend/mysqlctl.txt @@ -110,8 +110,8 @@ Global flags: --stderrthreshold severity logs at or above this threshold go to stderr (default 1) --tablet_dir string The directory within the vtdataroot to store vttablet/mysql files. Defaults to being generated by the tablet uid. --tablet_uid uint Tablet UID (default 41983) - -v, --v Level log level for V logs - --version print binary version + --v Level log level for V logs + -v, --version print binary version --vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging --xbstream_restore_flags string flags to pass to xbstream command during restore. These should be space separated and will be added to the end of the command. These need to match the ones used for backup e.g. --compress / --decompress, --encrypt / --decrypt --xtrabackup_backup_flags string flags to pass to backup command. These should be space separated and will be added to the end of the command diff --git a/go/flags/endtoend/mysqlctld.txt b/go/flags/endtoend/mysqlctld.txt index 6ac669ed9c9..9776c39bbd6 100644 --- a/go/flags/endtoend/mysqlctld.txt +++ b/go/flags/endtoend/mysqlctld.txt @@ -98,8 +98,8 @@ Usage of mysqlctld: --stderrthreshold severity logs at or above this threshold go to stderr (default 1) --tablet_dir string The directory within the vtdataroot to store vttablet/mysql files. Defaults to being generated by the tablet uid. --tablet_uid uint Tablet UID (default 41983) - -v, --v Level log level for V logs - --version print binary version + --v Level log level for V logs + -v, --version print binary version --vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging --wait_time duration How long to wait for mysqld startup or shutdown (default 5m0s) --xbstream_restore_flags string flags to pass to xbstream command during restore. These should be space separated and will be added to the end of the command. These need to match the ones used for backup e.g. --compress / --decompress, --encrypt / --decrypt diff --git a/go/flags/endtoend/vtaclcheck.txt b/go/flags/endtoend/vtaclcheck.txt index 4b158925437..6e2c57db109 100644 --- a/go/flags/endtoend/vtaclcheck.txt +++ b/go/flags/endtoend/vtaclcheck.txt @@ -14,6 +14,6 @@ Usage of vtaclcheck: --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) --static-auth-file string The path of the auth_server_static JSON file to check --stderrthreshold severity logs at or above this threshold go to stderr (default 1) - -v, --v Level log level for V logs - --version print binary version + --v Level log level for V logs + -v, --version print binary version --vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging diff --git a/go/flags/endtoend/vtbackup.txt b/go/flags/endtoend/vtbackup.txt index 98f145904fa..7023fd7355f 100644 --- a/go/flags/endtoend/vtbackup.txt +++ b/go/flags/endtoend/vtbackup.txt @@ -157,8 +157,8 @@ Usage of vtbackup: --topo_zk_tls_ca string the server ca to use to validate servers when connecting to the zk topo server --topo_zk_tls_cert string the cert to use to connect to the zk topo server, requires topo_zk_tls_key, enables TLS --topo_zk_tls_key string the key to use to connect to the zk topo server, enables TLS - -v, --v Level log level for V logs - --version print binary version + --v Level log level for V logs + -v, --version print binary version --vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging --xbstream_restore_flags string flags to pass to xbstream command during restore. These should be space separated and will be added to the end of the command. These need to match the ones used for backup e.g. --compress / --decompress, --encrypt / --decrypt --xtrabackup_backup_flags string flags to pass to backup command. These should be space separated and will be added to the end of the command diff --git a/go/flags/endtoend/vtctlclient.txt b/go/flags/endtoend/vtctlclient.txt index 8896b7b3f72..207f31905f2 100644 --- a/go/flags/endtoend/vtctlclient.txt +++ b/go/flags/endtoend/vtctlclient.txt @@ -30,8 +30,8 @@ Usage of vtctlclient: --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 + --v Level log level for V logs + -v, --version print binary version --vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging --vtctl_client_protocol string 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 diff --git a/go/flags/endtoend/vtctld.txt b/go/flags/endtoend/vtctld.txt index 5895327dc5f..cf4559b445a 100644 --- a/go/flags/endtoend/vtctld.txt +++ b/go/flags/endtoend/vtctld.txt @@ -151,8 +151,8 @@ Usage of vtctld: --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 + --v Level log level for V logs + -v, --version print binary version --vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging --vtctl_healthcheck_retry_delay duration delay before retrying a failed healthcheck (default 5s) --vtctl_healthcheck_timeout duration the health check timeout period (default 1m0s) diff --git a/go/flags/endtoend/vtexplain.txt b/go/flags/endtoend/vtexplain.txt index df5fea9d1d6..50b7c741c49 100644 --- a/go/flags/endtoend/vtexplain.txt +++ b/go/flags/endtoend/vtexplain.txt @@ -79,8 +79,8 @@ Usage of vtexplain: --topo_global_root string the path of the global topology data in the global topology server --topo_global_server_address string the address of the global topology server --topo_implementation string the topology implementation to use - -v, --v Level log level for V logs - --version print binary version + --v Level log level for V logs + -v, --version print binary version --vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging --vschema string Identifies the VTGate routing schema --vschema-file string Identifies the VTGate routing schema file diff --git a/go/flags/endtoend/vtgate.txt b/go/flags/endtoend/vtgate.txt index f6add89785e..11b6dabcb26 100644 --- a/go/flags/endtoend/vtgate.txt +++ b/go/flags/endtoend/vtgate.txt @@ -184,8 +184,8 @@ Usage of vtgate: --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") --transaction_mode string SINGLE: disallow multi-db transactions, MULTI: allow multi-db transactions with best effort commit, TWOPC: allow multi-db transactions with 2pc commit (default "MULTI") - -v, --v Level log level for V logs - --version print binary version + --v Level log level for V logs + -v, --version print binary version --vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging --vschema_ddl_authorized_users string List of users authorized to execute vschema ddl operations, or '%' to allow all users. --vtctld_addr string address of a vtctld instance diff --git a/go/flags/endtoend/vtgr.txt b/go/flags/endtoend/vtgr.txt index d4ed0501d9e..f110e4638b2 100644 --- a/go/flags/endtoend/vtgr.txt +++ b/go/flags/endtoend/vtgr.txt @@ -60,7 +60,7 @@ Usage of vtgr: --topo_zk_tls_ca string the server ca to use to validate servers when connecting to the zk topo server --topo_zk_tls_cert string the cert to use to connect to the zk topo server, requires topo_zk_tls_key, enables TLS --topo_zk_tls_key string the key to use to connect to the zk topo server, enables TLS - -v, --v Level log level for V logs - --version print binary version + --v Level log level for V logs + -v, --version print binary version --vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging --vtgr_config string Config file for vtgr. diff --git a/go/flags/endtoend/vtorc.txt b/go/flags/endtoend/vtorc.txt index e8270b9f5e7..35a7dea2eb0 100644 --- a/go/flags/endtoend/vtorc.txt +++ b/go/flags/endtoend/vtorc.txt @@ -73,7 +73,7 @@ Usage of vtorc: --topo_zk_tls_ca string the server ca to use to validate servers when connecting to the zk topo server --topo_zk_tls_cert string the cert to use to connect to the zk topo server, requires topo_zk_tls_key, enables TLS --topo_zk_tls_key string the key to use to connect to the zk topo server, enables TLS - -v, --v Level log level for V logs - --version print binary version + --v Level log level for V logs + -v, --version print binary version --vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging --wait-replicas-timeout duration Duration for which to wait for replica's to respond when issuing RPCs (default 30s) diff --git a/go/flags/endtoend/vttablet.txt b/go/flags/endtoend/vttablet.txt index 9340e5a0c01..5e71075963f 100644 --- a/go/flags/endtoend/vttablet.txt +++ b/go/flags/endtoend/vttablet.txt @@ -343,8 +343,8 @@ Usage of vttablet: --tx_throttler_healthcheck_cells strings A comma-separated list of cells. Only tabletservers running in these cells will be monitored for replication lag by the transaction throttler. --unhealthy_threshold duration replication lag after which a replica is considered unhealthy (default 2h0m0s) --use_super_read_only Set super_read_only flag when performing planned failover. - -v, --v Level log level for V logs - --version print binary version + --v Level log level for V logs + -v, --version print binary version --vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging --vreplication_copy_phase_duration duration Duration for each copy phase loop (before running the next catchup: default 1h) (default 1h0m0s) --vreplication_copy_phase_max_innodb_history_list_length int The maximum InnoDB transaction history that can exist on a vstreamer (source) before starting another round of copying rows. This helps to limit the impact on the source tablet. (default 1000000) diff --git a/go/flags/endtoend/vttestserver.txt b/go/flags/endtoend/vttestserver.txt index 384ebd7fe06..7445878bf2a 100644 --- a/go/flags/endtoend/vttestserver.txt +++ b/go/flags/endtoend/vttestserver.txt @@ -119,8 +119,8 @@ Usage of vttestserver: --topo_zk_tls_cert string the cert to use to connect to the zk topo server, requires topo_zk_tls_key, enables TLS --topo_zk_tls_key string the key to use to connect to the zk topo server, enables TLS --transaction_mode string Transaction mode MULTI (default), SINGLE or TWOPC (default "MULTI") - -v, --v Level log level for V logs - --version print binary version + --v Level log level for V logs + -v, --version print binary version --vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging --vschema_ddl_authorized_users string Comma separated list of users authorized to execute vschema ddl operations via vtgate --vtctl_client_protocol string Protocol to use to talk to the vtctl server. (default "grpc") diff --git a/go/flags/endtoend/zkctl.txt b/go/flags/endtoend/zkctl.txt index e07334f86ac..e7e41c4cb4d 100644 --- a/go/flags/endtoend/zkctl.txt +++ b/go/flags/endtoend/zkctl.txt @@ -11,8 +11,8 @@ Usage of zkctl: --pprof strings enable profiling --purge_logs_interval duration how often try to remove old logs (default 1h0m0s) --stderrthreshold severity logs at or above this threshold go to stderr (default 1) - -v, --v Level log level for V logs - --version print binary version + --v Level log level for V logs + -v, --version print binary version --vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging --zk.cfg string zkid@server1:leaderPort1:electionPort1:clientPort1,...) (default "6@:3801:3802:3803") --zk.myid uint which server do you want to be? only needed when running multiple instance on one box, otherwise myid is implied by hostname diff --git a/go/flags/endtoend/zkctld.txt b/go/flags/endtoend/zkctld.txt index 9bfec0066f7..6ec026be814 100644 --- a/go/flags/endtoend/zkctld.txt +++ b/go/flags/endtoend/zkctld.txt @@ -12,8 +12,8 @@ Usage of zkctld: --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) --stderrthreshold severity logs at or above this threshold go to stderr (default 1) - -v, --v Level log level for V logs - --version print binary version + --v Level log level for V logs + -v, --version print binary version --vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging --zk.cfg string zkid@server1:leaderPort1:electionPort1:clientPort1,...) (default "6@:3801:3802:3803") --zk.myid uint which server do you want to be? only needed when running multiple instance on one box, otherwise myid is implied by hostname diff --git a/go/internal/flag/flag.go b/go/internal/flag/flag.go index a06f1c63988..2c99e22017f 100644 --- a/go/internal/flag/flag.go +++ b/go/internal/flag/flag.go @@ -44,6 +44,7 @@ import ( // // See VEP-4, phase 1 for details: https://github.com/vitessio/enhancements/blob/c766ea905e55409cddeb666d6073cd2ac4c9783e/veps/vep-4.md#phase-1-preparation func Parse(fs *flag.FlagSet) { + preventGlogVFlagFromClobberingVersionFlagShorthand(fs) fs.AddGoFlagSet(goflag.CommandLine) if fs.Lookup("help") == nil { @@ -96,6 +97,32 @@ func TrickGlog() { os.Args = append(os.Args, args...) } +// The default behavior of PFlagFromGoFlag (which is called on each flag when +// calling AddGoFlagSet) is to allow any flags with single-character names to be +// accessible both as, for example, `-v` and `--v`. +// +// This prevents us from exposing version via `--version|-v` (pflag will actually +// panic when it goes to add the glog log-level flag), so we intervene to blank +// out the Shorthand for _just_ that flag before adding the rest of the goflags +// to a particular pflag FlagSet. +// +// IMPORTANT: This must be called prior to AddGoFlagSet in both Parse and +// ParseFlagsForTest. +func preventGlogVFlagFromClobberingVersionFlagShorthand(fs *flag.FlagSet) { + // N.B. we use goflag.Lookup instead of this package's Lookup, because we + // explicitly want to check only the goflags. + if f := goflag.Lookup("v"); f != nil { + if fs.Lookup("v") != nil { // This check is exactly what AddGoFlagSet does. + return + } + + pf := flag.PFlagFromGoFlag(f) + pf.Shorthand = "" + + fs.AddFlag(pf) + } +} + // Usage invokes the current CommandLine's Usage func, or if not overridden, // "prints a simple header and calls PrintDefaults". func Usage() { @@ -135,6 +162,7 @@ func ParseFlagsForTest() { } // parse remaining flags including the log-related ones like --alsologtostderr + preventGlogVFlagFromClobberingVersionFlagShorthand(flag.CommandLine) flag.CommandLine.AddGoFlagSet(goflag.CommandLine) flag.Parse() } diff --git a/go/vt/servenv/buildinfo.go b/go/vt/servenv/buildinfo.go index c03c85009ed..d00b4f063ff 100644 --- a/go/vt/servenv/buildinfo.go +++ b/go/vt/servenv/buildinfo.go @@ -40,7 +40,7 @@ var ( ) func registerVersionFlag(fs *pflag.FlagSet) { - fs.BoolVar(&version, "version", version, "print binary version") + fs.BoolVarP(&version, "version", "v", version, "print binary version") } // AppVersion is the struct to store build info.