1
0
Fork 0
kifflom/main.go

58 lines
951 B
Go
Raw Normal View History

2015-02-18 16:06:15 +00:00
package main
import (
"flag"
"fmt"
"os"
"strings"
2015-02-23 13:07:19 +00:00
"github.com/davecheney/profile"
2015-02-26 11:02:50 +00:00
"github.com/localhots/kifflom/buffer"
"github.com/localhots/kifflom/parser"
2015-02-18 16:06:15 +00:00
)
func main() {
var (
sel string
verbose bool
2015-02-23 13:07:19 +00:00
prof string
2015-02-18 16:06:15 +00:00
)
2015-02-23 13:07:19 +00:00
2015-02-18 16:06:15 +00:00
flag.StringVar(&sel, "s", "", "Selector")
2015-02-23 13:07:19 +00:00
flag.StringVar(&prof, "prof", "", "Performance profiling output")
2015-02-18 16:06:15 +00:00
flag.BoolVar(&verbose, "v", false, "Verbose parsing")
flag.Parse()
if len(sel) == 0 && !verbose {
fmt.Println("No selectors given and parser is not verbose")
os.Exit(1)
}
2015-02-23 13:07:19 +00:00
if prof != "" {
defer profile.Start(&profile.Config{
CPUProfile: true,
ProfilePath: prof,
}).Stop()
}
2015-02-18 16:06:15 +00:00
sels := strings.Split(sel, " ")
if len(sel) == 0 {
sels = []string{}
}
2015-02-23 13:07:19 +00:00
buf := buffer.NewReaderBuffer(os.Stdin)
2015-02-18 16:06:15 +00:00
pars := parser.New(buf, sels)
if verbose {
pars.Debug()
}
2015-02-23 13:07:19 +00:00
2015-02-18 16:06:15 +00:00
res := pars.ParseStream()
for {
if m, ok := <-res; ok {
fmt.Println(m.Sel, m.Val)
} else {
break
}
}
}