func main() { var g regexp.Grep g.AddFlags() g.Stdout = os.Stdout g.Stderr = os.Stderr flag.Usage = usage flag.Parse() args := flag.Args() if len(args) == 0 { flag.Usage() } pat := "(?m)" + args[0] if *iflag { pat = "(?i)" + pat } re, err := regexp.Compile(pat) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } g.Regexp = re if len(args) == 1 { g.Reader(os.Stdin, "stdin") } else { for _, arg := range args[1:] { g.File(arg) } } if !g.Match { os.Exit(1) } }
func main() { var g regexp.Grep g.AddFlags() g.Stdout = os.Stdout g.Stderr = os.Stderr flag.Usage = usage flag.Parse() args := flag.Args() if len(args) == 0 { flag.Usage() } if *cpuProfile != "" { f, err := os.Create(*cpuProfile) if err != nil { log.Fatal(err) } defer f.Close() pprof.StartCPUProfile(f) defer pprof.StopCPUProfile() } pat := "(?m)" + args[0] if *iflag { pat = "(?i)" + pat } re, err := regexp.Compile(pat) if err != nil { log.Fatal(err) } g.Regexp = re if len(args) == 1 { g.Reader(os.Stdin, "<standard input>") } else { for _, arg := range args[1:] { g.File(arg) } } if !g.Match { os.Exit(1) } }
func main() { var g regexp.Grep g.AddFlags() g.Stdout = os.Stdout g.Stderr = os.Stderr flag.Usage = usage flag.Parse() args := flag.Args() if len(args) == 0 { flag.Usage() } pat := "(?m)" + strings.Join(args, ".*") if *iflag { pat = "(?i)" + pat } re, err := regexp.Compile(pat) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } g.Regexp = re walker := fs.Walk(".") for walker.Step() { if walker.Stat().IsDir() { if strings.Contains(walker.Path(), ".git") { walker.SkipDir() } continue } g.File(walker.Path()) } if err := walker.Err(); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } if !g.Match { os.Exit(1) } }