-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}, | ||
}) | ||
} |