show version

This commit is contained in:
Timon Ringwald 2022-08-29 13:45:28 +02:00
parent 75dce36679
commit e7a2a65eb6
3 changed files with 16 additions and 1 deletions

6
go.mod
View File

@ -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

2
go.sum
View File

@ -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=

View File

@ -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)