Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cmd/grepturbo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ import (
const defaultIndexDir = ".grepturbo"

func main() {
// If the first arg isn't a known subcommand or flag, treat it as a search pattern
// so `grepturbo <pattern>` works alongside `grepturbo search <pattern>`.
knownSubcmds := map[string]bool{"build": true, "search": true, "init": true, "help": true, "completion": true}
if len(os.Args) > 1 {
first := os.Args[1]
if first != "" && first[0] != '-' && !knownSubcmds[first] {
// Inject "search" before the pattern
newArgs := make([]string, 0, len(os.Args)+1)
newArgs = append(newArgs, os.Args[0], "search")
newArgs = append(newArgs, os.Args[1:]...)
os.Args = newArgs
}
}

rootCmd := &cobra.Command{
Use: "grepturbo",
Short: "Index-accelerated regex search",
Expand Down
Loading