зеркало из https://github.com/github/vitess-gh.git
[cli] [servenv] Migrate `--version` flag to pflag, and also add to `vtctldclient` and `vtadmin` (#11189)
* unexport servenv.Version Signed-off-by: Andrew Mason <andrew@planetscale.com> * [cli] [servenv] Migrate `--version` flag to pflag Relates to #11144. Signed-off-by: Andrew Mason <andrew@planetscale.com> * [cli] [vtadmin|vtctldclient] Add `--version` flags to cobra commands Closes #10909. Signed-off-by: Andrew Mason <andrew@planetscale.com>
This commit is contained in:
Родитель
08b91ee65f
Коммит
944a961094
|
@ -27,6 +27,7 @@ import (
|
|||
|
||||
"vitess.io/vitess/go/trace"
|
||||
"vitess.io/vitess/go/vt/log"
|
||||
"vitess.io/vitess/go/vt/servenv"
|
||||
"vitess.io/vitess/go/vt/vtadmin"
|
||||
"vitess.io/vitess/go/vt/vtadmin/cache"
|
||||
"vitess.io/vitess/go/vt/vtadmin/cluster"
|
||||
|
@ -68,6 +69,7 @@ var (
|
|||
PostRun: func(cmd *cobra.Command, args []string) {
|
||||
trace.LogErrorsWhenClosing(traceCloser)
|
||||
},
|
||||
Version: servenv.AppVersion.String(),
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
|
||||
"vitess.io/vitess/go/trace"
|
||||
"vitess.io/vitess/go/vt/servenv"
|
||||
"vitess.io/vitess/go/vt/vtctl/vtctldclient"
|
||||
)
|
||||
|
||||
|
@ -80,6 +81,7 @@ var (
|
|||
// all errors in cobra (just from being output, they still get
|
||||
// propagated).
|
||||
SilenceErrors: true,
|
||||
Version: servenv.AppVersion.String(),
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -17,12 +17,13 @@ limitations under the License.
|
|||
package servenv
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
|
||||
"vitess.io/vitess/go/stats"
|
||||
)
|
||||
|
||||
|
@ -34,10 +35,14 @@ var (
|
|||
buildGitBranch = ""
|
||||
jenkinsBuildNumberStr = ""
|
||||
|
||||
// Version registers the command line flag to expose build info.
|
||||
Version = flag.Bool("version", false, "print binary version")
|
||||
// version registers the command line flag to expose build info.
|
||||
version bool
|
||||
)
|
||||
|
||||
func registerVersionFlag(fs *pflag.FlagSet) {
|
||||
fs.BoolVar(&version, "version", version, "print binary version")
|
||||
}
|
||||
|
||||
// AppVersion is the struct to store build info.
|
||||
var AppVersion versionInfo
|
||||
|
||||
|
@ -136,4 +141,6 @@ func init() {
|
|||
fmt.Sprintf("%v", AppVersion.jenkinsBuildNumber),
|
||||
}
|
||||
stats.NewGaugesWithMultiLabels("BuildInformation", "build information exposed via label", buildLabels).Set(buildValues, 1)
|
||||
|
||||
OnParse(registerVersionFlag)
|
||||
}
|
||||
|
|
|
@ -313,7 +313,7 @@ func ParseFlags(cmd string) {
|
|||
|
||||
_flag.Parse(fs)
|
||||
|
||||
if *Version {
|
||||
if version {
|
||||
AppVersion.Print()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
@ -334,7 +334,7 @@ func ParseFlagsWithArgs(cmd string) []string {
|
|||
|
||||
_flag.Parse(fs)
|
||||
|
||||
if *Version {
|
||||
if version {
|
||||
AppVersion.Print()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче