Skip to content

Commit bee2864

Browse files
author
Fletcher Aksel
committed
add --version flag
Signed-off-by: Fletcher Aksel <[email protected]>
1 parent 878e458 commit bee2864

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

cmd/root.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,34 @@ package cmd
33
import (
44
"fmt"
55
"os"
6+
"runtime/debug"
67

78
"github.com/spf13/cobra"
89
)
910

1011
var rootCmd = &cobra.Command{
11-
Use: "gettrackers",
12-
Short: "Download, filter, and output tracker URLs grouped by domain",
13-
Long: `gettrackers is a CLI tool that downloads tracker URLs from configurable sources, filters them using a blocklist, and outputs them grouped by domain.`,
14-
RunE: runGroups,
12+
Use: "gettrackers",
13+
Short: "Download, filter, and output tracker URLs grouped by domain",
14+
Long: `gettrackers is a CLI tool that downloads tracker URLs from configurable sources, filters them using a blocklist, and outputs them grouped by domain.`,
15+
RunE: runGroups,
16+
Version: getVersion(),
1517
}
1618

1719
var outputFile string
1820

21+
func getVersion() string {
22+
info, ok := debug.ReadBuildInfo()
23+
if !ok {
24+
return "unknown"
25+
}
26+
27+
v := info.Main.Version
28+
if v == "" {
29+
return "(unknown)"
30+
}
31+
return v
32+
}
33+
1934
func init() {
2035
rootCmd.PersistentFlags().StringVarP(&outputFile, "output", "o", "", "Write output to file instead of stdout")
2136
rootCmd.Flags().IntVarP(&startPriority, "start-priority", "p", 0, "Output N blank lines before tracker groups (default: 0)")
@@ -37,4 +52,3 @@ func getOutputWriter() (*os.File, error) {
3752
}
3853
return os.Stdout, nil
3954
}
40-

0 commit comments

Comments
 (0)