51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package cmd
|
|
|
|
import (
|
|
"github.com/jasonross/text-shark/internal/runner"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var (
|
|
findType string
|
|
findGlob string
|
|
findFixed bool
|
|
findIgnoreCase bool
|
|
)
|
|
|
|
var findCmd = &cobra.Command{
|
|
Use: "find <pattern> [path]",
|
|
Short: "Search for a pattern in files (wraps rg)",
|
|
Args: cobra.RangeArgs(1, 2),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
pattern := args[0]
|
|
path := "."
|
|
if len(args) == 2 {
|
|
path = args[1]
|
|
}
|
|
|
|
rgArgs := []string{}
|
|
if findIgnoreCase {
|
|
rgArgs = append(rgArgs, "-i")
|
|
}
|
|
if findFixed {
|
|
rgArgs = append(rgArgs, "-F")
|
|
}
|
|
if findType != "" {
|
|
rgArgs = append(rgArgs, "--type", findType)
|
|
}
|
|
if findGlob != "" {
|
|
rgArgs = append(rgArgs, "--glob", findGlob)
|
|
}
|
|
rgArgs = append(rgArgs, pattern, path)
|
|
|
|
return runner.RgStream(rgArgs...)
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
findCmd.Flags().StringVarP(&findType, "type", "t", "", "File type filter (e.g. go, py, js)")
|
|
findCmd.Flags().StringVarP(&findGlob, "glob", "g", "", "Glob pattern for file paths")
|
|
findCmd.Flags().BoolVarP(&findFixed, "fixed-strings", "F", false, "Treat pattern as a literal string")
|
|
findCmd.Flags().BoolVarP(&findIgnoreCase, "ignore-case", "i", false, "Case-insensitive search")
|
|
}
|