-
Notifications
You must be signed in to change notification settings - Fork 3
/
version.go
47 lines (36 loc) · 951 Bytes
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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)
},
})
}