diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-13 02:31:32 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-13 02:31:32 +0200 |
| commit | 26c94eb3db62ec6eebbf8d22c11afe691d9520c4 (patch) | |
| tree | 165e5bf69234b4f96c9b74deb4898d7143ddf120 /cmd/krino/main.go | |
| parent | a6e442a645902011b2081c216daaec052cdc6ce6 (diff) | |
| download | krino-0.0.1.tar.gz krino-0.0.1.zip | |
krino: release 0.0.1 — man pages, install, examples, cross and release, README, changelogv0.0.1
Also: undo removes the directories its run created; a hardlink is never a
duplicate of its own other name; a flag written before "undo" is honoured;
--version prints no leading v. Duplicate conditions with different scopes
not sharing an original is documented as a known limitation.
Diffstat (limited to 'cmd/krino/main.go')
| -rw-r--r-- | cmd/krino/main.go | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/cmd/krino/main.go b/cmd/krino/main.go index e204b5f..f5fdfea 100644 --- a/cmd/krino/main.go +++ b/cmd/krino/main.go @@ -9,12 +9,32 @@ import ( "fmt" "io" "os" + "runtime/debug" "strings" ) // version is stamped by the Makefile with -ldflags "-X main.version=...". var version = "dev" +// displayVersion returns the version to print for --version. The Makefile +// stamps a git tag, which carries a leading "v" (required for +// go install ...@v0.0.1, per design.md §14); that "v" belongs on the tag, +// not in the output, so it is stripped here. A "go install" build carries no +// ldflags, leaving version at its built-in "dev"; in that case fall back to +// the build info Go embeds automatically. +func displayVersion() string { + v := version + if v == "dev" { + if info, ok := debug.ReadBuildInfo(); ok && info.Main.Version != "" && info.Main.Version != "(devel)" { + v = info.Main.Version + } + } + if len(v) > 1 && v[0] == 'v' && v[1] >= '0' && v[1] <= '9' { + v = v[1:] + } + return v +} + const usage = `usage: krino [-y | -n] [-v] [--json] [-c FILE] [NAME...] krino init krino new NAME PATH @@ -63,7 +83,7 @@ func run(args []string, stdout, stderr io.Writer) int { return code } if *showVersion { - fmt.Fprintf(stdout, "krino %s\n", version) + fmt.Fprintf(stdout, "krino %s\n", displayVersion()) return 0 } rest := fs.Args() |
