Skip to content

Commit

Permalink
fix: -V flag (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmzane authored Feb 3, 2023
1 parent 2956428 commit fd5338f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ builds:
- CGO_ENABLED=0
flags:
- -trimpath
ldflags:
- -s -w -X main.version={{.Version}}
targets:
- darwin_amd64
- darwin_arm64
Expand Down
21 changes: 20 additions & 1 deletion cmd/musttag/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
package main

import (
"golang.org/x/tools/go/analysis/singlechecker"
"flag"
"fmt"
"os"
"runtime"

"github.com/junk1tm/musttag"
"golang.org/x/tools/go/analysis/singlechecker"
)

var version = "dev" // injected at build time.

func main() {
// override the builtin -V flag.
flag.Var(versionFlag{}, "V", "print version and exit")
singlechecker.Main(musttag.New())
}

type versionFlag struct{}

func (versionFlag) IsBoolFlag() bool { return true }
func (versionFlag) Get() interface{} { return nil }
func (versionFlag) String() string { return "" }
func (versionFlag) Set(string) error {
fmt.Printf("musttag version %s %s/%s\n", version, runtime.GOOS, runtime.GOARCH)
os.Exit(0)
return nil
}

0 comments on commit fd5338f

Please sign in to comment.