Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Command = &cobra.Command{ Use: "mock", Short: "generate mock goner code for interface", RunE: func(cmd *cobra.Command, args []string) error { if scanDir == "" && scanFile == nil { return errors.New("scan file or scan directory, at least one must be specified") } if packageName == "" { return errors.New("package name is required") } if destinationDir == "" { destinationDir = path.Join(scanDir, packageName) } err := os.MkdirAll(destinationDir, os.ModePerm) if err != nil { return err } var mockedStructs []string var genCode = func(theFilepath string) error { if !strings.HasSuffix(theFilepath, "gone.go") && strings.HasSuffix(theFilepath, ".go") { code, err := GenMockCode(theFilepath, packageName) if err != nil { return err } filename := filepath.Base(theFilepath) newFilepath := path.Join(destinationDir, fmt.Sprintf("%s.gone.go", strings.TrimSuffix(filename, ".go"))) code = AddGoneCode(code) mocked := GetMockedInterface(code) mockedStructs = append(mockedStructs, mocked...) if len(mocked) > 0 { return os.WriteFile(newFilepath, []byte(code), 0644) } } return nil } if scanDir != "" { err = filepath.Walk(scanDir, func(theFilepath string, info os.FileInfo, err error) error { if err != nil { return err } if !info.IsDir() { return genCode(theFilepath) } return nil }) if err != nil { return err } } for _, f := range scanFile { err := genCode(f) if err != nil { return err } } priestCode := GenMockPriestCode(mockedStructs, packageName) return os.WriteFile(path.Join(destinationDir, "load.gone.go"), []byte(priestCode), 0644) }, }
Functions ¶
func AddGoneCode ¶
func GenMockPriestCode ¶
func GetMockedInterface ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.