| 1 | // SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | |
| 3 | package main |
| 4 | |
| 5 | import ( |
| 6 | "fmt" |
| 7 | "runtime" |
| 8 | |
| 9 | "github.com/spf13/cobra" |
| 10 | |
| 11 | "github.com/tenseleyFlow/shithub/internal/infra/config" |
| 12 | "github.com/tenseleyFlow/shithub/internal/version" |
| 13 | ) |
| 14 | |
| 15 | var versionCmd = &cobra.Command{ |
| 16 | Use: "version", |
| 17 | Short: "Print version, commit, build time, Go runtime, and configured observability sinks", |
| 18 | Run: func(cmd *cobra.Command, args []string) { |
| 19 | fmt.Printf("shithubd %s\n", version.Version) |
| 20 | fmt.Printf(" commit: %s\n", version.Commit) |
| 21 | fmt.Printf(" built: %s\n", version.BuiltAt) |
| 22 | fmt.Printf(" go: %s\n", runtime.Version()) |
| 23 | fmt.Printf(" os: %s/%s\n", runtime.GOOS, runtime.GOARCH) |
| 24 | |
| 25 | cfg, err := config.Load(nil) |
| 26 | if err != nil { |
| 27 | fmt.Printf(" config: <invalid: %s>\n", err) |
| 28 | return |
| 29 | } |
| 30 | fmt.Printf(" env: %s\n", cfg.Env) |
| 31 | fmt.Printf(" log: %s/%s\n", cfg.Log.Format, cfg.Log.Level) |
| 32 | fmt.Printf(" metrics: %s\n", boolStr(cfg.Metrics.Enabled)) |
| 33 | fmt.Printf(" tracing: %s\n", tracingStr(cfg.Tracing)) |
| 34 | fmt.Printf(" errrep: %s\n", errrepStr(cfg.ErrorReporting)) |
| 35 | }, |
| 36 | } |
| 37 | |
| 38 | func boolStr(b bool) string { |
| 39 | if b { |
| 40 | return "enabled" |
| 41 | } |
| 42 | return "disabled" |
| 43 | } |
| 44 | |
| 45 | func tracingStr(t config.TracingConfig) string { |
| 46 | if !t.Enabled { |
| 47 | return "disabled" |
| 48 | } |
| 49 | return fmt.Sprintf("enabled (endpoint=%s, sample=%.2f)", t.Endpoint, t.SampleRate) |
| 50 | } |
| 51 | |
| 52 | func errrepStr(e config.ErrorReportingConfig) string { |
| 53 | if e.DSN == "" { |
| 54 | return "disabled" |
| 55 | } |
| 56 | return "enabled (dsn=*** env=" + e.Environment + ")" |
| 57 | } |
| 58 |