-
Notifications
You must be signed in to change notification settings - Fork 90
/
list.go
49 lines (38 loc) · 930 Bytes
/
list.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
package main
import (
"fmt"
"text/template"
"github.com/clipperhouse/typewriter"
)
func list(c config) error {
imports := typewriter.NewImportSpecSet(
typewriter.ImportSpec{Path: "fmt"},
typewriter.ImportSpec{Path: "os"},
typewriter.ImportSpec{Path: "github.com/clipperhouse/typewriter"},
)
listFunc := func(c config) error {
app, err := typewriter.NewApp("+gen")
if err != nil {
return err
}
fmt.Fprintln(c.out, "Installed typewriters:")
for _, tw := range app.TypeWriters {
fmt.Fprintf(c.out, " %s\n", tw.Name())
}
return nil
}
return execute(listFunc, c, imports, listTmpl)
}
var listTmpl = template.Must(template.New("list").Parse(`
func main() {
app, err := typewriter.NewApp("+gen")
if err != nil {
os.Stderr.WriteString(err.Error() + "\n")
os.Exit(1)
}
fmt.Println("Imported typewriters:")
for _, tw := range app.TypeWriters {
fmt.Println(" " + tw.Name())
}
}
`))