Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add buildinfo flag #6286

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Profiling Options:
Common Options:
-h, --help Show this message
-v, --version Show version
--buildinfo Show buildinfo
--help_tls TLS help
`

Expand Down
7 changes: 7 additions & 0 deletions server/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -5680,6 +5680,7 @@ func ConfigureOptions(fs *flag.FlagSet, args []string, printVersion, printHelp,
opts := &Options{}
var (
showVersion bool
showBuildInfo bool
showHelp bool
showTLSHelp bool
signal string
Expand Down Expand Up @@ -5735,6 +5736,7 @@ func ConfigureOptions(fs *flag.FlagSet, args []string, printVersion, printHelp,
fs.StringVar(&opts.RemoteSyslog, "remote_syslog", _EMPTY_, "Syslog server addr (udp://127.0.0.1:514).")
fs.BoolVar(&showVersion, "version", false, "Print version information.")
fs.BoolVar(&showVersion, "v", false, "Print version information.")
fs.BoolVar(&showBuildInfo, "buildinfo", false, "Print buildinfo.")
fs.IntVar(&opts.ProfPort, "profile", 0, "Profiling HTTP port.")
fs.StringVar(&opts.RoutesStr, "routes", _EMPTY_, "Routes to actively solicit a connection.")
fs.StringVar(&opts.Cluster.ListenStr, "cluster", _EMPTY_, "Cluster url from which members can solicit routes.")
Expand Down Expand Up @@ -5772,6 +5774,11 @@ func ConfigureOptions(fs *flag.FlagSet, args []string, printVersion, printHelp,
return nil, nil
}

if showBuildInfo {
PrintBuildinfoAndExit()
return nil, nil
}

if showHelp {
printHelp()
return nil, nil
Expand Down
13 changes: 13 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"path/filepath"
"regexp"
"runtime"
"runtime/debug"
"runtime/pprof"
"strconv"
"strings"
Expand Down Expand Up @@ -1583,6 +1584,18 @@ func PrintServerAndExit() {
os.Exit(0)
}

// PrintBuildinfoAndExit will print out https://pkg.go.dev/runtime/debug#BuildInfo and exit.
func PrintBuildinfoAndExit() {
bi, ok := debug.ReadBuildInfo()
if !ok || bi == nil {
//nolint:forbidigo
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neilalexander ok to ignore like this here?

fmt.Println("failed to read Buildinfo")
}
//nolint:forbidigo
fmt.Println(bi)
os.Exit(0)
}

// ProcessCommandLineArgs takes the command line arguments
// validating and setting flags for handling in case any
// sub command was present.
Expand Down
Loading