generate

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 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
		}

		var matchedFiles []string

		for _, arg := range args {
			filesName, err := filepath.Glob(arg)
			cobra.CheckErr(err)

			if strings.HasSuffix(arg, ".go") {
				matchedFiles = append(matchedFiles, filesName...)
			}

			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