-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
main.go
68 lines (59 loc) · 1.55 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
This is a console application that prints Cucumber messages to
STDOUT.
*/
package main
import (
b64 "encoding/base64"
"encoding/json"
"flag"
"fmt"
gherkin "github.com/cucumber/gherkin/go/v28"
"github.com/cucumber/messages/go/v24"
"os"
)
var noSource = flag.Bool("no-source", false, "Skip gherkin source events")
var noAst = flag.Bool("no-ast", false, "Skip gherkin AST events")
var noPickles = flag.Bool("no-pickles", false, "Skip gherkin Pickle events")
var predictableIds = flag.Bool("predictable-ids", false, "Generate incrementing ids rather than UUIDs")
var versionFlag = flag.Bool("version", false, "print version")
var dialectsFlag = flag.Bool("dialects", false, "print dialects as JSON")
var defaultDialectFlag = flag.String("default-dialect", "en", "the default dialect")
// Set during build with -ldflags
var version = "(unknown version)"
var gherkinDialects string
func main() {
flag.Parse()
if *versionFlag {
fmt.Printf("gherkin %s\n", version)
os.Exit(0)
}
if *dialectsFlag {
sDec, _ := b64.StdEncoding.DecodeString(gherkinDialects)
fmt.Println(string(sDec))
os.Exit(0)
}
var newId func() string
if *predictableIds {
newId = (&messages.Incrementing{}).NewId
} else {
newId = messages.UUID{}.NewId
}
paths := flag.Args()
encoder := json.NewEncoder(os.Stdout)
decoder := json.NewDecoder(os.Stdin)
_, err := gherkin.Messages(
paths,
decoder,
*defaultDialectFlag,
!*noSource,
!*noAst,
!*noPickles,
encoder,
newId,
)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to parse Gherkin: %+v\n", err)
os.Exit(1)
}
}