@@ -115,6 +115,10 @@ def cli():
115115@click .option ('--mapping' , is_flag = True ,
116116 help = 'Use file mapping.config to collect the defined not supported fields in ABOUT files.' )
117117
118+ @click .option ('--mapping-file' , metavar = 'FILE' , nargs = 1 ,
119+ type = click .Path (exists = True , dir_okay = True , readable = True , resolve_path = True ),
120+ help = 'Use a custom mapping file with mapping between input keys and ABOUT field names.' )
121+
118122@click .option ('--show-all' , is_flag = True , default = False ,
119123 help = 'Show all errors and warnings. '
120124 'By default, the tool only prints these '
@@ -128,7 +132,7 @@ def cli():
128132
129133@click .help_option ('-h' , '--help' )
130134
131- def inventory (location , output , mapping , quiet , format , show_all ):
135+ def inventory (location , output , mapping , mapping_file , quiet , format , show_all ):
132136 """
133137Collect a JSON or CSV inventory of components from .ABOUT files.
134138
@@ -151,7 +155,7 @@ def inventory(location, output, mapping, quiet, format, show_all):
151155 # accept zipped ABOUT files as input
152156 location = extract_zip (location )
153157
154- errors , abouts = model .collect_inventory (location , use_mapping = mapping )
158+ errors , abouts = model .collect_inventory (location , use_mapping = mapping , mapping_file = mapping_file )
155159
156160 write_errors = model .write_output (abouts , output , format )
157161 for err in write_errors :
@@ -176,7 +180,7 @@ def inventory(location, output, mapping, quiet, format, show_all):
176180@click .argument ('output' , nargs = 1 , required = True ,
177181 type = click .Path (exists = True , writable = True , dir_okay = True , resolve_path = True ))
178182
179- @click .option ('--fetch-license' , type = str , nargs = 2 , metavar = '<key> ' ,
183+ @click .option ('--fetch-license' , type = str , nargs = 2 , metavar = 'KEY ' ,
180184 help = ('Fetch licenses text from a DejaCode API. and create <license>.LICENSE side-by-side '
181185 'with the generated .ABOUT file using data fetched from a DejaCode License Library. '
182186 'The "license" key is needed in the input. '
@@ -193,7 +197,11 @@ def inventory(location, output, mapping, quiet, format, show_all):
193197 help = "Copy the 'license_file' from the directory to the generated location." )
194198
195199@click .option ('--mapping' , is_flag = True ,
196- help = 'Use file mapping.config with mapping between input keys and ABOUT field names.' )
200+ help = 'Use the default file mapping.config with mapping between input keys and ABOUT field names.' )
201+
202+ @click .option ('--mapping-file' , metavar = 'FILE' , nargs = 1 ,
203+ type = click .Path (exists = True , dir_okay = True , readable = True , resolve_path = True ),
204+ help = 'Use a custom mapping file with mapping between input keys and ABOUT field names.' )
197205
198206@click .option ('--show-all' , is_flag = True , default = False ,
199207 help = 'Show all errors and warnings. '
@@ -208,7 +216,7 @@ def inventory(location, output, mapping, quiet, format, show_all):
208216
209217@click .help_option ('-h' , '--help' )
210218
211- def gen (location , output , mapping , license_notice_text_location , fetch_license ,
219+ def gen (location , output , mapping , mapping_file , license_notice_text_location , fetch_license ,
212220 quiet , show_all ):
213221 """
214222Generate .ABOUT files in OUTPUT directory from a JSON or CSV inventory of .ABOUT files at LOCATION.
@@ -227,7 +235,7 @@ def gen(location, output, mapping, license_notice_text_location, fetch_license,
227235
228236 errors , abouts = gen_generate (
229237 location = location , base_dir = output , license_notice_text_location = license_notice_text_location ,
230- fetch_license = fetch_license , use_mapping = mapping )
238+ fetch_license = fetch_license , use_mapping = mapping , mapping_file = mapping_file )
231239
232240 about_count = len (abouts )
233241 error_count = 0
@@ -266,6 +274,10 @@ def gen(location, output, mapping, license_notice_text_location, fetch_license,
266274 help = 'Use the file "mapping.config" with mappings between the CSV '
267275 'inventory columns names and .ABOUT field names.' )
268276
277+ @click .option ('--mapping-file' , metavar = 'FILE' , nargs = 1 ,
278+ type = click .Path (exists = True , dir_okay = True , readable = True , resolve_path = True ),
279+ help = 'Use a custom mapping file with mapping between input keys and ABOUT field names.' )
280+
269281@click .option ('--show-all' , is_flag = True , default = False ,
270282 help = 'Show all errors and warnings. '
271283 'By default, the tool only prints these '
@@ -282,7 +294,7 @@ def gen(location, output, mapping, license_notice_text_location, fetch_license,
282294
283295@click .help_option ('-h' , '--help' )
284296
285- def attrib (location , output , template , mapping , inventory , quiet , show_all ):
297+ def attrib (location , output , template , mapping , mapping_file , inventory , quiet , show_all ):
286298 """
287299Generate an attribution document at OUTPUT using .ABOUT files at LOCATION.
288300
@@ -297,10 +309,10 @@ def attrib(location, output, template, mapping, inventory, quiet, show_all):
297309 if location .lower ().endswith ('.zip' ):
298310 location = extract_zip (location )
299311
300- inv_errors , abouts = model .collect_inventory (location , use_mapping = mapping )
312+ inv_errors , abouts = model .collect_inventory (location , use_mapping = mapping , mapping_file = mapping_file )
301313 no_match_errors = attrib_generate_and_save (
302314 abouts = abouts , output_location = output ,
303- use_mapping = mapping , template_loc = template ,
315+ use_mapping = mapping , mapping_file = mapping_file , template_loc = template ,
304316 inventory_location = inventory )
305317
306318 if not no_match_errors :
0 commit comments