/
skeleton.go
53 lines (41 loc) · 1.18 KB
/
skeleton.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
package cmd
import (
"github.com/devopsfaith/api2html/skeleton"
"github.com/spf13/cobra"
)
var (
outputPath string
skelCmd = &cobra.Command{
Use: "skel",
Short: "Executes commands to manage/create skeletons",
Aliases: []string{"skeleton"},
Example: "api2html skel",
}
createCmd = &cobra.Command{
Use: "create",
Short: "Creates a skeleton structure.",
Example: "api2html skel create -o outputPath <skelname>",
}
blogCmd = &cobra.Command{
Use: "blog",
Short: "Creates the blog skeleton example.",
RunE: skelWrapper{defaultBlogSkelFactory}.Create,
Example: "api2html skel create -o outputPath blog",
}
)
func init() {
rootCmd.AddCommand(skelCmd)
skelCmd.AddCommand(createCmd)
createCmd.AddCommand(blogCmd)
createCmd.PersistentFlags().StringVarP(&outputPath, "outputPath", "o", "example", "Output path for the example generation skel")
}
type skelFactory func(outputPath string) skeleton.Skel
func defaultBlogSkelFactory(outputPath string) skeleton.Skel {
return skeleton.NewBlog(outputPath)
}
type skelWrapper struct {
sk skelFactory
}
func (sw skelWrapper) Create(_ *cobra.Command, _ []string) error {
return sw.sk(outputPath).Create()
}