Skip to content

Commit

Permalink
report wire build version
Browse files Browse the repository at this point in the history
  • Loading branch information
muyizixiu committed Jun 14, 2021
1 parent d07cde0 commit 669511a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions cmd/wire/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"log"
"os"
"reflect"
"runtime"
"sort"
"strconv"
"strings"
Expand All @@ -37,6 +38,8 @@ import (
"golang.org/x/tools/go/types/typeutil"
)

const buildVersion = "0.5.0"

func main() {
subcommands.Register(subcommands.CommandsCommand(), "")
subcommands.Register(subcommands.FlagsCommand(), "")
Expand All @@ -45,6 +48,7 @@ func main() {
subcommands.Register(&diffCmd{}, "")
subcommands.Register(&genCmd{}, "")
subcommands.Register(&showCmd{}, "")
subcommands.Register(&versionCmd{}, "")
flag.Parse()

// Initialize the default logger to log to stderr.
Expand All @@ -64,6 +68,7 @@ func main() {
"diff": true,
"gen": true,
"show": true,
"version": true,
}
// Default to running the "gen" command.
if args := flag.Args(); len(args) == 0 || !allCmds[args[0]] {
Expand Down Expand Up @@ -607,3 +612,22 @@ func logErrors(errs []error) {
log.Println(strings.Replace(err.Error(), "\n", "\n\t", -1))
}
}

type versionCmd struct{}

func (*versionCmd) Name() string { return "version" }
func (*versionCmd) Synopsis() string {
return "print Wire version"
}
func (*versionCmd) Usage() string {
return `version
Version prints the build information for Go executables.
`
}
func (cmd *versionCmd) SetFlags(f *flag.FlagSet) {}
func (cmd *versionCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus {
fmt.Printf("wire version %s %s/%s", buildVersion, runtime.GOOS, runtime.GOARCH)
return subcommands.ExitSuccess
}

0 comments on commit 669511a

Please sign in to comment.