From 051f2df33fdca439eae345cd23bd4038b3f7ebb5 Mon Sep 17 00:00:00 2001 From: borisyang Date: Mon, 14 Jun 2021 10:31:10 +0800 Subject: [PATCH] report wire build version --- cmd/wire/main.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/cmd/wire/main.go b/cmd/wire/main.go index fa37e51d..47505173 100644 --- a/cmd/wire/main.go +++ b/cmd/wire/main.go @@ -27,6 +27,7 @@ import ( "log" "os" "reflect" + "runtime" "sort" "strconv" "strings" @@ -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(), "") @@ -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. @@ -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]] { @@ -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 +}