@@ -17,7 +17,7 @@ defmodule CodeQA.CLI do
1717
1818 defp handle_analyze ( args ) do
1919 { opts , [ path ] , _ } = OptionParser . parse ( args ,
20- strict: [ output: :string , progress: :boolean , workers: :integer , cache: :boolean , cache_dir: :string , timeout: :integer , show_ncd: :boolean , ncd_top: :integer , ncd_paths: :string , show_files: :boolean , show_file_paths: :string , combinations: :boolean , telemetry: :boolean , experimental_stopwords: :boolean , stopwords_threshold: :float ] ,
20+ strict: [ output: :string , progress: :boolean , workers: :integer , cache: :boolean , cache_dir: :string , timeout: :integer , show_ncd: :boolean , ncd_top: :integer , ncd_paths: :string , show_files: :boolean , show_file_paths: :string , combinations: :boolean , telemetry: :boolean , experimental_stopwords: :boolean , stopwords_threshold: :float , ignore_paths: :string ] ,
2121 aliases: [ o: :output , w: :workers , t: :timeout ]
2222 )
2323
@@ -28,7 +28,8 @@ defmodule CodeQA.CLI do
2828 exit ( { :shutdown , 1 } )
2929 end
3030
31- files = CodeQA.Collector . collect_files ( path )
31+ ignore_patterns = parse_ignore_paths ( opts [ :ignore_paths ] )
32+ files = CodeQA.Collector . collect_files ( path , ignore_patterns: ignore_patterns )
3233 if map_size ( files ) == 0 do
3334 IO . puts ( :stderr , "Warning: no source files found in '#{ path } '" )
3435 exit ( { :shutdown , 1 } )
@@ -88,7 +89,8 @@ defmodule CodeQA.CLI do
8889 ncd_top: :integer , ncd_paths: :string ,
8990 combinations: :boolean , telemetry: :boolean ,
9091 experimental_stopwords: :boolean , stopwords_threshold: :float ,
91- show_files: :boolean , show_file_paths: :string
92+ show_files: :boolean , show_file_paths: :string ,
93+ ignore_paths: :string
9294 ] ,
9395 aliases: [ w: :workers , t: :timeout ]
9496 )
@@ -106,6 +108,8 @@ defmodule CodeQA.CLI do
106108 exit ( { :shutdown , 1 } )
107109 end
108110
111+ ignore_patterns = parse_ignore_paths ( opts [ :ignore_paths ] )
112+ opts = Keyword . put ( opts , :ignore_patterns , ignore_patterns )
109113 { base_result , head_result , changes } = run_comparison ( path , base_ref , head_ref , changes_only , opts )
110114
111115 comparison =
@@ -127,7 +131,8 @@ defmodule CodeQA.CLI do
127131 timeout: :integer , show_ncd: :boolean ,
128132 ncd_top: :integer , ncd_paths: :string ,
129133 combinations: :boolean ,
130- show_files: :boolean , show_file_paths: :string
134+ show_files: :boolean , show_file_paths: :string ,
135+ ignore_paths: :string
131136 ] ,
132137 aliases: [ n: :commits , o: :output_dir , w: :workers , t: :timeout ]
133138 )
@@ -154,6 +159,7 @@ defmodule CodeQA.CLI do
154159 IO . puts ( :stderr , "Found #{ length ( commits ) } commits to analyze." )
155160
156161 analyze_opts = build_analyze_opts ( opts )
162+ ignore_patterns = parse_ignore_paths ( opts [ :ignore_paths ] )
157163
158164 commits
159165 |> Enum . with_index ( 1 )
@@ -164,6 +170,7 @@ defmodule CodeQA.CLI do
164170 current_opts = if opts [ :progress ] , do: [ { :on_progress , fn c , t , p , _tt -> progress_callback ( c , t , p , start_time_progress ) end } | analyze_opts ] , else: analyze_opts
165171
166172 files = CodeQA.Git . collect_files_at_ref ( path , commit )
173+ files = CodeQA.Collector . reject_ignored_map ( files , ignore_patterns )
167174
168175 if map_size ( files ) == 0 do
169176 IO . puts ( :stderr , "Warning: no source files found at commit #{ commit } " )
@@ -410,7 +417,9 @@ defmodule CodeQA.CLI do
410417 end
411418
412419 defp run_comparison ( path , base_ref , head_ref , changes_only , opts ) do
420+ ignore_patterns = opts [ :ignore_patterns ] || [ ]
413421 changes = CodeQA.Git . changed_files ( path , base_ref , head_ref )
422+ changes = CodeQA.Collector . reject_ignored ( changes , ignore_patterns , & & 1 . path )
414423
415424 file_paths = if changes_only do
416425 IO . puts ( :stderr , "Comparing #{ length ( changes ) } changed files..." )
@@ -422,6 +431,8 @@ defmodule CodeQA.CLI do
422431
423432 base_files = CodeQA.Git . collect_files_at_ref ( path , base_ref , file_paths )
424433 head_files = CodeQA.Git . collect_files_at_ref ( path , head_ref , file_paths )
434+ base_files = CodeQA.Collector . reject_ignored_map ( base_files , ignore_patterns )
435+ head_files = CodeQA.Collector . reject_ignored_map ( head_files , ignore_patterns )
425436
426437 if map_size ( base_files ) == 0 and map_size ( head_files ) == 0 do
427438 IO . puts ( :stderr , "Warning: no source files found at either ref" )
@@ -538,7 +549,7 @@ defmodule CodeQA.CLI do
538549
539550 defp handle_stopwords ( args ) do
540551 { opts , [ path ] , _ } = OptionParser . parse ( args ,
541- strict: [ workers: :integer , stopwords_threshold: :float , progress: :boolean ] ,
552+ strict: [ workers: :integer , stopwords_threshold: :float , progress: :boolean , ignore_paths: :string ] ,
542553 aliases: [ w: :workers ]
543554 )
544555
@@ -547,7 +558,8 @@ defmodule CodeQA.CLI do
547558 exit ( { :shutdown , 1 } )
548559 end
549560
550- files = CodeQA.Collector . collect_files ( path )
561+ ignore_patterns = parse_ignore_paths ( opts [ :ignore_paths ] )
562+ files = CodeQA.Collector . collect_files ( path , ignore_patterns: ignore_patterns )
551563 if map_size ( files ) == 0 do
552564 IO . puts ( :stderr , "Warning: no source files found in '#{ path } '" )
553565 exit ( { :shutdown , 1 } )
@@ -589,7 +601,8 @@ defmodule CodeQA.CLI do
589601 timeout: :integer , show_ncd: :boolean ,
590602 ncd_top: :integer , ncd_paths: :string ,
591603 combinations: :boolean , telemetry: :boolean ,
592- experimental_stopwords: :boolean , stopwords_threshold: :float
604+ experimental_stopwords: :boolean , stopwords_threshold: :float ,
605+ ignore_paths: :string
593606 ] ,
594607 aliases: [ o: :output , w: :workers , t: :timeout ]
595608 )
@@ -601,7 +614,8 @@ defmodule CodeQA.CLI do
601614 exit ( { :shutdown , 1 } )
602615 end
603616
604- files = CodeQA.Collector . collect_files ( path )
617+ ignore_patterns = parse_ignore_paths ( opts [ :ignore_paths ] )
618+ files = CodeQA.Collector . collect_files ( path , ignore_patterns: ignore_patterns )
605619 if map_size ( files ) == 0 do
606620 IO . puts ( :stderr , "Warning: no source files found in '#{ path } '" )
607621 exit ( { :shutdown , 1 } )
@@ -680,6 +694,13 @@ defmodule CodeQA.CLI do
680694 # credo:disable-for-next-line Credo.Check.Warning.OperationOnSameValues
681695 defp nan? ( x ) , do: x != x
682696
697+ defp parse_ignore_paths ( nil ) , do: [ ]
698+ defp parse_ignore_paths ( paths_string ) do
699+ paths_string
700+ |> String . split ( "," , trim: true )
701+ |> Enum . map ( & String . trim / 1 )
702+ end
703+
683704 defp print_usage do
684705 IO . puts ( """
685706 Usage: codeqa <command> [options]
@@ -704,6 +725,7 @@ defmodule CodeQA.CLI do
704725 --ncd-paths PATHS Comma-separated list of paths to compute NCD for
705726 --show-files Include individual file metrics in the output
706727 --show-file-paths P Comma-separated list of paths to include in the output
728+ --ignore-paths PATHS Comma-separated list of path patterns to ignore (supports wildcards, e.g. "test/*,docs/*")
707729
708730 Options for compare:
709731 --base-ref REF Base git ref to compare from (required)
@@ -722,6 +744,7 @@ defmodule CodeQA.CLI do
722744 --ncd-paths PATHS Comma-separated list of paths to compute NCD for
723745 --show-files Include individual file metrics in the output
724746 --show-file-paths P Comma-separated list of paths to include in the output
747+ --ignore-paths PATHS Comma-separated list of path patterns to ignore (supports wildcards, e.g. "test/*,docs/*")
725748
726749 Options for history:
727750 -n, --commits N Number of recent commits to analyze
@@ -737,6 +760,7 @@ defmodule CodeQA.CLI do
737760 --ncd-paths PATHS Comma-separated list of paths to compute NCD for
738761 --show-files Include individual file metrics in the output
739762 --show-file-paths P Comma-separated list of paths to include in the output
763+ --ignore-paths PATHS Comma-separated list of path patterns to ignore (supports wildcards, e.g. "test/*,docs/*")
740764
741765 Options for correlate:
742766 -t, --top N Number of top correlations to show (default: 20)
@@ -757,6 +781,7 @@ defmodule CodeQA.CLI do
757781 --cache Enable caching file metrics
758782 --cache-dir DIR Directory to store cache (default: .codeqa_cache)
759783 -t, --timeout MS Timeout for similarity analysis (default: 5000)
784+ --ignore-paths PATHS Comma-separated list of path patterns to ignore (supports wildcards, e.g. "test/*,docs/*")
760785 """ )
761786 end
762787end
0 commit comments