func walkDir(dir string, recursive bool, filter *regexp.Regexp, limitOne bool) (generated bool) { files, err := ioutil.ReadDir(dir) if err != nil { return } for _, file := range files { if strings.HasPrefix(file.Name(), ".") { continue } path := filepath.Join(dir, file.Name()) if file.IsDir() { if recursive { generated = walkDir(path, recursive, filter, limitOne) || generated if generated && limitOne { return } } continue } if !strings.HasSuffix(path, ".go") { continue } p := mockery.NewParser() err = p.Parse(path) if err != nil { continue } for _, iface := range p.Interfaces() { if !filter.MatchString(iface.Name) { continue } genMock(iface) generated = true if limitOne { return } } } return }
func mockFor(name string) { if name == "" { fmt.Fprintf(os.Stderr, "Use -name to specify the name of the interface\n") os.Exit(1) } parser := mockery.NewParser() ret := checkDir(parser, *fDir, name) if !ret { fmt.Printf("Unable to find %s in any go files under this path\n", name) os.Exit(1) } iface, err := parser.Find(name) if err != nil { fmt.Printf("Error finding %s: %s\n", name, err) os.Exit(1) } genMock(iface) }
func walkDir(dir string) { files, err := ioutil.ReadDir(dir) if err != nil { return } for _, file := range files { if strings.HasPrefix(file.Name(), ".") { continue } path := filepath.Join(dir, file.Name()) if file.IsDir() { if *fAll { walkDir(path) } continue } if !strings.HasSuffix(path, ".go") { continue } p := mockery.NewParser() err = p.Parse(path) if err != nil { continue } for _, iface := range p.Interfaces() { genMock(iface) } } return }