Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import argparse
- # Initialize the main parser
- parser = argparse.ArgumentParser(description="Jira Command Line Interface")
- # Add subparsers
- subparsers = parser.add_subparsers(dest="command")
- # Add the 'status' subcommand
- status_parser = subparsers.add_parser("status", help="Check the status of a ticket")
- # Create a mutually exclusive group for status subcommand
- status_group = status_parser.add_mutually_exclusive_group(required=True)
- status_group.add_argument("--list", dest="tickets", action="store_const", const="list", help="List tickets")
- status_group.add_argument("--update", dest="tickets", action="store_const", const="update", help="Update a ticket")
- status_group.add_argument("--transitions", dest="tickets", action="store_const", const="transitions", help="View ticket transitions")
- # Add a positional argument for the ticket number
- status_parser.add_argument("ticket_nr", metavar="TICKET", type=str, help="The ticket number")
- # Parse the arguments
- args = parser.parse_args()
- # Now, you can access both ticket_nr and the chosen action
- if args.command == "status":
- print(f"Action: {args.tickets}, Ticket Number: {args.ticket_nr}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement