Skip to content

Commit

Permalink
feat: Add version flag support
Browse files Browse the repository at this point in the history
  • Loading branch information
taichimaeda committed Nov 24, 2023
1 parent 24cad00 commit 62ed91f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cmd/wireplus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ import (
"golang.org/x/tools/go/types/typeutil"
)

const Version = "v0.1.5"

func main() {
// Register the subcommands.
subcommands.Register(subcommands.CommandsCommand(), "")
subcommands.Register(subcommands.FlagsCommand(), "")
subcommands.Register(subcommands.HelpCommand(), "")
Expand All @@ -54,13 +57,25 @@ func main() {
subcommands.Register(&detailCmd{}, "")
subcommands.Register(&graphCmd{}, "")
subcommands.Register(&lspCmd{}, "")

// Register a flag to print the version.
var version bool
flag.CommandLine.BoolVar(&version, "version", false, "print the version and exit")

// Parse the command-line flags.
flag.Parse()

// Initialize the default logger to log to stderr.
log.SetFlags(0)
log.SetPrefix("wire: ")
log.SetPrefix("wireplus: ")
log.SetOutput(os.Stderr)

// Print the version and exit if version flag is set.
if version {
log.Println(Version)
os.Exit(0)
}

// TODO(rvangent): Use subcommands's VisitCommands instead of hardcoded map,
// once there is a release that contains it:
// allCmds := map[string]bool{}
Expand Down

0 comments on commit 62ed91f

Please sign in to comment.