package bootstrap import ( "fmt" "os" "path" "github.com/spf13/cobra" "gitter.top/coco/bootstrap/template" ) func CreateProject() *cobra.Command { var name, output string cmd := &cobra.Command{ Use: "new", Short: "create new project", PreRun: func(cmd *cobra.Command, args []string) { if name != "" { return } if len(args) == 1 { name = args[0] return } name = "DemoProject" }, Run: func(cmd *cobra.Command, args []string) { b := &template.Builder{ Path: output, Name: name, } b.Path = path.Join(output, b.Name) if err := b.Build(); err != nil { _, _ = fmt.Fprint(os.Stderr, err) os.Exit(1) } }, } cmd.Flags().StringVar(&name, "name", "", "project name") cmd.Flags().StringVar(&output, "path", ".", "project path") return cmd }