mirror of
https://github.com/minio/minio.git
synced 2024-12-24 06:05:55 -05:00
update '-v' flag behavior to include copyRight and license (#15097)
``` ~ minio -v minio version DEVELOPMENT.2022-06-16T20-40-14Z (commit-id=e083228e2a06bfdcd006fee28d449cd2b47c542a) Runtime: go1.18.3 linux/amd64 Copyright (c) 2015-2022 MinIO, Inc. Licence AGPLv3 <https://www.gnu.org/licenses/agpl-3.0.html> ```
This commit is contained in:
parent
013cc66d8e
commit
d228d29944
@ -24,14 +24,18 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func genLDFlags(version string) string {
|
func genLDFlags(version string) string {
|
||||||
|
releaseTag, date := releaseTag(version)
|
||||||
|
copyrightYear := strconv.Itoa(date.Year())
|
||||||
ldflagsStr := "-s -w"
|
ldflagsStr := "-s -w"
|
||||||
ldflagsStr += " -X github.com/minio/minio/cmd.Version=" + version
|
ldflagsStr += " -X github.com/minio/minio/cmd.Version=" + version
|
||||||
ldflagsStr += " -X github.com/minio/minio/cmd.ReleaseTag=" + releaseTag(version)
|
ldflagsStr += " -X github.com/minio/minio/cmd.CopyrightYear=" + copyrightYear
|
||||||
|
ldflagsStr += " -X github.com/minio/minio/cmd.ReleaseTag=" + releaseTag
|
||||||
ldflagsStr += " -X github.com/minio/minio/cmd.CommitID=" + commitID()
|
ldflagsStr += " -X github.com/minio/minio/cmd.CommitID=" + commitID()
|
||||||
ldflagsStr += " -X github.com/minio/minio/cmd.ShortCommitID=" + commitID()[:12]
|
ldflagsStr += " -X github.com/minio/minio/cmd.ShortCommitID=" + commitID()[:12]
|
||||||
ldflagsStr += " -X github.com/minio/minio/cmd.GOPATH=" + os.Getenv("GOPATH")
|
ldflagsStr += " -X github.com/minio/minio/cmd.GOPATH=" + os.Getenv("GOPATH")
|
||||||
@ -40,7 +44,7 @@ func genLDFlags(version string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// genReleaseTag prints release tag to the console for easy git tagging.
|
// genReleaseTag prints release tag to the console for easy git tagging.
|
||||||
func releaseTag(version string) string {
|
func releaseTag(version string) (string, time.Time) {
|
||||||
relPrefix := "DEVELOPMENT"
|
relPrefix := "DEVELOPMENT"
|
||||||
if prefix := os.Getenv("MINIO_RELEASE"); prefix != "" {
|
if prefix := os.Getenv("MINIO_RELEASE"); prefix != "" {
|
||||||
relPrefix = prefix
|
relPrefix = prefix
|
||||||
@ -53,14 +57,17 @@ func releaseTag(version string) string {
|
|||||||
|
|
||||||
relTag := strings.Replace(version, " ", "-", -1)
|
relTag := strings.Replace(version, " ", "-", -1)
|
||||||
relTag = strings.Replace(relTag, ":", "-", -1)
|
relTag = strings.Replace(relTag, ":", "-", -1)
|
||||||
|
t, err := time.Parse("2006-01-02T15-04-05Z", relTag)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
relTag = strings.Replace(relTag, ",", "", -1)
|
relTag = strings.Replace(relTag, ",", "", -1)
|
||||||
relTag = relPrefix + "." + relTag
|
relTag = relPrefix + "." + relTag
|
||||||
|
|
||||||
if relSuffix != "" {
|
if relSuffix != "" {
|
||||||
relTag += "." + relSuffix
|
relTag += "." + relSuffix
|
||||||
}
|
}
|
||||||
|
|
||||||
return relTag
|
return relTag, t
|
||||||
}
|
}
|
||||||
|
|
||||||
// commitID returns the abbreviated commit-id hash of the last commit.
|
// commitID returns the abbreviated commit-id hash of the last commit.
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||||
//
|
//
|
||||||
// This file is part of MinIO Object Storage stack
|
// This file is part of MinIO Object Storage stack
|
||||||
//
|
//
|
||||||
@ -37,4 +37,7 @@ var (
|
|||||||
|
|
||||||
// ShortCommitID - first 12 characters from CommitID.
|
// ShortCommitID - first 12 characters from CommitID.
|
||||||
ShortCommitID = "DEVELOPMENT.GOGET"
|
ShortCommitID = "DEVELOPMENT.GOGET"
|
||||||
|
|
||||||
|
// CopyrightYear - dynamic value of the copyright end year
|
||||||
|
CopyrightYear = "0000"
|
||||||
)
|
)
|
||||||
|
32
cmd/main.go
32
cmd/main.go
@ -18,12 +18,14 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
|
"github.com/minio/minio/internal/color"
|
||||||
"github.com/minio/pkg/console"
|
"github.com/minio/pkg/console"
|
||||||
"github.com/minio/pkg/trie"
|
"github.com/minio/pkg/trie"
|
||||||
"github.com/minio/pkg/words"
|
"github.com/minio/pkg/words"
|
||||||
@ -69,11 +71,6 @@ 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}}
|
||||||
@ -137,20 +134,16 @@ func newApp(name string) *cli.App {
|
|||||||
Name: "help, h",
|
Name: "help, h",
|
||||||
Usage: "show help",
|
Usage: "show help",
|
||||||
}
|
}
|
||||||
|
cli.VersionPrinter = printMinIOVersion
|
||||||
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.Action = versionAndHelpAction
|
app.Version = ReleaseTag
|
||||||
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 = topLevelFlags
|
app.Flags = GlobalFlags
|
||||||
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) {
|
||||||
@ -170,16 +163,11 @@ func newApp(name string) *cli.App {
|
|||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
||||||
func versionAndHelpAction(ctx *cli.Context) {
|
func printMinIOVersion(c *cli.Context) {
|
||||||
if ctx.IsSet("version") {
|
fmt.Fprintln(c.App.Writer, color.Greenf("%s version %s (commit-id=%s)", c.App.Name, c.App.Version, CommitID))
|
||||||
console.Printf("%s version %s\n", ctx.App.Name, ReleaseTag)
|
fmt.Fprintln(c.App.Writer, color.Greenf("Runtime: %s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH))
|
||||||
console.Printf("commit: %s\n", CommitID)
|
fmt.Fprintln(c.App.Writer, color.Greenf("Copyright (c) 2015-%s MinIO, Inc.", CopyrightYear))
|
||||||
console.Printf("go version: %s\n", runtime.Version())
|
fmt.Fprintln(c.App.Writer, color.Red("Licence AGPLv3 <https://www.gnu.org/licenses/agpl-3.0.html>"))
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
cli.ShowAppHelpAndExit(ctx, 1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main main for minio server.
|
// Main main for minio server.
|
||||||
|
@ -73,6 +73,13 @@ var (
|
|||||||
return fmt.Sprint
|
return fmt.Sprint
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
Greenf = func() func(format string, a ...interface{}) string {
|
||||||
|
if IsTerminal() {
|
||||||
|
return color.New(color.FgGreen).SprintfFunc()
|
||||||
|
}
|
||||||
|
return fmt.Sprintf
|
||||||
|
}()
|
||||||
|
|
||||||
GreenBold = func() func(a ...interface{}) string {
|
GreenBold = func() func(a ...interface{}) string {
|
||||||
if IsTerminal() {
|
if IsTerminal() {
|
||||||
return color.New(color.FgGreen, color.Bold).SprintFunc()
|
return color.New(color.FgGreen, color.Bold).SprintFunc()
|
||||||
|
Loading…
Reference in New Issue
Block a user