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 ( import (
"os" "os"
"path/filepath" "path/filepath"
"runtime"
"sort" "sort"
"github.com/minio/cli" "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. // Help template for minio.
var minioHelpTemplate = `NAME: var minioHelpTemplate = `NAME:
{{.Name}} - {{.Usage}} {{.Name}} - {{.Usage}}
@ -132,14 +138,19 @@ func newApp(name string) *cli.App {
Usage: "show help", Usage: "show help",
} }
topLevelFlags := make([]cli.Flag, len(GlobalFlags)+1)
copy(topLevelFlags, GlobalFlags)
topLevelFlags[len(GlobalFlags)] = versionFlag
app := cli.NewApp() app := cli.NewApp()
app.Name = name app.Name = name
app.Author = "MinIO, Inc." app.Author = "MinIO, Inc."
app.Version = ReleaseTag app.Action = versionAndHelpAction
app.Usage = "High Performance Object Storage" app.Usage = "High Performance Object Storage"
app.Description = `Build high performance data infrastructure for machine learning, analytics and application data workloads with MinIO` 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.HideHelpCommand = true // Hide `help, h` command, we already have `minio --help`.
app.HideVersion = true
app.Commands = commands app.Commands = commands
app.CustomAppHelpTemplate = minioHelpTemplate app.CustomAppHelpTemplate = minioHelpTemplate
app.CommandNotFound = func(ctx *cli.Context, command string) { app.CommandNotFound = func(ctx *cli.Context, command string) {
@ -159,6 +170,18 @@ func newApp(name string) *cli.App {
return 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. // Main main for minio server.
func Main(args []string) { func Main(args []string) {
// Set the minio app name. // Set the minio app name.