Skip to content

Commit b5d6a4a

Browse files
committed
feat: add -version flag with build info
1 parent e708e71 commit b5d6a4a

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

.goreleaser.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ builds:
1616
- arm64
1717
ldflags: |
1818
-X main.Version={{.Version}}
19+
-X main.Commit={{.Commit}}
20+
-X main.Date={{.Date}}
1921
2022
archives:
2123
- name_template: >-

cmd/sshot/main.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,26 @@ package main
22

33
import (
44
"flag"
5+
"fmt"
56
"log"
67
"os"
8+
"runtime"
79

810
"github.com/fgouteroux/sshot/pkg/playbook"
911
"github.com/fgouteroux/sshot/pkg/types"
1012
)
1113

14+
// Build information set via ldflags
15+
var (
16+
Version = "dev"
17+
Commit = "none"
18+
Date = "unknown"
19+
)
20+
1221
var execOptions types.ExecutionOptions
1322

1423
func main() {
24+
version := flag.Bool("version", false, "Show version information")
1525
dryRun := flag.Bool("dry-run", false, "Run in dry-run mode (don't execute commands)")
1626
dryRunShort := flag.Bool("n", false, "Run in dry-run mode (shorthand)")
1727
verbose := flag.Bool("verbose", false, "Enable verbose logging")
@@ -25,6 +35,14 @@ func main() {
2535

2636
flag.Parse()
2737

38+
if *version {
39+
fmt.Printf("sshot %s\n", Version)
40+
fmt.Printf(" commit: %s\n", Commit)
41+
fmt.Printf(" built: %s\n", Date)
42+
fmt.Printf(" go: %s\n", runtime.Version())
43+
os.Exit(0)
44+
}
45+
2846
execOptions.DryRun = *dryRun || *dryRunShort
2947
execOptions.Verbose = *verbose || *verboseShort
3048
execOptions.Progress = *progress

0 commit comments

Comments
 (0)