Skip to content

Commit 497b70c

Browse files
committed
feat: Add version flag
Add version flag (-v, --version) that displays version and commit SHA. Add utility function to format version information for consistent display across the application.
1 parent 71c2e5b commit 497b70c

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

cmd/grab/main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/epilande/codegrab/internal/model"
1515
"github.com/epilande/codegrab/internal/ui"
1616
"github.com/epilande/codegrab/internal/ui/themes"
17+
"github.com/epilande/codegrab/internal/utils"
1718
)
1819

1920
type stringSliceFlag []string
@@ -32,6 +33,7 @@ func main() {
3233

3334
var globPatterns stringSliceFlag
3435
var showHelp bool
36+
var showVersion bool
3537
var nonInteractive bool
3638
var outputPath string
3739
var useTempFile bool
@@ -41,6 +43,9 @@ func main() {
4143
flag.BoolVar(&showHelp, "help", false, "Display help information")
4244
flag.BoolVar(&showHelp, "h", false, "Display help information (shorthand)")
4345

46+
flag.BoolVar(&showVersion, "version", false, "Display version information")
47+
flag.BoolVar(&showVersion, "v", false, "Display version information (shorthand)")
48+
4449
flag.BoolVar(&nonInteractive, "non-interactive", false, "Run in non-interactive mode")
4550
flag.BoolVar(&nonInteractive, "n", false, "Run in non-interactive mode (shorthand)")
4651

@@ -71,6 +76,11 @@ func main() {
7176
os.Exit(0)
7277
}
7378

79+
if showVersion {
80+
fmt.Println(utils.VersionInfo())
81+
os.Exit(0)
82+
}
83+
7484
if themeName != "" {
7585
if err := themes.SetTheme(themeName); err != nil {
7686
fmt.Fprintf(os.Stderr, "Warning: %v, using default theme\n", err)

internal/utils/version.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package utils
2+
3+
var (
4+
Version = "dev"
5+
CommitSHA = "unknown"
6+
)
7+
8+
func VersionInfo() string {
9+
return "grab " + Version + " (" + CommitSHA + ")"
10+
}

0 commit comments

Comments
 (0)