Created
August 31, 2025 20:59
-
-
Save zacharysyoung/42b2e3ba44cedf1be0544f0bf095d915 to your computer and use it in GitHub Desktop.
SO-7869345
This file contains hidden or 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
| import argparse | |
| def my_stop(args): | |
| args.stop = True | |
| if args.gracefully: | |
| print("Let's try to stop...") | |
| else: | |
| print("Stop, now!") | |
| parser = argparse.ArgumentParser(prog="mydaemon") | |
| graceful = argparse.ArgumentParser(add_help=False) | |
| graceful.add_argument("-g", "--gracefully", action="store_true", help="tries to terminate the process gracefully") | |
| sp = parser.add_subparsers() | |
| sp_start = sp.add_parser("start", help="Starts %(prog)s daemon") | |
| sp_stop = sp.add_parser( | |
| "stop", parents=[graceful], description="Stops the daemon if it is currently running.", help="Stops %(prog)s daemon" | |
| ) | |
| sp_restart = sp.add_parser("restart", parents=[graceful], help="Restarts %(prog)s daemon") | |
| sp_stop.set_defaults(func=my_stop) | |
| args = parser.parse_args() | |
| args.func(args) | |
| print(args.stop) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment