Skip to content

Commit

Permalink
add "wrench version" command
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
  • Loading branch information
emidoots committed Oct 4, 2024
1 parent 5ef56f3 commit 185ef60
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <command> -h" for more information about a command.
`
Expand Down
47 changes: 47 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -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)
},
})
}

0 comments on commit 185ef60

Please sign in to comment.