Refactored elifs into match case
This commit is contained in:
parent
b7918a2e30
commit
745c926d76
1 changed files with 11 additions and 9 deletions
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in a new issue