From e7a2a65eb6431eb732aa66846f132eedc0541ebb Mon Sep 17 00:00:00 2001 From: Timon Ringwald Date: Mon, 29 Aug 2022 13:45:28 +0200 Subject: [PATCH] show version --- go.mod | 6 +++++- go.sum | 2 ++ main.go | 9 +++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 21eec85..c638663 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,11 @@ module git.milar.in/milarin/format go 1.18 require ( - github.com/fatih/color v1.13.0 // indirect + git.milar.in/milarin/buildinfo v1.0.0 + github.com/fatih/color v1.13.0 +) + +require ( github.com/mattn/go-colorable v0.1.12 // indirect github.com/mattn/go-isatty v0.0.14 // indirect golang.org/x/sys v0.0.0-20220517195934-5e4e11fc645e // indirect diff --git a/go.sum b/go.sum index c970384..f6049c5 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +git.milar.in/milarin/buildinfo v1.0.0 h1:tw98GupUYl/0a/3aPGuezhE4wseycOSsbcLp70hy60U= +git.milar.in/milarin/buildinfo v1.0.0/go.mod h1:arI9ZoENOgcZcanv25k9y4dKDUhPp0buJrlVerGruas= github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= diff --git a/main.go b/main.go index 1d51fed..1494bcc 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,8 @@ import ( "strconv" "strings" "unicode/utf8" + + "git.milar.in/milarin/buildinfo" ) var ( @@ -45,6 +47,8 @@ var ( // it may be useful to have a boolean flag for this behavior lineParseAmount = flag.Int("n", 1, "amount of lines to feed into input pattern") + showVersion = flag.Bool("v", false, "show version and exit") + replacePattern = regexp.MustCompile(`\{(\d+)(?::(.*?))?(?::(.*?))?(?::(.*?))?\}`) numMutationPattern = regexp.MustCompile(`([+\-*/])(\d+|\((\d+)\))`) ) @@ -52,6 +56,11 @@ var ( func main() { flag.Parse() + if *showVersion { + buildinfo.Print(buildinfo.Options{}) + return + } + pattern, err := regexp.Compile(*input) if err != nil { panic(err)