Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow mode selecting within combined short arguments. #45

Merged
merged 5 commits into from
Dec 7, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion covert/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def argparse():
sys.exit(0)
ad = {}
args = Args()
aiter = iter(av[1:])
# Support a few other forms for Age etc. compatibility (but only as the first arg)
if av[0].lower() in ('enc', 'encrypt', '-e', '--encrypt'):
args.mode, ad, modehelp = 'enc', encargs, f"{hdrhelp}\nEncryption options:\n{enchelp}"
Expand All @@ -109,11 +110,20 @@ def argparse():
elif next((k for k, v in encargs.items() if av[0] in v), None) is not None:
args.mode, ad, modehelp = 'enc', encargs, enchelp
av.insert(0, None)
covert-encryption marked this conversation as resolved.
Show resolved Hide resolved
elif av[0].startswith('-'):
if av[0][:2] == '-e':
args.mode, ad, modehelp = 'enc', encargs, f"{hdrhelp}\nEncryption options:\n{enchelp}"
elif av[0][:2] == '-d':
args.mode, ad, modehelp = 'dec', decargs, f"{hdrhelp}\nEncryption options:\n{enchelp}"
covert-encryption marked this conversation as resolved.
Show resolved Hide resolved
else:
stderr.write(' 💣 Invalid or missing command (enc/dec/benchmark).\n')
sys.exit(1)
av[0] = f'-{av[0][2:]}'
aiter = iter(av)
covert-encryption marked this conversation as resolved.
Show resolved Hide resolved
else:
stderr.write(' 💣 Invalid or missing command (enc/dec/benchmark).\n')
sys.exit(1)

aiter = iter(av[1:])
longargs = [flag[1:] for switches in ad.values() for flag in switches if flag.startswith("--")]
shortargs = [flag[1:] for switches in ad.values() for flag in switches if not flag.startswith("--")]
for a in aiter:
Expand Down