Skip to content

Commit

Permalink
Add guards for unusable CLI arg combinations (CensoredUsername#214)
Browse files Browse the repository at this point in the history
* Add guards for unusable CLI arg combinations
  • Loading branch information
madeddy authored Apr 4, 2024
1 parent ac1e5a3 commit 45467d5
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions unrpyc.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def main():
'--language',
dest='language',
action='store',
default='english',
default=None,
help="If writing a translation file, the language of the translations to write")

ap.add_argument(
Expand Down Expand Up @@ -346,12 +346,24 @@ def main():

args = ap.parse_args()

# Catch impossible arg combinations with clear info, so they do not produce unclear
# errors or fail silent
if (args.no_pyexpr or args.comparable) and not args.dump:
raise ap.error(
"Arguments 'comparable' and 'no_pyexpr' are not usable without 'dump'.")

if ((args.try_harder or args.dump)
and (args.write_translation_file or args.translation_file or args.language)):
raise ap.error(
"Arguments 'try_harder' and/or 'dump' are not usable with the translation "
"feature.")

# Fail early to avoid wasting time going through the files
if (args.write_translation_file
and not args.clobber
and not args.clobber
and args.write_translation_file.exists()):
# Fail early to avoid wasting time going through the files
print("Output translation file already exists. Pass --clobber to overwrite.")
return
raise ap.error(
"Output translation file already exists. Pass --clobber to overwrite.")

if args.translation_file:
with args.translation_file.open('rb') as in_file:
Expand Down

0 comments on commit 45467d5

Please sign in to comment.