diff --git a/cmd/main.go b/cmd/main.go index cba9fdfff..1b320b064 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -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.