Skip to content

Commit 05fef35

Browse files
committed
Improved CLI error messages
1 parent cdf4001 commit 05fef35

File tree

3 files changed

+38
-38
lines changed

3 files changed

+38
-38
lines changed

about_code_tool/about.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ def get_genattrib_errors(self):
10771077

10781078
def main(parser, options, args):
10791079
"""
1080-
Main command line entry point.
1080+
Main commnand line entry point.
10811081
"""
10821082
overwrite = options.overwrite
10831083
verbosity = options.verbosity
@@ -1092,7 +1092,7 @@ def main(parser, options, args):
10921092
handler.setLevel(logging.WARNING)
10931093

10941094
if not len(args) == 2:
1095-
print('Input and Output paths are required.')
1095+
print('ERROR: <input_path> and <output_path> are required.')
10961096
print()
10971097
parser.print_help()
10981098
return errno.EEXIST
@@ -1101,25 +1101,25 @@ def main(parser, options, args):
11011101
output_path = os.path.abspath(output_path)
11021102

11031103
if not path_exists(input_path):
1104-
print('Input path does not exist.')
1104+
print('ERROR: <input_path> does not exist.')
11051105
print()
11061106
parser.print_help()
11071107
return errno.EEXIST
11081108

11091109
if os.path.isdir(output_path):
1110-
print('Output must be a file, not a directory.')
1110+
print('ERROR: <output_path> must be a file, not a directory.')
11111111
print()
11121112
parser.print_help()
11131113
return errno.EISDIR
11141114

11151115
if not output_path.endswith('.csv'):
1116-
print('Output file name must end with ".csv".')
1116+
print('ERROR: <output_path> must be a CSV file ending with ".csv".')
11171117
print()
11181118
parser.print_help()
11191119
return errno.EINVAL
11201120

11211121
if path_exists(output_path) and not overwrite:
1122-
print('Output file already exists. Select a different file name or use the --overwrite option.')
1122+
print('ERROR: <output_path> file already exists. Select a different file name or use the --overwrite option.')
11231123
print()
11241124
parser.print_help()
11251125
return errno.EEXIST
@@ -1136,7 +1136,7 @@ def main(parser, options, args):
11361136
return OK
11371137
else:
11381138
# we should never reach this
1139-
assert False, 'Unsupported option(s).'
1139+
assert False, 'ERROR: Unsupported option(s).'
11401140

11411141

11421142
def get_parser():

about_code_tool/genabout.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ def filter_empty_values(abouts):
654654

655655
def main(parser, options, args):
656656
"""
657-
Main commnad line entry point.
657+
Main commnand line entry point.
658658
"""
659659
verbosity = options.verbosity
660660
action = options.action
@@ -684,25 +684,25 @@ def main(parser, options, args):
684684
if action in valid_actions:
685685
action_num = action
686686
else:
687-
print('Invalid action: should be 0, 1, 2 or 3')
687+
print('ERROR: Invalid action: must be one of: 0, 1, 2 or 3')
688688
sys.exit(errno.EINVAL)
689689

690690
if copy_files_path:
691691
# code to handle tilde character
692692
copy_files_path = os.path.abspath(expanduser(copy_files_path))
693693
if not path_exists(copy_files_path):
694-
print("The project path does not exist.")
694+
print("ERROR: The COPY_FILES path does not exist.")
695695
sys.exit(errno.EINVAL)
696696

697697
if license_text_path:
698698
# code to handle tilde character
699699
license_text_path = os.path.abspath(expanduser(license_text_path))
700700
if not path_exists(license_text_path):
701-
print("The license text path does not exist.")
701+
print("ERROR: LICENSE_TEXT_LOCATION path does not exist.")
702702
sys.exit(errno.EINVAL)
703703

704704
if mapping_config and not path_exists('MAPPING.CONFIG'):
705-
print("The file 'MAPPING.CONFIG' does not exist.")
705+
print("ERROR: The file 'MAPPING.CONFIG' does not exist.")
706706
sys.exit(errno.EINVAL)
707707

708708
if extract_license:
@@ -712,7 +712,7 @@ def main(parser, options, args):
712712
gen_license = True
713713

714714
if not len(args) == 2:
715-
print('Input and Output paths are required.')
715+
print('ERROR: <input_path> and <utput_path> are required.')
716716
print()
717717
parser.print_help()
718718
sys.exit(errno.EEXIST)
@@ -724,25 +724,25 @@ def main(parser, options, args):
724724
output_path += '/'
725725

726726
if not exists(input_path):
727-
print('Input path does not exist.')
727+
print('ERROR: <input_path> file does not exist.')
728728
print()
729729
parser.print_help()
730730
sys.exit(errno.EEXIST)
731731

732732
if not exists(output_path):
733-
print('Output path does not exist.')
733+
print('ERROR: <output_path> directory does not exist.')
734734
print()
735735
parser.print_help()
736736
sys.exit(errno.EEXIST)
737737

738738
if not isdir(output_path):
739-
print('Output must be a directory, not a file.')
739+
print('ERROR: <output_path> must be a directory, not a file.')
740740
print()
741741
parser.print_help()
742742
sys.exit(errno.EISDIR)
743743

744744
if not input_path.endswith('.csv'):
745-
print("Input file name must be a CSV file ends with '.csv'")
745+
print("ERROR: <input_path> file must be a CSV file ends with '.csv'")
746746
print()
747747
parser.print_help()
748748
sys.exit(errno.EINVAL)
@@ -751,8 +751,8 @@ def main(parser, options, args):
751751

752752
dup_keys = gen.get_duplicated_keys(input_path)
753753
if dup_keys:
754-
print('The input file contains duplicated keys. '
755-
'Duplicated keys are not allowed.')
754+
print('ERROR: The <input_path> CSV file contains duplicated column keys. '
755+
'Duplicated column keys are not allowed.')
756756
print(dup_keys)
757757
print()
758758
print('Please fix the input file and re-run the tool.')
@@ -783,43 +783,43 @@ def main(parser, options, args):
783783

784784
if copy_files_path:
785785
if not isdir(copy_files_path):
786-
print("The COPY_FILES path must be a directory.")
787-
print("'--copy_files' is skipped.")
786+
print("WARNING: The COPY_FILES path must be a directory.")
787+
print("'--copy_files' option ignored.")
788788
else:
789789
licenses_in_project = True
790790
license_list = gen.verify_files_existence(input_list,
791791
copy_files_path,
792792
licenses_in_project)
793793
if not license_list:
794-
print("None of the file was found. '--copy_files' is ignored.")
794+
print("WARNING: No file found. '--copy_files' is ignored.")
795795
else:
796796
gen.copy_files(output_path, license_list)
797797

798798
if license_text_path:
799799
if not isdir(license_text_path):
800-
print("The LICENSE_TEXT_LOCATION path must be a directory.")
801-
print("'--license_text_location' is skipped.")
800+
print("WARNING: The LICENSE_TEXT_LOCATION path must be a directory.")
801+
print("'--license_text_location' option ignored.")
802802
else:
803803
licenses_in_project = False
804804
license_list = gen.verify_files_existence(input_list,
805805
license_text_path,
806806
licenses_in_project)
807807
if not license_list:
808-
print("None of the file was found. '--copy_files' is ignored.")
808+
print("WARNING: No file found. '--copy_files' option ignored.")
809809
else:
810810
gen.copy_files(output_path, license_list)
811811

812812
if extract_license:
813813
if not api_url or not api_username or not api_key:
814-
print("Missing argument for --extract_license")
814+
print("ERROR: Missing argument for --extract_license")
815815
sys.exit(errno.EINVAL)
816816
for line in input_list:
817817
try:
818818
if line['dje_license_key']:
819819
break
820820
except Exception as e:
821821
print(repr(e))
822-
print("The <input_path> CSV does not contain the required column 'dje_license_key' ")
822+
print("ERROR: The <input_path> CSV does not contain the required column 'dje_license_key' ")
823823
sys.exit(errno.EINVAL)
824824

825825
if gen_license:

about_code_tool/genattrib.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,29 +150,29 @@ def main(parser, options, args):
150150

151151
if mapping_config:
152152
if not exists('MAPPING.CONFIG'):
153-
print("The 'MAPPING.CONFIG' file does not exist.")
153+
print("ERROR: The 'MAPPING.CONFIG' file does not exist.")
154154
sys.exit(errno.EINVAL)
155155

156156
if template_location:
157157
template_location = abspath(expanduser(template_location))
158158
if not exists(template_location):
159-
print('The TEMPLATE_LOCATION file does not exist.')
159+
print('ERROR: The TEMPLATE_LOCATION file does not exist.')
160160
parser.print_help()
161161
sys.exit(errno.EINVAL)
162162

163163
if verification_location:
164164
verification_location = abspath(expanduser(verification_location))
165165
if not verification_location.endswith('.csv'):
166-
print('The VERIFICATION_LOCATION path must end with ".csv".')
166+
print('ERROR: The VERIFICATION_LOCATION file path must end with ".csv".')
167167
parser.print_help()
168168
sys.exit(errno.EINVAL)
169169
if not exists(dirname(verification_location)):
170-
print('The VERIFICATION_LOCATION file parent directory does not exist.')
170+
print('ERROR: The VERIFICATION_LOCATION file parent directory does not exist.')
171171
parser.print_help()
172172
sys.exit(errno.EINVAL)
173173

174174
if not len(args) >= 2 or not len(args) < 4:
175-
print('The number of arguments is incorrect.\n')
175+
print('ERROR: The number of arguments is incorrect.')
176176
parser.print_help()
177177
sys.exit(errno.EEXIST)
178178

@@ -194,7 +194,7 @@ def main(parser, options, args):
194194
sys.setdefaultencoding('utf-8') # @UndefinedVariable
195195

196196
if not exists(input_path):
197-
print('<input_path> does not exist.')
197+
print('ERROR: <input_path> does not exist.')
198198
parser.print_help()
199199
sys.exit(errno.EEXIST)
200200

@@ -203,23 +203,23 @@ def main(parser, options, args):
203203
input_path = extract_zip(input_path)
204204

205205
if isdir(output_path):
206-
print('<output_path> must be an HTML file, not a directory')
206+
print('ERROR: <output_path> must be an HTML file, not a directory')
207207
parser.print_help()
208208
sys.exit(errno.EISDIR)
209209

210210
# We only support HTML currently
211211
if not output_path.endswith('.html'):
212-
print('<output_path> must be an HTML file.')
212+
print('ERROR: <output_path> must be an HTML file.')
213213
parser.print_help()
214214
sys.exit(errno.EINVAL)
215215

216216
if exists(output_path) and not overwrite:
217-
print('A file at <output_path> already exists. Select a different file name or use the --overwrite option.')
217+
print('ERROR: A file at <output_path> already exists. Select a different file name or use the --overwrite option.')
218218
parser.print_help()
219219
sys.exit(errno.EEXIST)
220220

221221
if component_subset_path and not exists(component_subset_path):
222-
print('<component_list> CSV file does not exist.')
222+
print('ERROR: the <component_list> CSV file does not exist.')
223223
parser.print_help()
224224
sys.exit(errno.EEXIST)
225225

@@ -240,7 +240,7 @@ def main(parser, options, args):
240240
abouts = apply_mappings(abouts)
241241

242242
if not has_about_file_keys(abouts):
243-
print('The required key "about_file" was not found.')
243+
print('ERROR: The required column key "about_file" was not found in the <component_list> CSV file.')
244244
print('Please use the "--mapping" option to map the input keys and verify the mapping information are correct.')
245245
print('OR, correct the header keys from the component list.')
246246
parser.print_help()

0 commit comments

Comments
 (0)