Restore config loading, keep exported Version, keep cgo off

Bring back the in-progress viper and go-homedir configuration loading
from the original root command as a persistent pre-run on the root
command, with a --config flag and a config line in sutil info. Restore
the exported main.Version with a nolint directive instead of renaming
it. Export CGO_ENABLED=0 from the Makefile, drop -race from make test,
and remove the C toolchain from the Docker builder stage.
This commit is contained in:
2026-10-31 10:11:47 -07:00
parent f53b6aad42
commit 4d45aa4ca3
9 changed files with 243 additions and 25 deletions
+15 -5
View File
@@ -15,31 +15,41 @@ import (
// module support.
var ErrNoBuildInfo = errors.New("sutil: no build information in this binary")
// noConfigFile is what `sutil info` prints when no config file was loaded.
const noConfigFile = "(none)"
// newInfoCommand returns `sutil info`, which prints the build version, the
// Go toolchain version, the module path, and the VCS metadata recorded by
// the Go toolchain at build time.
func newInfoCommand(p Params) *cobra.Command {
// Go toolchain version, the module path, the configuration file in use,
// and the VCS metadata recorded by the Go toolchain at build time.
func newInfoCommand(a *app) *cobra.Command {
return &cobra.Command{
Use: "info",
Short: "Print build information",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
return writeBuildInfo(cmd.OutOrStdout(), p.Version)
return writeBuildInfo(
cmd.OutOrStdout(), a.params.Version, a.configFileUsed(),
)
},
}
}
// writeBuildInfo writes one "key: value" line per fact to w.
func writeBuildInfo(w io.Writer, version string) error {
func writeBuildInfo(w io.Writer, version, configFile string) error {
info, ok := debug.ReadBuildInfo()
if !ok {
return ErrNoBuildInfo
}
if configFile == "" {
configFile = noConfigFile
}
lines := []string{
"version: " + version,
"go: " + info.GoVersion,
"module: " + info.Main.Path,
"config: " + configFile,
}
for _, setting := range info.Settings {