commit 207463e
Ham Adams
·
2024-09-10 04:17:28 +0000 UTC
parent 770c472
Add a -version flag and display the version on start Add a -version flag that displays the current senpai version and exits. This makes use of the new Go 1.24 feature that embeds VCS information in the binary. See: https://tip.golang.org/doc/go1.24#go-command
4 files changed,
+29,
-4
M
app.go
+10,
-1
1@@ -18,6 +18,7 @@ import (
2 "os/exec"
3 "path/filepath"
4 "regexp"
5+ "runtime/debug"
6 "strconv"
7 "strings"
8 "sync"
9@@ -215,7 +216,7 @@ func NewApp(cfg Config) (app *App, err error) {
10 }
11
12 func (app *App) Close() {
13- app.win.Exit() // tell all instances of app.ircLoop to stop when possible
14+ app.win.Exit() // tell all instances of app.ircLoop to stop when possible
15 app.events <- event{ // tell app.eventLoop to stop
16 src: "*",
17 content: nil,
18@@ -2316,6 +2317,14 @@ func formatSize(v int64) string {
19 panic("unreachable")
20 }
21
22+func BuildVersion() (string, bool) {
23+ if bi, ok := debug.ReadBuildInfo(); ok {
24+ return bi.Main.Version, true
25+ } else {
26+ return "", false
27+ }
28+}
29+
30 type ReadProgress struct {
31 io.Reader
32 period time.Duration
+11,
-0
1@@ -20,13 +20,24 @@ func main() {
2 var configPath string
3 var nickname string
4 var debug bool
5+ var version bool
6 flag.StringVar(&configPath, "config", "", "path to the configuration file")
7 flag.StringVar(&nickname, "nickname", "", "nick name/display name to use")
8 flag.BoolVar(&debug, "debug", false, "show raw protocol data in the home buffer")
9+ flag.BoolVar(&version, "version", false, "show version info")
10 flag.Parse()
11
12 rand.Seed(time.Now().UnixNano())
13
14+ if version {
15+ if v, ok := senpai.BuildVersion(); ok {
16+ fmt.Printf("senpai version %v\n", v)
17+ } else {
18+ fmt.Printf("senpai (unknown version)\n")
19+ }
20+ return
21+ }
22+
23 if configPath == "" {
24 configDir, err := os.UserConfigDir()
25 if err != nil {
+3,
-0
1@@ -20,6 +20,9 @@ senpai - your everyday IRC student
2 *-debug*
3 Advanced. Show all IRC messages that are received from/sent to the server.
4
5+*-version*
6+ Display version info.
7+
8 # DESCRIPTION
9
10 senpai is an IRC client made for bouncers. It supports the newest IRC
+5,
-3
1@@ -9,13 +9,15 @@ import (
2 "git.sr.ht/~delthas/senpai/ui"
3 )
4
5-const welcomeMessage = "Welcome to senpai! To get started, use the Help buttons, or enter /help for a list of commands."
6-
7 func (app *App) initWindow() {
8+ version, ok := BuildVersion()
9+ if !ok {
10+ version = "(unknown version)"
11+ }
12 app.win.AddBuffer("", "(home)", "")
13 app.win.AddLine("", "", ui.Line{
14 Head: "--",
15- Body: ui.PlainString(welcomeMessage),
16+ Body: ui.PlainString(fmt.Sprintf("Welcome to senpai %v! To get started, use the Help buttons, or enter /help for a list of commands.", version)),
17 At: time.Now(),
18 })
19 }