mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
Names say what each thing is: no package stutter, one word per concept, spelled out, none that differ only in case. The browser table puts one field per line. Wire names (flags, output fields, keys.json) are unchanged.
54 lines
1023 B
Go
54 lines
1023 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime/debug"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var (
|
|
version = "dev"
|
|
commit = "none"
|
|
buildDate = "unknown"
|
|
)
|
|
|
|
func newVersionCommand() *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "version",
|
|
Short: "Print version information",
|
|
Run: func(command *cobra.Command, _ []string) {
|
|
resolveVersionFromBuildInfo()
|
|
fmt.Fprintf(command.OutOrStdout(), "hack-browser-data %s\n commit: %s\n built: %s\n",
|
|
version, commit, buildDate)
|
|
},
|
|
}
|
|
}
|
|
|
|
func resolveVersionFromBuildInfo() {
|
|
if version != "dev" {
|
|
return
|
|
}
|
|
info, ok := debug.ReadBuildInfo()
|
|
if !ok {
|
|
return
|
|
}
|
|
if info.Main.Version != "" && info.Main.Version != "(devel)" {
|
|
version = info.Main.Version
|
|
}
|
|
for _, setting := range info.Settings {
|
|
switch setting.Key {
|
|
case "vcs.revision":
|
|
if len(setting.Value) > 8 {
|
|
commit = setting.Value[:8]
|
|
} else if setting.Value != "" {
|
|
commit = setting.Value
|
|
}
|
|
case "vcs.time":
|
|
if setting.Value != "" {
|
|
buildDate = setting.Value
|
|
}
|
|
}
|
|
}
|
|
}
|