cmd

package
v0.0.0-...-22b531f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AddCmd = &cobra.Command{
	Use:     "add [component name]",
	Short:   "Add a component to the project",
	Example: "gomall add swagger",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) < 1 {
			fmt.Println("please enter component name")
			fmt.Println("See 'gomall help add'")
			return
		}
		module := args[0]

		switch module {
		case "swagger":
			if err := addSwagger(); err != nil {
				fmt.Println(err)
				return
			}
		}

	},
}
View Source
var InitCmd = &cobra.Command{
	Use:   "init [project name]",
	Short: "Create a new project",
	Args:  cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		projectName := args[0]
		fmt.Printf("Creating a new project: %s\n", projectName)
		initNewProject(projectName)
	},
}
View Source
var NewCmd = &cobra.Command{
	Use:   "new [module name]",
	Short: "Create a new module for the project",
	Args:  cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		moduleName := args[0]
		fmt.Printf("Creating a new module: %s\n", moduleName)

		internalPath := "internal"
		directories := []string{"router", "controllers", "services", "models"}

		for _, dir := range directories {
			err := os.MkdirAll(filepath.Join(internalPath, dir), os.ModePerm)
			if err != nil {
				fmt.Printf("Error creating directory: %v\n", err)
				return
			}
		}

		fileTempaltes := map[string]string{
			filepath.Join(internalPath, "models", moduleName+".go"):      tools.GetFile("web/template/model.tmpl"),
			filepath.Join(internalPath, "services", moduleName+".go"):    tools.GetFile("web/template/service.tmpl"),
			filepath.Join(internalPath, "controllers", moduleName+".go"): tools.GetFile("web/template/controller.tmpl"),
			filepath.Join(internalPath, "router", moduleName+".go"):      tools.GetFile("web/template/router.tmpl"),
		}

		for filePath, templateContent := range fileTempaltes {
			if _, err := os.Stat(filePath); os.IsNotExist(err) {
				err := tools.CreateFileByTmplContent(filePath, templateContent, moduleName)
				if err != nil {
					fmt.Printf("Error creating file: %v\n", err)
					return
				}
				fmt.Printf("File created: %s\n", filePath)
			} else {
				fmt.Printf("File already exists: %s\n", filePath)
			}
		}

	},
}
View Source
var (
	// host           string
	// port           int
	ServerStartCmd = &cobra.Command{
		Use:   "server",
		Short: `Start the server`,
		Run: func(cmd *cobra.Command, args []string) {
			start()
		},
	}
)
View Source
var VersionCmd = &cobra.Command{
	Use:     "version",
	Short:   "Get the version of Go-Gin-Boilerplate",
	Example: "gomall version",
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Printf(`Go-Gin-Boilerplate version: %v`, "v0.0.1")
	},
}

Functions

func Execute

func Execute(fs embed.FS)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL