Refactored elifs into match case

This commit is contained in:
LucasVerdelho 2024-03-19 21:58:27 +00:00
parent b7918a2e30
commit 745c926d76

View file

@ -140,24 +140,26 @@ def main():
parser.add_argument("command", choices=["sign", "verify"], help="Command to execute: 'sign' or 'verify'")
parser.add_argument("user", help="Username")
parser.add_argument("filename", help="File name")
parser.add_argument("--test", action="store_true", help="Perform testing (simulate errors)")
args = parser.parse_args()
if args.command == "sign":
if os.path.exists(args.user + ".crt") and os.path.exists(args.user + ".key"):
match args.command:
case "sign" if os.path.exists(args.user + ".crt") and os.path.exists(args.user + ".key"):
sign(args.user, args.filename)
print("File signed successfully.")
else:
case "sign":
print("User certificate or private key not found.")
elif args.command == "verify":
if os.path.exists(args.filename + ".sig"):
case "verify" if os.path.exists(args.filename + ".sig"):
verify(args.filename, args.user)
else:
case "verify":
print("Signature file not found.")
else:
case _:
parser.print_help()
sys.exit(1)
if __name__ == "__main__":
main()