allow string/hosts to be written as input, not directly as argument

This commit is contained in:
2023-12-07 21:42:14 +01:00
parent f351949166
commit e08aaaaa4e

View File

@@ -11,6 +11,7 @@ import json
import os import os
import subprocess import subprocess
import sys import sys
import getpass
parser = argparse.ArgumentParser(description=__doc__) parser = argparse.ArgumentParser(description=__doc__)
subparsers = parser.add_subparsers(title="commands", dest="command", required=True) subparsers = parser.add_subparsers(title="commands", dest="command", required=True)
@@ -25,6 +26,8 @@ encrypt_flags.add_argument(
"--string", "--string",
help="String that shall be encrypted", help="String that shall be encrypted",
dest="encrypt_string", dest="encrypt_string",
nargs="?",
const="",
) )
encrypt_flags.add_argument( encrypt_flags.add_argument(
"-f", "-f",
@@ -46,6 +49,8 @@ decrypt_flags.add_argument(
"Also supports 'all'" "Also supports 'all'"
), ),
dest="decrypt_host", dest="decrypt_host",
nargs="?",
const="",
) )
decrypt_flags.add_argument( decrypt_flags.add_argument(
"-f", "-f",
@@ -234,7 +239,7 @@ def main():
# ENCRYPTION # ENCRYPTION
if args.command == "encrypt": if args.command == "encrypt":
if args.encrypt_string: if args.encrypt_string is not None:
password = input("Enter string: ") if not args.encrypt_string else args.encrypt_string password = input("Enter string: ") if not args.encrypt_string else args.encrypt_string
output = encrypt_string(password) output = encrypt_string(password)
elif args.encrypt_file: elif args.encrypt_file:
@@ -242,7 +247,7 @@ def main():
output = encrypt_file(filename) output = encrypt_file(filename)
# DECRYPTION # DECRYPTION
elif args.command == "decrypt": elif args.command == "decrypt":
if args.decrypt_host: if args.decrypt_host is not None:
host = input("Enter host: ") if not args.decrypt_host else args.decrypt_host host = input("Enter host: ") if not args.decrypt_host else args.decrypt_host
var = input("Enter variable: ") if not args.decrypt_var else args.decrypt_var var = input("Enter variable: ") if not args.decrypt_var else args.decrypt_var
output = decrypt_string(host, var) output = decrypt_string(host, var)