show version with branch and commit in help and -version

- add -version flag (besides --version and -V)
- help output includes the version
- commit and branch are set via ldflags by goreleaser; plain go build
  falls back to the VCS revision embedded by Go

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Florian WaltherandClaude Opus 5.5 committed 2026-10-03 19:38:48 +02:00
1 parent 03e791cbcd
commit f51680f83c
4 files changed
+79 -7

No files matched your search

+10
View File
@@ -2,6 +2,7 @@
```
gosh - Go Shell
Version: 0.2.1 (branch: main, commit: 03e791c)
Built-in commands:
cd [dir] - Change directory (cd with no args goes to home)
@@ -102,6 +103,15 @@ _gosh is not meant for production use, it is just a proof of concept._
go build ./
```
Die Version lässt sich mit `gosh -version` (oder `--version`, `-V`) abfragen und steht auch in der Ausgabe von `help`:
```
$ gosh -version
gosh 0.2.1 (branch: main, commit: 03e791c)
```
Version und Branch werden beim Bauen mit GoReleaser per `-ldflags` gesetzt. Bei einem einfachen `go build` steht dort `dev`, der Commit wird dann aus den von Go eingebetteten Git-Informationen gelesen (mit `-dirty`, falls es uncommittete Änderungen gab).
## Release
Binaries sowie `.deb`- und `.rpm`-Pakete werden mit [GoReleaser](https://goreleaser.com) gebaut (Konfiguration: `.goreleaser.yaml`).