forked from tcnksm/gcli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
framework.go
133 lines (117 loc) · 3.88 KB
/
framework.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package skeleton
import "fmt"
// Framework represents framework
type Framework struct {
// Name is framework name
Name string
// AltName is alternative name which represent Framework
AltNames []string
// Description is description of framework
Description string
// URL is framework project URL
URL string
// BaseTemplates
BaseTemplates []Template
// CommandTemplate
CommandTemplates []Template
// If Hide is true, `list` command doesn't show
// this framework
Hide bool
}
// CommonTemplates is collection of templates which are used all frameworks.
var CommonTemplates = []Template{
{"resource/tmpl/common/CHANGELOG.md.tmpl", "CHANGELOG.md"},
{"resource/tmpl/common/README.md.tmpl", "README.md"},
{"resource/tmpl/common/gitignore.tmpl", ".gitignore"},
}
// Frameworks is collection of Framework.
var Frameworks = []*Framework{
{
Name: "mitchellh_cli",
AltNames: []string{"mitchellh"},
URL: "https://github.com/mitchellh/cli",
Description: `mitchellh/cli cli is a library for implementing powerful command-line interfaces in Go.
cli is the library that powers the CLI for Packer, Serf, and Consul.
`,
BaseTemplates: []Template{
{"resource/tmpl/mitchellh_cli/main.go.tmpl", "main.go"},
{"resource/tmpl/mitchellh_cli/version.go.tmpl", "version.go"},
{"resource/tmpl/mitchellh_cli/cli.go.tmpl", "cli.go"},
{"resource/tmpl/mitchellh_cli/commands.go.tmpl", "commands.go"},
{"resource/tmpl/mitchellh_cli/command/meta.go.tmpl", "command/meta.go"},
{"resource/tmpl/mitchellh_cli/command/version.go.tmpl", "command/version.go"},
},
CommandTemplates: []Template{
{"resource/tmpl/mitchellh_cli/command/command.go.tmpl", "command/{{ .Name }}.go"},
{"resource/tmpl/mitchellh_cli/command/command_test.go.tmpl", "command/{{ .Name }}_test.go"},
},
},
{
Name: "codegangsta_cli",
AltNames: []string{"codegangsta"},
URL: "https://github.com/codegangsta/cli",
Description: `codegangsta/cli is simple, fast, and fun package for building command line apps in Go.
The goal is to enable developers to write fast and distributable command line applications in an expressive way.
`,
BaseTemplates: []Template{
{"resource/tmpl/codegangsta_cli/main.go.tmpl", "main.go"},
{"resource/tmpl/codegangsta_cli/version.go.tmpl", "version.go"},
{"resource/tmpl/codegangsta_cli/commands.go.tmpl", "commands.go"},
},
CommandTemplates: []Template{
{"resource/tmpl/codegangsta_cli/command/command.go.tmpl", "command/{{ .Name }}.go"},
{"resource/tmpl/codegangsta_cli/command/command_test.go.tmpl", "command/{{ .Name }}_test.go"},
},
},
{
Name: "go_cmd",
URL: "https://github.com/golang/go/tree/master/src/cmd/go",
Description: `
`,
BaseTemplates: []Template{
{"resource/tmpl/go_cmd/main.go.tmpl", "main.go"},
},
CommandTemplates: []Template{
{"resource/tmpl/go_cmd/command.go.tmpl", "{{ .Name }}.go"},
{"resource/tmpl/go_cmd/command_test.go.tmpl", "{{ .Name }}_test.go"},
},
},
{
Name: "bash",
URL: "",
Description: `
`,
BaseTemplates: []Template{
{"resource/tmpl/bash/main.sh.tmpl", "{{ .Name }}.sh"},
},
CommandTemplates: []Template{},
Hide: true,
},
{
Name: "flag",
AltNames: []string{},
URL: "https://golang.org/pkg/flag/",
Description: `Package flag implements command-line flag parsing.`,
BaseTemplates: []Template{
{"resource/tmpl/flag/main.go.tmpl", "main.go"},
{"resource/tmpl/flag/version.go.tmpl", "version.go"},
{"resource/tmpl/flag/cli.go.tmpl", "cli.go"},
{"resource/tmpl/flag/cli_test.go.tmpl", "cli_test.go"},
},
CommandTemplates: []Template{},
},
}
// FrameworkByName retuns Framework
func FrameworkByName(name string) (*Framework, error) {
for _, f := range Frameworks {
if f.Name == name {
return f, nil
}
for _, alt := range f.AltNames {
if alt == name {
return f, nil
}
}
}
return nil, fmt.Errorf("invalid framework name: %s", name)
}