Created
March 13, 2024 15:57
-
-
Save SamDudley/77ec5a7f769e91ad241b3be6c1868e72 to your computer and use it in GitHub Desktop.
A python script template with no dependencies.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import argparse | |
class CommandError(Exception): | |
pass | |
def main(args): | |
if args.cake == "chocolate": | |
raise CommandError("Not chocolate cake!") | |
print(f"Yes {args.cake} cake!") | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument("cake") | |
try: | |
main(parser.parse_args()) | |
except CommandError as e: | |
print(str(e)) | |
exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment