Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var GrepCmd = &cobra.Command{ Use: "grep <pattern>", Short: "Search CANARY tokens by pattern", Long: `Search for CANARY tokens matching a pattern. Searches across: - Feature names - File paths - Test names - Bench names - Requirement IDs The search is case-insensitive and matches substrings. Examples: canary grep User # Find all tokens related to "User" canary grep internal/auth # Find tokens in auth directory canary grep TestAuth # Find tokens with "TestAuth" test`, Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { prompt, _ := cmd.Flags().GetString("prompt") if prompt != "" { if _, err := utils.LoadPrompt(prompt); err != nil { return err } } pattern := args[0] dbPath, _ := cmd.Flags().GetString("db") groupBy, _ := cmd.Flags().GetString("group-by") limit, _ := cmd.Flags().GetInt("limit") var effLimit int if limit < 0 { effLimit = math.MaxInt32 } else { effLimit = utils.EffectiveLimit(limit, defaultGrepLimit) } projectID := utils.ReadProjectID(cmd) db, err := utils.OpenIndexRO(cmd, dbPath) if err != nil { return err } defer db.Close() tokens, err := canary.GrepTokens(db, projectID, pattern, effLimit) if err != nil { return utils.GuardContract(cmd, err) } if len(tokens) == 0 { fmt.Printf("No tokens found matching pattern: %s\n", pattern) return nil } fmt.Printf("Found %d tokens matching '%s':\n\n", len(tokens), pattern) if groupBy == "requirement" { fmt.Print(canary.FormatGrepResultsByRequirement(tokens)) } else { fmt.Print(canary.FormatGrepResults(tokens)) } if effLimit > 0 && len(tokens) == effLimit { fmt.Printf("(showing %d; use --limit -1 for all)\n", effLimit) } return nil }, }
CANARY: REQ=CBIN-CLI-001; FEATURE="GrepCmd"; ASPECT=CLI; STATUS=TESTED; TEST=TestCANARY_CBIN_CLI_001_CLI_GrepCmd; UPDATED=2026-08-29
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.