feat: cli migrate to cobra with subcommands (#550)

* 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
This commit is contained in:
Roger
2026-04-05 14:25:51 +08:00
committed by GitHub
parent 068b82178f
commit 4af2ded428
15 changed files with 418 additions and 112 deletions
+53
View File
@@ -0,0 +1,53 @@
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
}
}
}
}