From 053604c0464f5d58a5228ad9c4f506671ef9ff28 Mon Sep 17 00:00:00 2001 From: LucasLvy Date: Thu, 4 Aug 2022 12:06:56 +0200 Subject: [PATCH 1/4] feat(cli): file is optional --- README.md | 2 +- amarna/command_line.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a60cf15..fbbd7a2 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ Examples of these are: ### Rule names Obtain the names of the currently implemented rules with: ```bash - amarna --show-rules . + amarna --show-rules ``` ### Rule allowlist diff --git a/amarna/command_line.py b/amarna/command_line.py index 8bf04a7..3920c13 100644 --- a/amarna/command_line.py +++ b/amarna/command_line.py @@ -96,6 +96,7 @@ def main() -> int: metavar="-f", type=str, help="the name of the .cairo file or directory with .cairo files to analyze", + nargs="?" ) parser.add_argument("-p", "--print", action="store_true", help="print output") From c1b542b2b1b6db3e48d8223b8588f743251d6113 Mon Sep 17 00:00:00 2001 From: LucasLvy Date: Tue, 9 Aug 2022 12:16:52 +0200 Subject: [PATCH 2/4] feat(cli): check if file is specified and exists --- amarna/command_line.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/amarna/command_line.py b/amarna/command_line.py index 3920c13..e1ed6bc 100644 --- a/amarna/command_line.py +++ b/amarna/command_line.py @@ -96,7 +96,7 @@ def main() -> int: metavar="-f", type=str, help="the name of the .cairo file or directory with .cairo files to analyze", - nargs="?" + nargs="?", ) parser.add_argument("-p", "--print", action="store_true", help="print output") @@ -150,9 +150,12 @@ def main() -> int: filename = args.filename - if not os.path.isabs(filename): + if filename is not None and not os.path.isabs(filename): filename = os.path.join(os.getcwd(), filename) + if not os.path.exists(filename): + raise Exception("The specified file doesn't exist") + rule_set_names: List[str] = get_rule_names(args.rules, args.exclude_rules) results: List[Union[Result, ResultMultiplePositions]] From 2b9fa7523c6632c758dea5647933d90533e932e7 Mon Sep 17 00:00:00 2001 From: LucasLvy Date: Wed, 10 Aug 2022 10:39:20 +0200 Subject: [PATCH 3/4] feat(cli): separate None check from isabs + remove exception --- amarna/command_line.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/amarna/command_line.py b/amarna/command_line.py index e1ed6bc..2fb93b6 100644 --- a/amarna/command_line.py +++ b/amarna/command_line.py @@ -150,11 +150,16 @@ def main() -> int: filename = args.filename - if filename is not None and not os.path.isabs(filename): + if filename is None: + print("No file specified") + return -1 + + if not os.path.isabs(filename): filename = os.path.join(os.getcwd(), filename) if not os.path.exists(filename): - raise Exception("The specified file doesn't exist") + print("The specified file doesn't exist") + return -1 rule_set_names: List[str] = get_rule_names(args.rules, args.exclude_rules) From 9e5a8f41bca09e8ca001aa74b653772fc68bf64a Mon Sep 17 00:00:00 2001 From: Filipe Casal Date: Wed, 10 Aug 2022 17:33:39 +0100 Subject: [PATCH 4/4] Add filename to the error message. --- amarna/command_line.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amarna/command_line.py b/amarna/command_line.py index 2fb93b6..370a263 100644 --- a/amarna/command_line.py +++ b/amarna/command_line.py @@ -158,7 +158,7 @@ def main() -> int: filename = os.path.join(os.getcwd(), filename) if not os.path.exists(filename): - print("The specified file doesn't exist") + print(f"The specified file doesn't exist: {filename}") return -1 rule_set_names: List[str] = get_rule_names(args.rules, args.exclude_rules)