generate

package
v1.9.24 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "enum",
	Short: "枚举生成器",
	Long:  `枚举生成器`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			return
		}

		matchedFiles := []string{}
		for _, v := range args {
			files, err := filepath.Glob(v)
			cobra.CheckErr(err)

			if strings.HasSuffix(v, ".go") {
				matchedFiles = append(matchedFiles, files...)
			}
		}

		if len(matchedFiles) == 0 {
			return
		}

		for _, path := range matchedFiles {

			code, err := enum.G.Generate(path)
			cobra.CheckErr(err)

			if len(code) == 0 {
				continue
			}

			var genFile = ""
			if strings.HasSuffix(path, ".pb.go") {
				genFile = strings.ReplaceAll(path, ".pb.go", "_enum.pb.go")
			} else {
				genFile = strings.ReplaceAll(path, ".go", "_enum.go")
			}

			err = os.WriteFile(genFile, code, 0644)
			cobra.CheckErr(err)
		}
	},
}

EnumCmd 枚举生成器

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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