88 "os"
99 "os/exec"
1010 "path/filepath"
11+ "regexp"
1112 "runtime/debug"
1213 "strings"
1314
@@ -232,7 +233,11 @@ func applyCliOverrides(cmd *cobra.Command, config *Config, args *Arguments) {
232233 }
233234
234235 if len (args .regexpPatterns ) > 0 {
235- config .Regexp .Patterns = args .regexpPatterns
236+ // CLI `--regexp` only accepts regex strings, map them into include rules
237+ config .Rules .Include .Rules = make ([]Rule , 0 , len (args .regexpPatterns ))
238+ for _ , p := range args .regexpPatterns {
239+ config .Rules .Include .Rules = append (config .Rules .Include .Rules , Rule {Type : "regex" , Pattern : p })
240+ }
236241 }
237242
238243 if cmd .Flags ().Changed ("fg-color" ) {
@@ -275,17 +280,14 @@ func applyCliOverrides(cmd *cobra.Command, config *Config, args *Arguments) {
275280
276281 // Handle extra exclusion patterns from CLI
277282 if len (args .extraExclusion ) > 0 {
278- if config .Plugins .Exclusion == nil {
279- config .Plugins .Exclusion = & ExclusionConfig {Enabled : true , Rules : []ExclusionRule {}}
280- }
281- // Add CLI exclusion patterns as text rules
283+ // Add CLI exclusion patterns as regex rules into unified rules.exclude
282284 for _ , pattern := range args .extraExclusion {
283- config .Plugins .Exclusion .Rules = append (config .Plugins .Exclusion .Rules , ExclusionRule {
284- Type : "text" ,
285- Pattern : pattern ,
286- })
285+ if _ , err := regexp .Compile (pattern ); err != nil {
286+ slog .Warn ("Invalid regex in --extra-exclusion; skipping" , "pattern" , pattern , "error" , err )
287+ continue
288+ }
289+ config .Rules .Exclude .Rules = append (config .Rules .Exclude .Rules , Rule {Type : "regex" , Pattern : pattern })
287290 }
288- config .Plugins .Exclusion .Enabled = true
289291 }
290292}
291293
@@ -297,7 +299,14 @@ func runApp(config *Config, args *Arguments) error {
297299 return err
298300 }
299301
300- state := internal .NewState (text , config .Core .Alphabet , config .Regexp .Patterns )
302+ // Convert include rules to regex patterns list
303+ var includePatterns []string
304+ for _ , r := range config .Rules .Include .Rules {
305+ if r .Type == "regex" && r .Pattern != "" {
306+ includePatterns = append (includePatterns , r .Pattern )
307+ }
308+ }
309+ state := internal .NewState (text , config .Core .Alphabet , includePatterns )
301310
302311 plugins := config .Plugins
303312 if plugins .Tabledetection != nil && plugins .Tabledetection .Enabled {
@@ -312,14 +321,11 @@ func runApp(config *Config, args *Arguments) error {
312321 state .ColorDetectionConfig = internal .NewColorDetectionConfig ()
313322 }
314323
315- if plugins . Exclusion != nil && plugins . Exclusion . Enabled {
316- // Convert config exclusion rules to internal exclusion rules
324+ // Apply user-defined exclusion rules (unified rules section)
325+ if len ( config . Rules . Exclude . Rules ) > 0 {
317326 var rules []internal.ExclusionRule
318- for _ , rule := range plugins .Exclusion .Rules {
319- rules = append (rules , internal.ExclusionRule {
320- Type : rule .Type ,
321- Pattern : rule .Pattern ,
322- })
327+ for _ , rule := range config .Rules .Exclude .Rules {
328+ rules = append (rules , internal.ExclusionRule {Type : rule .Type , Pattern : rule .Pattern })
323329 }
324330 state .ExclusionConfig = internal .NewExclusionConfig (rules )
325331 }
@@ -446,7 +452,7 @@ func main() {
446452 rootCmd .Flags ().StringVarP (& args .target , "target" , "t" , "" , "Stores the hint in the specified path" )
447453 rootCmd .Flags ().StringVarP (& args .inputFile , "input-file" , "i" , "" , "Read input from file instead of stdin" )
448454 rootCmd .Flags ().BoolVarP (& args .showVersion , "version" , "v" , false , "Print version and exit" )
449- rootCmd .Flags ().StringArrayVar (& args .extraExclusion , "extra-exclusion" , nil , "Additional text patterns to exclude from matching" )
455+ rootCmd .Flags ().StringArrayVar (& args .extraExclusion , "extra-exclusion" , nil , "Additional regex patterns to exclude from matching" )
450456
451457 rootCmd .Flags ().BoolVar (& args .listView , "list" , false , "Enable list view" )
452458
0 commit comments