addcmd

package
v0.0.0-...-c75f131 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CmdAdd = &cobra.Command{
	Use:   "add",
	Short: "Add proto, dockerfile or makefile",
	Long:  "Add proto, dockerfile or makefile",
}
View Source
var CmdAddApi = &cobra.Command{
	Use:     "api",
	Short:   "Add proto api file",
	Long:    "Add proto api file",
	Example: "mangokit add api api/helloworld/v1/proto hello.proto",
	Run: func(cmd *cobra.Command, args []string) {
		dir, name := cmdFunc(args)
		GenerateProtoFile(dir, name, ProtoApiContent)
	},
}
View Source
var CmdAddDockerfile = &cobra.Command{
	Use:   "dockerfile",
	Short: "Generate dockerfile",
	Long:  "Generate dockerfile",
	Run: func(cmd *cobra.Command, args []string) {
		_, err := os.Stat("Dockerfile")
		if err == nil {
			color.Yellow("Dockerfile is already exist!\n")
			return
		}

		if err = os.WriteFile("Dockerfile", []byte(dockerfileContent), 0666); err != nil {
			color.Red("generate Dockerfile error, %v\n", err)
			return
		}

		color.Green("Dockerfile added!")
	},
}
View Source
var CmdAddError = &cobra.Command{
	Use:     "error",
	Short:   "Add proto error file",
	Long:    "Add proto error file",
	Example: "mangokit add api api/helloworld/v1/proto errReason.proto",
	Run: func(cmd *cobra.Command, args []string) {
		dir, name := cmdFunc(args)
		GenerateProtoFile(dir, name, ProtoErrorContent)
	},
}
View Source
var CmdAddMakefile = &cobra.Command{
	Use:   "makefile",
	Short: "Generate makefile",
	Long:  "Generate makefile",
	Run: func(cmd *cobra.Command, args []string) {
		_, err := os.Stat("makefile")
		if err == nil {
			color.Yellow("makefile is already exist!\n")
			return
		}

		if err = os.WriteFile("makefile", []byte(makefileContent), 0666); err != nil {
			color.Red("generate makefile error, %v\n", err)
			return
		}

		color.Green("makefile added!")
	},
}
View Source
var ProtoApiContent string
View Source
var ProtoErrorContent string

Functions

func GenerateProtoFile

func GenerateProtoFile(dir, name string, content string) error

Types

type TemplateInfo

type TemplateInfo struct {
	Package  string
	Name     string
	FileName string
}

Jump to

Keyboard shortcuts

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