9
9
from codeanalyzer .schema import model_dump_json
10
10
from codeanalyzer .options import AnalysisOptions
11
11
12
+
12
13
def main (
13
- input : Annotated [Path , typer .Option ("-i" , "--input" , help = "Path to the project root directory." )],
14
- output : Optional [Path ] = typer .Option (None , "-o" , "--output" ),
15
- format : OutputFormat = typer .Option (OutputFormat .JSON , "-f" , "--format" ),
16
- analysis_level : int = typer .Option (1 , "-a" , "--analysis-level" ),
17
- using_codeql : bool = typer .Option (False , "--codeql/--no-codeql" ),
18
- using_ray : bool = typer .Option (False , "--ray/--no-ray" ),
19
- rebuild_analysis : bool = typer .Option (False , "--eager/--lazy" ),
20
- skip_tests : bool = typer .Option (True , "--skip-tests/--include-tests" ),
21
- file_name : Optional [Path ] = typer .Option (None , "--file-name" ),
22
- cache_dir : Optional [Path ] = typer .Option (None , "-c" , "--cache-dir" ),
23
- clear_cache : bool = typer .Option (False , "--clear-cache/--keep-cache" ),
24
- verbosity : int = typer .Option (0 , "-v" , count = True ),
14
+ input : Annotated [
15
+ Path , typer .Option ("-i" , "--input" , help = "Path to the project root directory." )
16
+ ],
17
+ output : Annotated [
18
+ Optional [Path ],
19
+ typer .Option ("-o" , "--output" , help = "Output directory for artifacts." ),
20
+ ] = None ,
21
+ format : Annotated [
22
+ OutputFormat ,
23
+ typer .Option (
24
+ "-f" ,
25
+ "--format" ,
26
+ help = "Output format: json or msgpack." ,
27
+ case_sensitive = False ,
28
+ ),
29
+ ] = OutputFormat .JSON ,
30
+ analysis_level : Annotated [
31
+ int ,
32
+ typer .Option ("-a" , "--analysis-level" , help = "1: symbol table, 2: call graph." ),
33
+ ] = 1 ,
34
+ using_codeql : Annotated [
35
+ bool , typer .Option ("--codeql/--no-codeql" , help = "Enable CodeQL-based analysis." )
36
+ ] = False ,
37
+ using_ray : Annotated [
38
+ bool ,
39
+ typer .Option ("--ray/--no-ray" , help = "Enable Ray for distributed analysis." ),
40
+ ] = False ,
41
+ rebuild_analysis : Annotated [
42
+ bool ,
43
+ typer .Option (
44
+ "--eager/--lazy" ,
45
+ help = "Enable eager or lazy analysis. Defaults to lazy." ,
46
+ ),
47
+ ] = False ,
48
+ skip_tests : Annotated [
49
+ bool ,
50
+ typer .Option (
51
+ "--skip-tests/--include-tests" ,
52
+ help = "Skip test files in analysis." ,
53
+ ),
54
+ ] = True ,
55
+ file_name : Annotated [
56
+ Optional [Path ],
57
+ typer .Option (
58
+ "--file-name" ,
59
+ help = "Analyze only the specified file (relative to input directory)." ,
60
+ ),
61
+ ] = None ,
62
+ cache_dir : Annotated [
63
+ Optional [Path ],
64
+ typer .Option (
65
+ "-c" ,
66
+ "--cache-dir" ,
67
+ help = "Directory to store analysis cache. Defaults to '.codeanalyzer' in the input directory." ,
68
+ ),
69
+ ] = None ,
70
+ clear_cache : Annotated [
71
+ bool ,
72
+ typer .Option (
73
+ "--clear-cache/--keep-cache" ,
74
+ help = "Clear cache after analysis. By default, cache is retained." ,
75
+ ),
76
+ ] = False ,
77
+ verbosity : Annotated [
78
+ int , typer .Option ("-v" , count = True , help = "Increase verbosity: -v, -vv, -vvv" )
79
+ ] = 0 ,
25
80
):
26
81
options = AnalysisOptions (
27
82
input = input ,
@@ -46,13 +101,17 @@ def main(
46
101
if options .file_name is not None :
47
102
full_file_path = options .input / options .file_name
48
103
if not full_file_path .exists ():
49
- logger .error (f"Specified file '{ options .file_name } ' does not exist in '{ options .input } '." )
104
+ logger .error (
105
+ f"Specified file '{ options .file_name } ' does not exist in '{ options .input } '."
106
+ )
50
107
raise typer .Exit (code = 1 )
51
108
if not full_file_path .is_file ():
52
109
logger .error (f"Specified path '{ options .file_name } ' is not a file." )
53
110
raise typer .Exit (code = 1 )
54
- if not str (options .file_name ).endswith ('.py' ):
55
- logger .error (f"Specified file '{ options .file_name } ' is not a Python file (.py)." )
111
+ if not str (options .file_name ).endswith (".py" ):
112
+ logger .error (
113
+ f"Specified file '{ options .file_name } ' is not a Python file (.py)."
114
+ )
56
115
raise typer .Exit (code = 1 )
57
116
58
117
with Codeanalyzer (options ) as analyzer :
@@ -85,6 +144,7 @@ def _write_output(artifacts, output_dir: Path, format: OutputFormat):
85
144
f"Compression ratio: { artifacts .get_compression_ratio ():.1%} of JSON size"
86
145
)
87
146
147
+
88
148
app = typer .Typer (
89
149
callback = main ,
90
150
name = "codeanalyzer" ,
0 commit comments