Skip to content

Commit a1d1898

Browse files
authored
Print argparse's help msg if invalid input
1 parent 5b4d553 commit a1d1898

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

src/fosslight_oss_pkg/_convert.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,21 @@ def convert_report(base_path, output_name, format, need_log_file=True):
5252
files_to_convert = base_path.split(",")
5353
file_option_on = True
5454
for file in files_to_convert:
55-
if file.endswith((".yaml", ".yml")):
56-
oss_yaml_files.append(file)
55+
if os.path.isfile(file):
56+
if file.endswith((".yaml", ".yml")):
57+
oss_yaml_files.append(file)
58+
else:
59+
logger.error("Not support file name or extension")
60+
sys.exit(1)
5761
else:
58-
logger.error("Not support file name or extension")
62+
logger.error(f"Check the path to find: {base_path}")
5963
sys.exit(1)
6064

6165
if oss_yaml_files:
6266
convert_yml_to_excel(oss_yaml_files, output_report, file_option_on, base_path)
6367
else:
6468
logger.info("fosslight_prechecker: can't convert anything")
65-
logger.info("Try 'fosslight_prechecker -h for more information")
69+
logger.info("Try 'fosslight_prechecker -h' for more information")
6670

6771
try:
6872
_str_final_result_log = safe_dump(_result_log, allow_unicode=True, sort_keys=True)

src/fosslight_prechecker/_help.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# SPDX-License-Identifier: GPL-3.0-only
55
from fosslight_util.help import PrintHelpMsg
66

7+
78
_HELP_MESSAGE_PRECHECKER = """
89
FOSSLight Prechecker is a tool that checks whether source code complies with copyright and license writing rules.
910

src/fosslight_prechecker/_precheck.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,5 +281,5 @@ def run_lint(target_path, disable, output_file_name, format='', need_log_file=Tr
281281
logger.warning("Can't make result file\n")
282282
sys.exit(exit_code)
283283
else:
284-
logger.error(f"Check the path to find : {path_to_find}")
284+
logger.error(f"Check the path to find : {target_path}")
285285
sys.exit(1)

src/fosslight_prechecker/cli.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@
1414

1515
def main():
1616
parser = argparse.ArgumentParser(description='FOSSLight Prechecker', prog='fosslight_prechecker', add_help=False)
17-
parser.add_argument('mode', nargs='?', help='lint | convert | add', choices=['lint', 'convert', 'add'])
18-
parser.add_argument('--path', '-p', help='Path to check', type=str, dest='path', default="")
19-
parser.add_argument('--format', '-f', help='Format of ouput', type=str, dest='format', default="")
20-
parser.add_argument('--output', '-o', help='Output file name', type=str, dest='output', default="")
21-
parser.add_argument('--no', '-n', help='Disable automatic exclude mode', action='store_true', dest='disable')
22-
parser.add_argument('--license', '-l', help='License name to add', type=str, dest='license', default="")
23-
parser.add_argument('--copyright', '-c', help='Copyright to add', type=str, dest='copyright', default="")
24-
parser.add_argument('--help', '-h', help='Print help message', action='store_true', dest='help')
25-
parser.add_argument('--ignore', '-i', help='Do not write log to file', action='store_false', dest='log')
26-
parser.add_argument('--version', '-v', help='Print FOSSLight Prechecker version', action='store_true', dest='version')
17+
parser.add_argument('mode', nargs='?', help='lint | convert | add', choices=['lint', 'add', 'convert'])
18+
parser.add_argument('-h', '--help', help='Print help message', action='store_true', dest='help')
19+
parser.add_argument('-i', '--ignore', help='Do not write log to file', action='store_false', dest='log')
20+
parser.add_argument('-v', '--version', help='Print FOSSLight Prechecker version', action='store_true', dest='version')
21+
parser.add_argument('-n', '--no', help='Disable automatic exclude mode', action='store_true', dest='disable')
22+
parser.add_argument('-p', '--path', help='Path to check', type=str, dest='path', default="")
23+
parser.add_argument('-f', '--format', help='Format of ouput', type=str, dest='format', default="")
24+
parser.add_argument('-o', '--output', help='Output file name', type=str, dest='output', default="")
25+
parser.add_argument('-l', '--license', help='License name to add', type=str, dest='license', default="")
26+
parser.add_argument('-c', '--copyright', help='Copyright to add', type=str, dest='copyright', default="")
2727
try:
28-
args, unknown = parser.parse_known_args()
28+
args = parser.parse_args()
2929
except SystemExit:
30-
print_help_msg()
30+
sys.exit(0)
3131

32-
if args.help or unknown:
32+
if args.help:
3333
print_help_msg()
3434

3535
if args.version:

0 commit comments

Comments
 (0)