27 lines
643 B
Go
27 lines
643 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
|
|
"g.fc.run/ai/byre/internal/grep"
|
|
)
|
|
|
|
func grepCmd(args []string) {
|
|
fs := flag.NewFlagSet("grep", flag.ExitOnError)
|
|
opts := grep.Options{}
|
|
fs.StringVar(&opts.Glob, "glob", "", "search only files whose names match this glob")
|
|
fs.BoolVar(&opts.IgnoreCase, "ignore-case", false, "match case-insensitively")
|
|
fs.BoolVar(&opts.FilesOnly, "files-only", false, "list matching files, not lines")
|
|
fs.Parse(args)
|
|
if fs.NArg() != 2 {
|
|
usage()
|
|
}
|
|
out, err := grep.Search(context.Background(), fs.Arg(0), "", fs.Arg(1), opts)
|
|
if err != nil {
|
|
fatal("grep failed", "err", err)
|
|
}
|
|
fmt.Print(out)
|
|
}
|