generate

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "enum",
	Short: "枚举生成器",
	Long:  `枚举生成器`,
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) == 0 {
			return fmt.Errorf("input file is mandatory, see: -help")
		}

		matchedFiles := []string{}
		for _, v := range args {
			files, err := filepath.Glob(v)
			if err != nil {
				return err
			}

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

		if len(matchedFiles) == 0 {
			return fmt.Errorf("no file matched")
		}

		for _, path := range matchedFiles {

			code, err := enum.G.Generate(path)
			if err != nil {
				return 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)
			if err != nil {
				return err
			}
		}

		return nil
	},
}

Cmd 枚举生成器

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