From e22615e1807147738d15e840372faba064bde152 Mon Sep 17 00:00:00 2001 From: Alex Bozhenko Date: Fri, 13 Dec 2024 16:03:05 -0800 Subject: [PATCH 1/6] Add buildinfo flag Signed-off-by: Alex Bozhenko --- main.go | 2 ++ server/opts.go | 16 +++++++++++++--- server/opts_test.go | 22 ++++++++++++---------- server/reload_test.go | 2 +- server/server.go | 23 ++++++++++++++++++----- server/server_test.go | 31 ++++++++++++++++++++++++++----- 6 files changed, 72 insertions(+), 24 deletions(-) diff --git a/main.go b/main.go index ee6c105bf47..f0427dc1304 100644 --- a/main.go +++ b/main.go @@ -86,6 +86,7 @@ Profiling Options: Common Options: -h, --help Show this message -v, --version Show version + --buildinfo Show buildinfo --help_tls TLS help ` @@ -106,6 +107,7 @@ func main() { opts, err := server.ConfigureOptions(fs, os.Args[1:], server.PrintServerAndExit, fs.Usage, + server.PrintBuildinfoAndExit, server.PrintTLSHelpAndDie) if err != nil { server.PrintAndDie(fmt.Sprintf("%s: %s", exe, err)) diff --git a/server/opts.go b/server/opts.go index 172377253ee..30c498647a8 100644 --- a/server/opts.go +++ b/server/opts.go @@ -5676,10 +5676,11 @@ func getDefaultAuthTimeout(tls *tls.Config, tlsTimeout float64) float64 { // specific flags. On success, an options structure is returned configured // based on the selected flags and/or configuration file. // The command line options take precedence to the ones in the configuration file. -func ConfigureOptions(fs *flag.FlagSet, args []string, printVersion, printHelp, printTLSHelp func()) (*Options, error) { +func ConfigureOptions(fs *flag.FlagSet, args []string, printVersion, printHelp, printBuildinfo, printTLSHelp func()) (*Options, error) { opts := &Options{} var ( showVersion bool + showBuildInfo bool showHelp bool showTLSHelp bool signal string @@ -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.") @@ -5772,6 +5774,11 @@ func ConfigureOptions(fs *flag.FlagSet, args []string, printVersion, printHelp, return nil, nil } + if showBuildInfo { + printBuildinfo() + return nil, nil + } + if showHelp { printHelp() return nil, nil @@ -5783,8 +5790,8 @@ func ConfigureOptions(fs *flag.FlagSet, args []string, printVersion, printHelp, } // Process args looking for non-flag options, - // 'version' and 'help' only for now - showVersion, showHelp, err = ProcessCommandLineArgs(fs) + // 'version', 'help' and 'buildinfo' only for now + showVersion, showHelp, showBuildInfo, err = ProcessCommandLineArgs(fs) if err != nil { return nil, err } else if showVersion { @@ -5793,6 +5800,9 @@ func ConfigureOptions(fs *flag.FlagSet, args []string, printVersion, printHelp, } else if showHelp { printHelp() return nil, nil + } else if showBuildInfo { + printBuildinfo() + return nil, nil } // Snapshot flag options. diff --git a/server/opts_test.go b/server/opts_test.go index 0cc482da5dd..9ee03f21b9d 100644 --- a/server/opts_test.go +++ b/server/opts_test.go @@ -1434,19 +1434,21 @@ func TestConfigureOptions(t *testing.T) { usage := func() { panic("should not get there") } var fs *flag.FlagSet type testPrint struct { - args []string - version, help, tlsHelp func() + args []string + version, help, tlsHelp, buildinfo func() } testFuncs := []testPrint{ - {[]string{"-v"}, checkPrintInvoked, usage, PrintTLSHelpAndDie}, - {[]string{"version"}, checkPrintInvoked, usage, PrintTLSHelpAndDie}, - {[]string{"-h"}, PrintServerAndExit, checkPrintInvoked, PrintTLSHelpAndDie}, - {[]string{"help"}, PrintServerAndExit, checkPrintInvoked, PrintTLSHelpAndDie}, - {[]string{"-help_tls"}, PrintServerAndExit, usage, checkPrintInvoked}, + {[]string{"-v"}, checkPrintInvoked, usage, PrintTLSHelpAndDie, checkPrintInvoked}, + {[]string{"version"}, checkPrintInvoked, usage, PrintTLSHelpAndDie, checkPrintInvoked}, + {[]string{"-h"}, PrintServerAndExit, checkPrintInvoked, PrintTLSHelpAndDie, checkPrintInvoked}, + {[]string{"help"}, PrintServerAndExit, checkPrintInvoked, PrintTLSHelpAndDie, checkPrintInvoked}, + {[]string{"-help_tls"}, PrintServerAndExit, usage, checkPrintInvoked, checkPrintInvoked}, + {[]string{"buildinfo"}, PrintServerAndExit, usage, PrintTLSHelpAndDie, checkPrintInvoked}, + {[]string{"-buildinfo"}, PrintServerAndExit, usage, PrintTLSHelpAndDie, checkPrintInvoked}, } for _, tf := range testFuncs { fs = flag.NewFlagSet("test", flag.ContinueOnError) - opts, err := ConfigureOptions(fs, tf.args, tf.version, tf.help, tf.tlsHelp) + opts, err := ConfigureOptions(fs, tf.args, tf.version, tf.help, tf.buildinfo, tf.tlsHelp) if err != nil { t.Fatalf("Error on configure: %v", err) } @@ -1463,7 +1465,7 @@ func TestConfigureOptions(t *testing.T) { // Helper function that expect parsing with given args to not produce an error. mustNotFail := func(args []string) *Options { fs := flag.NewFlagSet("test", flag.ContinueOnError) - opts, err := ConfigureOptions(fs, args, PrintServerAndExit, fs.Usage, PrintTLSHelpAndDie) + opts, err := ConfigureOptions(fs, args, PrintServerAndExit, fs.Usage, PrintBuildinfoAndExit, PrintTLSHelpAndDie) if err != nil { stackFatalf(t, "Error on configure: %v", err) } @@ -1477,7 +1479,7 @@ func TestConfigureOptions(t *testing.T) { // (flagSet would print error message about unknown flags, etc..) silenceOuput := &bytes.Buffer{} fs.SetOutput(silenceOuput) - opts, err := ConfigureOptions(fs, args, PrintServerAndExit, fs.Usage, PrintTLSHelpAndDie) + opts, err := ConfigureOptions(fs, args, PrintServerAndExit, fs.Usage, PrintBuildinfoAndExit, PrintTLSHelpAndDie) if opts != nil || err == nil { stackFatalf(t, "Expected no option and an error, got opts=%v and err=%v", opts, err) } diff --git a/server/reload_test.go b/server/reload_test.go index bc20f40641c..2a95a445982 100644 --- a/server/reload_test.go +++ b/server/reload_test.go @@ -3818,7 +3818,7 @@ func TestConfigReloadBoolFlags(t *testing.T) { if test.cmdLine != nil { args = append(args, test.cmdLine...) } - opts, err = ConfigureOptions(fs, args, nil, nil, nil) + opts, err = ConfigureOptions(fs, args, nil, nil, nil, nil) if err != nil { t.Fatalf("Error processing config: %v", err) } diff --git a/server/server.go b/server/server.go index 030dea5f5bf..baab175ab96 100644 --- a/server/server.go +++ b/server/server.go @@ -33,6 +33,7 @@ import ( "path/filepath" "regexp" "runtime" + "runtime/debug" "runtime/pprof" "strconv" "strings" @@ -1583,23 +1584,35 @@ 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 { + fmt.Println("failed to read Buildinfo") + } + 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. -func ProcessCommandLineArgs(cmd *flag.FlagSet) (showVersion bool, showHelp bool, err error) { +func ProcessCommandLineArgs(cmd *flag.FlagSet) (showVersion bool, showHelp bool, showBuildinfo bool, err error) { if len(cmd.Args()) > 0 { arg := cmd.Args()[0] switch strings.ToLower(arg) { case "version": - return true, false, nil + return true, false, false, nil case "help": - return false, true, nil + return false, true, false, nil + case "buildinfo": + return false, false, true, nil default: - return false, false, fmt.Errorf("unrecognized command: %q", arg) + return false, false, false, fmt.Errorf("unrecognized command: %q", arg) } } - return false, false, nil + return false, false, false, nil } // Public version. diff --git a/server/server_test.go b/server/server_test.go index 9f389261069..12c189d181d 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -659,16 +659,16 @@ func TestProcessCommandLineArgs(t *testing.T) { cmd.IntVar(&port, "p", 4222, "Port.") cmd.Parse([]string{"-a", "127.0.0.1", "-p", "9090"}) - showVersion, showHelp, err := ProcessCommandLineArgs(cmd) + showVersion, showHelp, showBuildinfo, err := ProcessCommandLineArgs(cmd) if err != nil { t.Errorf("Expected no errors, got: %s", err) } - if showVersion || showHelp { + if showVersion || showHelp || showBuildinfo { t.Errorf("Expected not having to handle subcommands") } cmd.Parse([]string{"version"}) - showVersion, showHelp, err = ProcessCommandLineArgs(cmd) + showVersion, showHelp, showBuildinfo, err = ProcessCommandLineArgs(cmd) if err != nil { t.Errorf("Expected no errors, got: %s", err) } @@ -678,9 +678,12 @@ func TestProcessCommandLineArgs(t *testing.T) { if showHelp { t.Errorf("Expected not having to handle help command") } + if showBuildinfo { + t.Errorf("Expected not having to handle buildinfo command") + } cmd.Parse([]string{"help"}) - showVersion, showHelp, err = ProcessCommandLineArgs(cmd) + showVersion, showHelp, showBuildinfo, err = ProcessCommandLineArgs(cmd) if err != nil { t.Errorf("Expected no errors, got: %s", err) } @@ -690,9 +693,27 @@ func TestProcessCommandLineArgs(t *testing.T) { if !showHelp { t.Errorf("Expected having to handle help command") } + if showBuildinfo { + t.Errorf("Expected not having to handle buildinfo command") + } + + cmd.Parse([]string{"buildinfo"}) + showVersion, showHelp, showBuildinfo, err = ProcessCommandLineArgs(cmd) + if err != nil { + t.Errorf("Expected no errors, got: %s", err) + } + if showVersion { + t.Errorf("Expected not having to handle version command") + } + if showHelp { + t.Errorf("Expected not having to handle help command") + } + if !showBuildinfo { + t.Errorf("Expected having to handle buildinfo command") + } cmd.Parse([]string{"foo", "-p", "9090"}) - _, _, err = ProcessCommandLineArgs(cmd) + _, _, _, err = ProcessCommandLineArgs(cmd) if err == nil { t.Errorf("Expected an error handling the command arguments") } From 194f19c25d4b73b190fcbec5b62a148cb646cda6 Mon Sep 17 00:00:00 2001 From: Alex Bozhenko Date: Thu, 19 Dec 2024 16:00:45 -0800 Subject: [PATCH 2/6] add nolint for these printlns --- server/server.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/server.go b/server/server.go index baab175ab96..d7811838f72 100644 --- a/server/server.go +++ b/server/server.go @@ -1588,8 +1588,10 @@ func PrintServerAndExit() { func PrintBuildinfoAndExit() { bi, ok := debug.ReadBuildInfo() if !ok || bi == nil { + //nolint:forbidigo fmt.Println("failed to read Buildinfo") } + //nolint:forbidigo fmt.Println(bi) os.Exit(0) } From 70443b5d06be8bd341bb2f4b2ff56728118eaacb Mon Sep 17 00:00:00 2001 From: Alex Bozhenko Date: Thu, 26 Dec 2024 16:04:21 -0800 Subject: [PATCH 3/6] make it not break semver Signed-off-by: Alex Bozhenko --- main.go | 1 - server/opts.go | 11 ++++------- server/opts_test.go | 22 ++++++++++------------ server/reload_test.go | 2 +- server/server.go | 12 +++++------- server/server_test.go | 31 +++++-------------------------- 6 files changed, 25 insertions(+), 54 deletions(-) diff --git a/main.go b/main.go index f0427dc1304..2e860d81925 100644 --- a/main.go +++ b/main.go @@ -107,7 +107,6 @@ func main() { opts, err := server.ConfigureOptions(fs, os.Args[1:], server.PrintServerAndExit, fs.Usage, - server.PrintBuildinfoAndExit, server.PrintTLSHelpAndDie) if err != nil { server.PrintAndDie(fmt.Sprintf("%s: %s", exe, err)) diff --git a/server/opts.go b/server/opts.go index 30c498647a8..aac2ef5153f 100644 --- a/server/opts.go +++ b/server/opts.go @@ -5676,7 +5676,7 @@ func getDefaultAuthTimeout(tls *tls.Config, tlsTimeout float64) float64 { // specific flags. On success, an options structure is returned configured // based on the selected flags and/or configuration file. // The command line options take precedence to the ones in the configuration file. -func ConfigureOptions(fs *flag.FlagSet, args []string, printVersion, printHelp, printBuildinfo, printTLSHelp func()) (*Options, error) { +func ConfigureOptions(fs *flag.FlagSet, args []string, printVersion, printHelp, printTLSHelp func()) (*Options, error) { opts := &Options{} var ( showVersion bool @@ -5775,7 +5775,7 @@ func ConfigureOptions(fs *flag.FlagSet, args []string, printVersion, printHelp, } if showBuildInfo { - printBuildinfo() + PrintBuildinfoAndExit() return nil, nil } @@ -5790,8 +5790,8 @@ func ConfigureOptions(fs *flag.FlagSet, args []string, printVersion, printHelp, } // Process args looking for non-flag options, - // 'version', 'help' and 'buildinfo' only for now - showVersion, showHelp, showBuildInfo, err = ProcessCommandLineArgs(fs) + // 'version' and 'help' only for now + showVersion, showHelp, err = ProcessCommandLineArgs(fs) if err != nil { return nil, err } else if showVersion { @@ -5800,9 +5800,6 @@ func ConfigureOptions(fs *flag.FlagSet, args []string, printVersion, printHelp, } else if showHelp { printHelp() return nil, nil - } else if showBuildInfo { - printBuildinfo() - return nil, nil } // Snapshot flag options. diff --git a/server/opts_test.go b/server/opts_test.go index 9ee03f21b9d..0cc482da5dd 100644 --- a/server/opts_test.go +++ b/server/opts_test.go @@ -1434,21 +1434,19 @@ func TestConfigureOptions(t *testing.T) { usage := func() { panic("should not get there") } var fs *flag.FlagSet type testPrint struct { - args []string - version, help, tlsHelp, buildinfo func() + args []string + version, help, tlsHelp func() } testFuncs := []testPrint{ - {[]string{"-v"}, checkPrintInvoked, usage, PrintTLSHelpAndDie, checkPrintInvoked}, - {[]string{"version"}, checkPrintInvoked, usage, PrintTLSHelpAndDie, checkPrintInvoked}, - {[]string{"-h"}, PrintServerAndExit, checkPrintInvoked, PrintTLSHelpAndDie, checkPrintInvoked}, - {[]string{"help"}, PrintServerAndExit, checkPrintInvoked, PrintTLSHelpAndDie, checkPrintInvoked}, - {[]string{"-help_tls"}, PrintServerAndExit, usage, checkPrintInvoked, checkPrintInvoked}, - {[]string{"buildinfo"}, PrintServerAndExit, usage, PrintTLSHelpAndDie, checkPrintInvoked}, - {[]string{"-buildinfo"}, PrintServerAndExit, usage, PrintTLSHelpAndDie, checkPrintInvoked}, + {[]string{"-v"}, checkPrintInvoked, usage, PrintTLSHelpAndDie}, + {[]string{"version"}, checkPrintInvoked, usage, PrintTLSHelpAndDie}, + {[]string{"-h"}, PrintServerAndExit, checkPrintInvoked, PrintTLSHelpAndDie}, + {[]string{"help"}, PrintServerAndExit, checkPrintInvoked, PrintTLSHelpAndDie}, + {[]string{"-help_tls"}, PrintServerAndExit, usage, checkPrintInvoked}, } for _, tf := range testFuncs { fs = flag.NewFlagSet("test", flag.ContinueOnError) - opts, err := ConfigureOptions(fs, tf.args, tf.version, tf.help, tf.buildinfo, tf.tlsHelp) + opts, err := ConfigureOptions(fs, tf.args, tf.version, tf.help, tf.tlsHelp) if err != nil { t.Fatalf("Error on configure: %v", err) } @@ -1465,7 +1463,7 @@ func TestConfigureOptions(t *testing.T) { // Helper function that expect parsing with given args to not produce an error. mustNotFail := func(args []string) *Options { fs := flag.NewFlagSet("test", flag.ContinueOnError) - opts, err := ConfigureOptions(fs, args, PrintServerAndExit, fs.Usage, PrintBuildinfoAndExit, PrintTLSHelpAndDie) + opts, err := ConfigureOptions(fs, args, PrintServerAndExit, fs.Usage, PrintTLSHelpAndDie) if err != nil { stackFatalf(t, "Error on configure: %v", err) } @@ -1479,7 +1477,7 @@ func TestConfigureOptions(t *testing.T) { // (flagSet would print error message about unknown flags, etc..) silenceOuput := &bytes.Buffer{} fs.SetOutput(silenceOuput) - opts, err := ConfigureOptions(fs, args, PrintServerAndExit, fs.Usage, PrintBuildinfoAndExit, PrintTLSHelpAndDie) + opts, err := ConfigureOptions(fs, args, PrintServerAndExit, fs.Usage, PrintTLSHelpAndDie) if opts != nil || err == nil { stackFatalf(t, "Expected no option and an error, got opts=%v and err=%v", opts, err) } diff --git a/server/reload_test.go b/server/reload_test.go index 2a95a445982..bc20f40641c 100644 --- a/server/reload_test.go +++ b/server/reload_test.go @@ -3818,7 +3818,7 @@ func TestConfigReloadBoolFlags(t *testing.T) { if test.cmdLine != nil { args = append(args, test.cmdLine...) } - opts, err = ConfigureOptions(fs, args, nil, nil, nil, nil) + opts, err = ConfigureOptions(fs, args, nil, nil, nil) if err != nil { t.Fatalf("Error processing config: %v", err) } diff --git a/server/server.go b/server/server.go index d7811838f72..c6a3195fb89 100644 --- a/server/server.go +++ b/server/server.go @@ -1599,22 +1599,20 @@ func PrintBuildinfoAndExit() { // ProcessCommandLineArgs takes the command line arguments // validating and setting flags for handling in case any // sub command was present. -func ProcessCommandLineArgs(cmd *flag.FlagSet) (showVersion bool, showHelp bool, showBuildinfo bool, err error) { +func ProcessCommandLineArgs(cmd *flag.FlagSet) (showVersion bool, showHelp bool, err error) { if len(cmd.Args()) > 0 { arg := cmd.Args()[0] switch strings.ToLower(arg) { case "version": - return true, false, false, nil + return true, false, nil case "help": - return false, true, false, nil - case "buildinfo": - return false, false, true, nil + return false, true, nil default: - return false, false, false, fmt.Errorf("unrecognized command: %q", arg) + return false, false, fmt.Errorf("unrecognized command: %q", arg) } } - return false, false, false, nil + return false, false, nil } // Public version. diff --git a/server/server_test.go b/server/server_test.go index 12c189d181d..9f389261069 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -659,16 +659,16 @@ func TestProcessCommandLineArgs(t *testing.T) { cmd.IntVar(&port, "p", 4222, "Port.") cmd.Parse([]string{"-a", "127.0.0.1", "-p", "9090"}) - showVersion, showHelp, showBuildinfo, err := ProcessCommandLineArgs(cmd) + showVersion, showHelp, err := ProcessCommandLineArgs(cmd) if err != nil { t.Errorf("Expected no errors, got: %s", err) } - if showVersion || showHelp || showBuildinfo { + if showVersion || showHelp { t.Errorf("Expected not having to handle subcommands") } cmd.Parse([]string{"version"}) - showVersion, showHelp, showBuildinfo, err = ProcessCommandLineArgs(cmd) + showVersion, showHelp, err = ProcessCommandLineArgs(cmd) if err != nil { t.Errorf("Expected no errors, got: %s", err) } @@ -678,12 +678,9 @@ func TestProcessCommandLineArgs(t *testing.T) { if showHelp { t.Errorf("Expected not having to handle help command") } - if showBuildinfo { - t.Errorf("Expected not having to handle buildinfo command") - } cmd.Parse([]string{"help"}) - showVersion, showHelp, showBuildinfo, err = ProcessCommandLineArgs(cmd) + showVersion, showHelp, err = ProcessCommandLineArgs(cmd) if err != nil { t.Errorf("Expected no errors, got: %s", err) } @@ -693,27 +690,9 @@ func TestProcessCommandLineArgs(t *testing.T) { if !showHelp { t.Errorf("Expected having to handle help command") } - if showBuildinfo { - t.Errorf("Expected not having to handle buildinfo command") - } - - cmd.Parse([]string{"buildinfo"}) - showVersion, showHelp, showBuildinfo, err = ProcessCommandLineArgs(cmd) - if err != nil { - t.Errorf("Expected no errors, got: %s", err) - } - if showVersion { - t.Errorf("Expected not having to handle version command") - } - if showHelp { - t.Errorf("Expected not having to handle help command") - } - if !showBuildinfo { - t.Errorf("Expected having to handle buildinfo command") - } cmd.Parse([]string{"foo", "-p", "9090"}) - _, _, _, err = ProcessCommandLineArgs(cmd) + _, _, err = ProcessCommandLineArgs(cmd) if err == nil { t.Errorf("Expected an error handling the command arguments") } From e680e5bf025cef8cb95a6f2c017679829bd70772 Mon Sep 17 00:00:00 2001 From: Alex Bozhenko Date: Fri, 27 Dec 2024 11:10:12 -0800 Subject: [PATCH 4/6] make printBuildinfoAndExit not exported --- server/opts.go | 2 +- server/server.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/opts.go b/server/opts.go index aac2ef5153f..c8c369e045b 100644 --- a/server/opts.go +++ b/server/opts.go @@ -5775,7 +5775,7 @@ func ConfigureOptions(fs *flag.FlagSet, args []string, printVersion, printHelp, } if showBuildInfo { - PrintBuildinfoAndExit() + printBuildinfoAndExit() return nil, nil } diff --git a/server/server.go b/server/server.go index c6a3195fb89..d1bd3f9f563 100644 --- a/server/server.go +++ b/server/server.go @@ -1584,8 +1584,8 @@ func PrintServerAndExit() { os.Exit(0) } -// PrintBuildinfoAndExit will print out https://pkg.go.dev/runtime/debug#BuildInfo and exit. -func PrintBuildinfoAndExit() { +// 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 From 4561b5f1f8d6fb09a8d949e04699a254da13ddcf Mon Sep 17 00:00:00 2001 From: Alex Bozhenko Date: Fri, 27 Dec 2024 13:24:22 -0800 Subject: [PATCH 5/6] nit fixes --- server/opts.go | 2 +- server/server.go | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/server/opts.go b/server/opts.go index c8c369e045b..c7a3af71f07 100644 --- a/server/opts.go +++ b/server/opts.go @@ -5775,7 +5775,7 @@ func ConfigureOptions(fs *flag.FlagSet, args []string, printVersion, printHelp, } if showBuildInfo { - printBuildinfoAndExit() + printBuildInfoAndExit() return nil, nil } diff --git a/server/server.go b/server/server.go index d1bd3f9f563..bbfae711bdc 100644 --- a/server/server.go +++ b/server/server.go @@ -1584,13 +1584,15 @@ func PrintServerAndExit() { os.Exit(0) } -// printBuildinfoAndExit will print out https://pkg.go.dev/runtime/debug#BuildInfo and exit. -func printBuildinfoAndExit() { +// 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 - fmt.Println("failed to read Buildinfo") + fmt.Fprintln(os.Stderr, "failed to read BuildInfo") + os.Exit(1) } + //nolint:forbidigo fmt.Println(bi) os.Exit(0) From 280824c6c5499bddf09f815aad618c9f39b4269c Mon Sep 17 00:00:00 2001 From: Alex Bozhenko Date: Fri, 27 Dec 2024 13:28:49 -0800 Subject: [PATCH 6/6] drop from help text --- main.go | 1 - 1 file changed, 1 deletion(-) diff --git a/main.go b/main.go index 2e860d81925..ee6c105bf47 100644 --- a/main.go +++ b/main.go @@ -86,7 +86,6 @@ Profiling Options: Common Options: -h, --help Show this message -v, --version Show version - --buildinfo Show buildinfo --help_tls TLS help `