Skip to content

Commit 43501cc

Browse files
committed
add version command
1 parent 57492d5 commit 43501cc

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

.goreleaser.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ builds:
1818
- 6
1919
- 7
2020
main: ./cmd/aws-fuzzy/main.go
21+
ldflags:
22+
- -X github.com/AndreZiviani/aws-fuzzy/internal/version.versionTag={{.Version}}
2123
- id: "windows"
2224
env:
2325
- CGO_ENABLED=0
@@ -26,6 +28,8 @@ builds:
2628
goarch:
2729
- amd64
2830
main: ./cmd/aws-fuzzy/main.go
31+
ldflags:
32+
- -X github.com/AndreZiviani/aws-fuzzy/internal/version.versionTag={{.Version}}
2933
- id: "macos"
3034
env:
3135
- CGO_ENABLED=1
@@ -35,6 +39,8 @@ builds:
3539
- amd64
3640
- arm64
3741
main: ./cmd/aws-fuzzy/main.go
42+
ldflags:
43+
- -X github.com/AndreZiviani/aws-fuzzy/internal/version.versionTag={{.Version}}
3844
archives:
3945
- format: binary
4046
checksum:

internal/cli/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/AndreZiviani/aws-fuzzy/internal/ssh"
77
"github.com/AndreZiviani/aws-fuzzy/internal/ssm"
88
"github.com/AndreZiviani/aws-fuzzy/internal/sso"
9+
"github.com/AndreZiviani/aws-fuzzy/internal/version"
910
flags "github.com/jessevdk/go-flags"
1011
)
1112

@@ -19,5 +20,6 @@ func Run() {
1920
chart.Init(Parser)
2021
sso.Init(Parser)
2122
ssm.Init(Parser)
23+
version.Init(Parser)
2224
Parser.Parse()
2325
}

internal/version/main.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package version
2+
3+
import (
4+
flags "github.com/jessevdk/go-flags"
5+
)
6+
7+
type Version struct {
8+
}
9+
10+
var (
11+
versionTag string
12+
version Version
13+
)
14+
15+
func Init(parser *flags.Parser) {
16+
_, err := parser.AddCommand(
17+
"version",
18+
"Show aws-fuzzy version",
19+
"Show aws-fuzzy version",
20+
&version)
21+
22+
if err != nil {
23+
return
24+
}
25+
}

internal/version/version.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package version
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
func (p *Version) Execute(args []string) error {
8+
if len(versionTag) > 0 {
9+
fmt.Printf("aws-fuzzy %s\n", versionTag)
10+
} else {
11+
fmt.Printf("Unknown version, manually compiled from git?\n")
12+
}
13+
return nil
14+
}

0 commit comments

Comments
 (0)