-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (57 loc) · 1.33 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
package main
import (
"flag"
"log"
"os"
"sort"
"text/tabwriter"
"github.com/paulbes/makedoc/makedoc"
)
var targetVar string
var verboseVar bool
var colorVar bool
func init() {
flag.StringVar(&targetVar, "target", "", "only show documentation for given target")
flag.BoolVar(&verboseVar, "verbose", false, "show verbose output")
flag.BoolVar(&colorVar, "pretty", false, "make the output pretty")
flag.Parse()
}
func fail(msg string, args ...interface{}) {
logErr := log.New(os.Stderr, "", 0)
logErr.Printf(msg, args...)
os.Exit(1)
}
func main() {
files := flag.Args()
if len(files) == 0 {
fail("no makefiles provided for parsing")
}
docs, err := makedoc.Load(files)
if err != nil {
fail("failed to load makefiles: %s", err)
}
var targets []string
if len(targetVar) > 0 {
if _, hasKey := docs[targetVar]; !hasKey {
fail("target: %s, doesn't exist", targetVar)
}
targets = append(targets, targetVar)
} else {
for t := range docs {
targets = append(targets, t)
}
}
sort.Strings(targets)
w := new(tabwriter.Writer)
w.Init(os.Stdout, 0, 8, 2, '\t', tabwriter.AlignRight)
for _, t := range targets {
err = makedoc.Pretty(os.Stdout, docs[t], verboseVar, colorVar)
if err != nil {
fail("failed to format help: %s", err)
}
}
err = w.Flush()
if err != nil {
fail("failed to flush help: %s", err)
}
}