Include build info in info command

This commit is contained in:
Tim Van Baak 2025-05-02 12:29:46 -07:00
parent 46db4dd735
commit b42d425873

View File

@ -3,27 +3,30 @@ package cmd
import (
"database/sql"
"fmt"
"runtime/debug"
"github.com/Jaculabilis/intake/core"
"github.com/spf13/cobra"
)
var infoCmd = &cobra.Command{
Use: "info",
Use: "info [--build]",
Short: "Print intake config",
Long: `Print intake config as it would be used by other commands.
`,
Run: func(cmd *cobra.Command, args []string) {
info()
info(boolArg(cmd, "build"))
},
DisableFlagsInUseLine: true,
}
func init() {
rootCmd.AddCommand(infoCmd)
infoCmd.Flags().Bool("build", false, "Include exact build settings")
}
func info() {
func info(buildInfo bool) {
fmt.Printf("Revision: %s\n", core.GetRevInfo())
fmt.Printf("Data path: %s\n", dataPath)
@ -66,4 +69,13 @@ func info() {
} else {
fmt.Printf("Items: %d\n", items)
}
if buildInfo {
fmt.Printf("Build settings:\n")
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
fmt.Printf(" %s=%s\n", setting.Key, setting.Value)
}
}
}
}