-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
48 lines (41 loc) · 907 Bytes
/
main.go
File metadata and controls
48 lines (41 loc) · 907 Bytes
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
package main
import (
"flag"
"fmt"
"golang.org/x/crypto/ssh/terminal"
"io/ioutil"
"os"
)
var (
schema = flag.String("schema", "", "Avro schema to generate a message for, optionally pass this in as the 1st arg")
)
func main() {
checkArgs()
test := GenerateMessage(*schema)
fmt.Println(test)
}
func must(err error) {
if err != nil {
panic(err)
}
}
func checkArgs() {
flag.Parse()
if *schema == "" {
if !terminal.IsTerminal(0) {
bytes, err := ioutil.ReadAll(os.Stdin)
must(err)
*schema = string(bytes)
}
if *schema == "" {
printUsageErrorAndExit("You must provide a schema to generate messages for")
}
}
}
func printUsageErrorAndExit(format string, values ...interface{}) {
fmt.Fprintf(os.Stderr, "ERROR: %s\n", fmt.Sprintf(format, values...))
fmt.Fprintln(os.Stderr)
fmt.Fprintln(os.Stderr, "Available command line options:")
flag.PrintDefaults()
os.Exit(64)
}