@@ -5,12 +5,13 @@ import (
55 "fmt"
66 "log"
77 "os"
8+ "regexp"
89 "strings"
910
1011 "github.com/bbeardsley/histkeep"
1112)
1213
13- const version = "0.0.2 "
14+ const version = "0.0.3 "
1415
1516func printUsage () {
1617 fmt .Fprintln (os .Stderr , "Usage" )
@@ -31,6 +32,7 @@ func printUsage() {
3132
3233func main () {
3334 lastNPtr := flag .Int ("last" , 15 , "keep the last specified number of values" )
35+ formatPtr := flag .String ("format" , "" , "regex format for the values. Accepts NUMBER and UUID as shortcuts." )
3436 versionPtr := flag .Bool ("version" , false , "print version number and exit" )
3537
3638 flag .Parse ()
@@ -43,8 +45,7 @@ func main() {
4345 command := strings .TrimSpace (flag .Arg (0 ))
4446 file := strings .TrimSpace (flag .Arg (1 ))
4547 value := strings .TrimSpace (flag .Arg (2 ))
46-
47- hist := histkeep .NewHistKeep (file , * lastNPtr )
48+ hist := histkeep .NewHistKeep (file , * lastNPtr , buildFormat (* formatPtr ))
4849
4950 switch command {
5051 case "" , "h" , "-h" , "--h" , "/h" , "/?" , "help" , "-help" , "--help" , "/help" :
@@ -93,3 +94,24 @@ func main() {
9394
9495 return
9596}
97+
98+ func buildFormat (formatStr string ) * regexp.Regexp {
99+ format := processedNamedFormats (formatStr )
100+ regex , _ := regexp .Compile ("^" + format + "$" )
101+ return regex
102+ }
103+
104+ func processedNamedFormats (formatStr string ) string {
105+ var matched bool
106+ matched , _ = regexp .MatchString ("^NUMBER$" , formatStr )
107+ if matched {
108+ return "\\ d+"
109+ }
110+
111+ matched , _ = regexp .MatchString ("^UUID$" , formatStr )
112+ if matched {
113+ return "([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}){1}"
114+ }
115+
116+ return formatStr
117+ }
0 commit comments