-
Notifications
You must be signed in to change notification settings - Fork 2
/
json2nd.go
66 lines (53 loc) · 874 Bytes
/
json2nd.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
package main
import (
"flag"
"fmt"
"os"
"runtime/debug"
"github.com/draxil/json2nd/internal/options"
)
var version = ""
func main() {
oh, err := options.New(os.Args[1:])
if err != nil {
if err == flag.ErrHelp {
os.Exit(0)
}
bail(err)
}
args := oh.Args()
opts := oh.Options
if opts.JustPrintVersion {
justPrintVersion()
}
if len(args) > 0 {
err := filemode(args, os.Stdout, opts)
bailIfError(err)
return
}
err = processor{os.Stdin, os.Stdout, opts, true}.run()
bailIfError(err)
}
func bailIfError(e error) {
if e == nil {
return
}
bail(e)
}
func bail(e error) {
fmt.Fprintln(os.Stderr, e)
os.Exit(1)
}
func justPrintVersion() {
if version != "" {
fmt.Println(version)
} else {
info, ok := debug.ReadBuildInfo()
if ok {
fmt.Println(info.Main.Version)
} else {
fmt.Println("don't know")
}
}
os.Exit(0)
}