Skip to content

Commit 4784595

Browse files
committed
feat: add version flag to CLI
1 parent 1c064a2 commit 4784595

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

internal/cli/root.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ package cli
22

33
import (
44
"github.com/spf13/cobra"
5+
6+
"github.com/kernelshard/expose/internal/version"
57
)
68

79
var rootCmd = &cobra.Command{
8-
Use: "expose",
9-
Short: "Expose localhost to the internet",
10-
Long: "Minimal CLI to expose your local dev server",
10+
Use: "expose",
11+
Short: "Expose localhost to the internet",
12+
Long: "Minimal CLI to expose your local dev server",
13+
Version: version.GetFullVersion(),
1114
}
1215

1316
func Execute() error {

internal/version/version.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package version
2+
3+
var (
4+
Version = "v0.1.1"
5+
GitCommit = "1c064a2"
6+
BuildDate = "2025-11-07"
7+
)
8+
9+
// GetVersion returns just the version string
10+
func GetVersion() string {
11+
if Version == "dev" {
12+
return "dev (unreleased)"
13+
}
14+
return Version
15+
}
16+
17+
// GetFullVersion returns version with build metadata (for Cobra)
18+
// Note: Cobra automatically prefixes with "expose version"
19+
func GetFullVersion() string {
20+
return GetVersion() + " (commit: " + GitCommit + ", built: " + BuildDate + ")"
21+
}

internal/version/version_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package version
2+
3+
import (
4+
"strings"
5+
"testing"
6+
)
7+
8+
func TestGetVersion(t *testing.T) {
9+
v := GetVersion()
10+
if !strings.Contains(v, Version) {
11+
t.Errorf("GetVersion mismatch expected %s in:%s", Version, v)
12+
}
13+
}
14+
15+
func TestGetFullVersion(t *testing.T) {
16+
fullVersion := GetFullVersion()
17+
if !strings.Contains(fullVersion, GitCommit) {
18+
t.Errorf("GetFullVersion call expected %s in %s", GitCommit, fullVersion)
19+
}
20+
if !strings.Contains(fullVersion, BuildDate) {
21+
t.Errorf("GetFullVersion call expected %s in %s", BuildDate, fullVersion)
22+
}
23+
}

0 commit comments

Comments
 (0)