From 185ef60a35eb2b75cb5edbb9219d28575c4ff405 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Fri, 4 Oct 2024 10:06:39 -0700 Subject: [PATCH] add "wrench version" command Signed-off-by: Stephen Gutekanst --- main.go | 1 + version.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 version.go diff --git a/main.go b/main.go index 1afe902..2f704c9 100644 --- a/main.go +++ b/main.go @@ -24,6 +24,7 @@ The commands are: runners (remote) list registered runners secret (remote) manage secrets git manage local git repositories + version print the wrench version Use "wrench -h" for more information about a command. ` diff --git a/version.go b/version.go new file mode 100644 index 0000000..2ee99f6 --- /dev/null +++ b/version.go @@ -0,0 +1,47 @@ +package main + +import ( + "flag" + "fmt" + + "github.com/hexops/cmder" + "github.com/hexops/wrench/internal/errors" + "github.com/hexops/wrench/internal/wrench" +) + +func init() { + usage := `wrench version: print the wrench version + +Usage: + + wrench version + +` + + // Parse flags for our subcommand. + flagSet := flag.NewFlagSet("version", flag.ExitOnError) + + // Handles calls to our subcommand. + handler := func(args []string) error { + _ = flagSet.Parse(args) + if len(args) != 0 { + return &cmder.UsageError{Err: errors.New("expected no arguments")} + } + + fmt.Println("wrench version", wrench.Version, "built using", wrench.GoVersion) + + return nil + } + + // Register the command. + commands = append(commands, &cmder.Command{ + FlagSet: flagSet, + Aliases: []string{}, + Handler: handler, + UsageFunc: func() { + fmt.Fprintf(flag.CommandLine.Output(), "Usage of 'wrench %s':\n", flagSet.Name()) + flagSet.PrintDefaults() + fmt.Printf("%s", usage) + }, + }) +}