-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
73 lines (61 loc) · 1.46 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
69
70
71
72
73
package main
import (
"fmt"
"os"
"github.com/alecthomas/kingpin"
"github.com/pkg/errors"
)
type GlobalConfig struct {
Debug bool
InFilename string
OutFilename string
OutFormat string
}
func ConfigureGlobals(app *kingpin.Application) (*GlobalConfig, error) {
cfg := &GlobalConfig{}
app.Flag("debug", "Enable debug mode.").
Short('d').
BoolVar(&cfg.Debug)
app.Flag("in", "Filename to read from").
Short('i').
Default("-").
StringVar(&cfg.InFilename)
app.Flag("out", "Filename to write to").
Short('o').
Default("-").
StringVar(&cfg.OutFilename)
return cfg, nil
}
func configureApp(app *kingpin.Application) error {
var err error
var globals *GlobalConfig
globals, err = ConfigureGlobals(app)
if err != nil {
return errors.Wrap(err, "unable to configure globals")
}
if err := ConfigureParseCommand(app, globals); err != nil {
return errors.Wrap(err, "unable to configure parse command")
}
return nil
}
var version = "master"
func main() {
app := kingpin.New("cfgt", "A configuration file translation utility")
app.Author("Joyent, Inc.")
app.Version(version)
if err := configureApp(app); err != nil {
type stackTracer interface {
StackTrace() errors.StackTrace
}
switch origErr := err.(type) {
case stackTracer:
fmt.Printf("Bad: %v\n", origErr)
for _, f := range origErr.StackTrace() {
fmt.Printf("%+v\n", f)
}
default:
fmt.Printf("Bad: %v\n", err)
}
}
kingpin.MustParse(app.Parse(os.Args[1:]))
}