Update --version option behavior (#15032)

- Add git commit ID
- Add go version
This commit is contained in:
Aditya Manthramurthy 2022-06-02 18:40:53 -07:00 committed by GitHub
parent 09f5e29327
commit 61a7434379
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -20,6 +20,7 @@ package cmd
import (
"os"
"path/filepath"
"runtime"
"sort"
"github.com/minio/cli"
@ -68,6 +69,11 @@ var GlobalFlags = []cli.Flag{
},
}
var versionFlag = cli.BoolFlag{
Name: "version, v",
Usage: "print version information",
}
// Help template for minio.
var minioHelpTemplate = `NAME:
{{.Name}} - {{.Usage}}
@ -132,14 +138,19 @@ func newApp(name string) *cli.App {
Usage: "show help",
}
topLevelFlags := make([]cli.Flag, len(GlobalFlags)+1)
copy(topLevelFlags, GlobalFlags)
topLevelFlags[len(GlobalFlags)] = versionFlag
app := cli.NewApp()
app.Name = name
app.Author = "MinIO, Inc."
app.Version = ReleaseTag
app.Action = versionAndHelpAction
app.Usage = "High Performance Object Storage"
app.Description = `Build high performance data infrastructure for machine learning, analytics and application data workloads with MinIO`
app.Flags = GlobalFlags
app.Flags = topLevelFlags
app.HideHelpCommand = true // Hide `help, h` command, we already have `minio --help`.
app.HideVersion = true
app.Commands = commands
app.CustomAppHelpTemplate = minioHelpTemplate
app.CommandNotFound = func(ctx *cli.Context, command string) {
@ -159,6 +170,18 @@ func newApp(name string) *cli.App {
return app
}
func versionAndHelpAction(ctx *cli.Context) {
if ctx.IsSet("version") {
console.Printf("%s version %s\n", ctx.App.Name, ReleaseTag)
console.Printf("commit: %s\n", CommitID)
console.Printf("go version: %s\n", runtime.Version())
return
}
cli.ShowAppHelpAndExit(ctx, 1)
}
// Main main for minio server.
func Main(args []string) {
// Set the minio app name.