11import argparse
22import os
33from pathlib import Path
4- from rsmetacheck . run_somef import run_somef_batch , run_somef_single , ensure_somef_configured
4+
55from rsmetacheck .run_analyzer import run_analysis
6+ from rsmetacheck .run_somef import (
7+ ensure_somef_configured ,
8+ run_somef_batch ,
9+ run_somef_single ,
10+ )
611
712
813def cli ():
9- parser = argparse .ArgumentParser (description = "Detect metadata pitfalls in software repositories using SoMEF." )
14+ parser = argparse .ArgumentParser (
15+ description = "Detect metadata pitfalls in software repositories using SoMEF."
16+ )
1017 parser .add_argument (
1118 "--input" ,
1219 nargs = "+" ,
1320 required = True ,
14- help = "One or more: GitHub/GitLab URLs, JSON files containing repositories, OR existing SoMEF output files when using --skip-somef."
21+ help = "One or more: GitHub/GitLab URLs, JSON files containing repositories, OR existing SoMEF output files when using --skip-somef." ,
1522 )
1623 parser .add_argument (
1724 "--skip-somef" ,
1825 action = "store_true" ,
19- help = "Skip SoMEF execution and analyze existing SoMEF output files directly. --input should point to SoMEF JSON files."
26+ help = "Skip SoMEF execution and analyze existing SoMEF output files directly. --input should point to SoMEF JSON files." ,
2027 )
2128 parser .add_argument (
2229 "--pitfalls-output" ,
2330 default = os .path .join (os .getcwd (), "pitfalls_outputs" ),
24- help = "Directory to store pitfall JSON-LD files (default: ./pitfalls_outputs)."
31+ help = "Directory to store pitfall JSON-LD files (default: ./pitfalls_outputs)." ,
2532 )
2633 parser .add_argument (
2734 "--somef-output" ,
2835 default = os .path .join (os .getcwd (), "somef_outputs" ),
29- help = "Directory to store SoMEF output files (default: ./somef_outputs)."
36+ help = "Directory to store SoMEF output files (default: ./somef_outputs)." ,
3037 )
3138 parser .add_argument (
3239 "--analysis-output" ,
3340 default = os .path .join (os .getcwd (), "analysis_results.json" ),
34- help = "File path for summary results (default: ./analysis_results.json)."
41+ help = "File path for summary results (default: ./analysis_results.json)." ,
3542 )
3643 parser .add_argument (
3744 "--threshold" ,
3845 type = float ,
3946 default = 0.8 ,
40- help = "SoMEF confidence threshold (default: 0.8). Only used when running SoMEF."
47+ help = "SoMEF confidence threshold (default: 0.8). Only used when running SoMEF." ,
48+ )
49+ parser .add_argument (
50+ "-b" ,
51+ "--branch" ,
52+ help = "Branch of the repository to analyze. Overrides the default branch. Only used when running SoMEF." ,
4153 )
54+
4255 parser .add_argument (
43- "-b" , "--branch" ,
44- help = "Branch of the repository to analyze. Overrides the default branch. Only used when running SoMEF."
56+ "-c" ,
57+ "--generate-codemeta" ,
58+ action = "store_true" ,
59+ help = "Generate codemeta files for each repository. Only used when running SoMEF." ,
4560 )
4661
4762 parser .add_argument (
4863 "--verbose" ,
4964 action = "store_true" ,
50- help = "Include both detected AND undetected pitfalls in the output JSON-LD."
65+ help = "Include both detected AND undetected pitfalls in the output JSON-LD." ,
5166 )
5267
5368 args = parser .parse_args ()
5469
5570 if args .skip_somef :
56- print (f"Skipping SoMEF execution. Analyzing { len (args .input )} existing SoMEF output files..." )
71+ print (
72+ f"Skipping SoMEF execution. Analyzing { len (args .input )} existing SoMEF output files..."
73+ )
5774
5875 somef_json_paths = []
5976 for json_path in args .input :
@@ -67,29 +84,58 @@ def cli():
6784 return
6885
6986 print (f"Analyzing { len (somef_json_paths )} SoMEF output files..." )
70- run_analysis (somef_json_paths , args .pitfalls_output , args .analysis_output , verbose = args .verbose )
87+ run_analysis (
88+ somef_json_paths ,
89+ args .pitfalls_output ,
90+ args .analysis_output ,
91+ verbose = args .verbose ,
92+ )
7193
7294 else :
7395 ensure_somef_configured ()
7496
7597 threshold = args .threshold
7698 somef_output_dir = args .somef_output
99+ generate_codemeta = args .generate_codemeta
77100
78101 print (f"Detected { len (args .input )} input(s):" )
102+ if generate_codemeta :
103+ print (
104+ "Codemeta generation is ENABLED. Codemeta files will be created for each repository."
105+ )
79106
80107 for input_item in args .input :
81108 if input_item .startswith ("http://" ) or input_item .startswith ("https://" ):
82109 print (f"Processing repository URL: { input_item } " )
83- run_somef_single (input_item , somef_output_dir , threshold , branch = args .branch )
110+ run_somef_single (
111+ input_item ,
112+ somef_output_dir ,
113+ threshold ,
114+ branch = args .branch ,
115+ generate_codemeta = generate_codemeta ,
116+ )
84117 elif os .path .exists (input_item ):
85118 print (f"Processing repositories from file: { input_item } " )
86- run_somef_batch (input_item , somef_output_dir , threshold , branch = args .branch )
119+ run_somef_batch (
120+ input_item ,
121+ somef_output_dir ,
122+ threshold ,
123+ branch = args .branch ,
124+ generate_codemeta = generate_codemeta ,
125+ )
87126 else :
88- print (f"Warning: Skipping invalid input (not a URL or existing file): { input_item } " )
127+ print (
128+ f"Warning: Skipping invalid input (not a URL or existing file): { input_item } "
129+ )
89130
90131 print (f"\n Running analysis on outputs in { somef_output_dir } ..." )
91- run_analysis (somef_output_dir , args .pitfalls_output , args .analysis_output , verbose = args .verbose )
132+ run_analysis (
133+ somef_output_dir ,
134+ args .pitfalls_output ,
135+ args .analysis_output ,
136+ verbose = args .verbose ,
137+ )
92138
93139
94140if __name__ == "__main__" :
95- cli ()
141+ cli ()
0 commit comments