Refactored elifs into match case
This commit is contained in:
parent
b7918a2e30
commit
745c926d76
1 changed files with 11 additions and 9 deletions
|
@ -140,23 +140,25 @@ def main():
|
||||||
parser.add_argument("command", choices=["sign", "verify"], help="Command to execute: 'sign' or 'verify'")
|
parser.add_argument("command", choices=["sign", "verify"], help="Command to execute: 'sign' or 'verify'")
|
||||||
parser.add_argument("user", help="Username")
|
parser.add_argument("user", help="Username")
|
||||||
parser.add_argument("filename", help="File name")
|
parser.add_argument("filename", help="File name")
|
||||||
|
parser.add_argument("--test", action="store_true", help="Perform testing (simulate errors)")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.command == "sign":
|
match args.command:
|
||||||
if os.path.exists(args.user + ".crt") and os.path.exists(args.user + ".key"):
|
case "sign" if os.path.exists(args.user + ".crt") and os.path.exists(args.user + ".key"):
|
||||||
sign(args.user, args.filename)
|
sign(args.user, args.filename)
|
||||||
print("File signed successfully.")
|
print("File signed successfully.")
|
||||||
else:
|
case "sign":
|
||||||
print("User certificate or private key not found.")
|
print("User certificate or private key not found.")
|
||||||
elif args.command == "verify":
|
case "verify" if os.path.exists(args.filename + ".sig"):
|
||||||
if os.path.exists(args.filename + ".sig"):
|
|
||||||
verify(args.filename, args.user)
|
verify(args.filename, args.user)
|
||||||
else:
|
case "verify":
|
||||||
print("Signature file not found.")
|
print("Signature file not found.")
|
||||||
else:
|
case _:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in a new issue