33 lines
677 B
Go
33 lines
677 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", "", "项目名称")
|
|
createCmd.MarkFlagRequired("project")
|
|
}
|
|
|
|
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
|
|
}
|