mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-05-19 18:58:03 +02:00
4af2ded428
* feat: migrate CLI to cobra with dump/list/version subcommands (#546) * fix: remove residual duckduckgo references and add README/LICENSE to release archives * fix: address PR review feedback from Copilot
54 lines
960 B
Go
54 lines
960 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime/debug"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var (
|
|
version = "dev"
|
|
commit = "none"
|
|
buildDate = "unknown"
|
|
)
|
|
|
|
func versionCmd() *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "version",
|
|
Short: "Print version information",
|
|
Run: func(cmd *cobra.Command, _ []string) {
|
|
resolveVersionFromBuildInfo()
|
|
fmt.Fprintf(cmd.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 _, s := range info.Settings {
|
|
switch s.Key {
|
|
case "vcs.revision":
|
|
if len(s.Value) > 8 {
|
|
commit = s.Value[:8]
|
|
} else if s.Value != "" {
|
|
commit = s.Value
|
|
}
|
|
case "vcs.time":
|
|
if s.Value != "" {
|
|
buildDate = s.Value
|
|
}
|
|
}
|
|
}
|
|
}
|