32 lines
638 B
Go
32 lines
638 B
Go
|
package cmd
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"github.com/spf13/cobra"
|
||
|
"log"
|
||
|
"os"
|
||
|
)
|
||
|
|
||
|
var createCmd = &cobra.Command{
|
||
|
Use: "create",
|
||
|
Short: "创建一个新项目",
|
||
|
Long: `通过hertz_demo为模板创建一个新项目`,
|
||
|
Run: func(cmd *cobra.Command, args []string) {
|
||
|
handleCreateCommand(args)
|
||
|
},
|
||
|
}
|
||
|
|
||
|
func init() {
|
||
|
createCmd.Flags().StringVarP(&project, "project", "p", "", "项目名称")
|
||
|
}
|
||
|
|
||
|
func handleCreateCommand(args []string) {
|
||
|
err := handleRemoteTemplate(template, branch, project)
|
||
|
if err != nil {
|
||
|
log.Printf("Error creating project: %s\n", err)
|
||
|
os.Exit(1)
|
||
|
}
|
||
|
fmt.Printf("Project %s created successfully!\n", project)
|
||
|
return
|
||
|
}
|