Skip to content

Instantly share code, notes, and snippets.

@Hansimov
Last active June 26, 2023 11:15
Show Gist options
  • Save Hansimov/5ab26b3430dbdb6e411918361d819fd9 to your computer and use it in GitHub Desktop.
Save Hansimov/5ab26b3430dbdb6e411918361d819fd9 to your computer and use it in GitHub Desktop.
A template for customized Argument Parser in Python
import argparse
import sys
class ArgParser(argparse.ArgumentParser):
def __init__(self, *args, **kwargs):
super(ArgParser, self).__init__(*args, **kwargs)
self.add_argument(
"-s", "--sync", action="store_true", help="Sync origin and upstream"
)
self.add_argument("-i", "--paper-id", type=str, help="arXiv paper ID")
self.add_argument(
"-u",
"--update",
action="store_true",
help="Update ... from dataUrl, and use latest ... rev",
)
self.add_argument(
"-c",
"--commit",
nargs="?",
const=True,
type=str,
help="Git add and commit changes",
)
self.add_argument(
"-r",
"--repush",
action="store_true",
help="Git re-commit and re-push changes",
)
self.add_argument(
"-pr",
"--pull-request",
action="store_true",
help="Submit PR for new branch",
)
self.add_argument("-lb", "--label", action="store_true", help="Add label to PR")
self.add_argument(
"-jk",
"--jenkins",
action="store_true",
help="Post Jenkins checkpoints jobs for PR",
)
self.add_argument(
"-cp",
"--checkpoints",
action="store_true",
help="Copy and paste results of Jenkins checkpoints jobs to PR",
)
self.add_argument(
"-jr", "--jira", action="store_true", help="Post comment to Jira issue"
)
self.add_argument(
"-a",
"--all-steps",
action="store_true",
help="""Execute all steps (with intervals):
-s: sync_upstream();
-u: update();
-c: checkout_branch() + git_add_commit_push();
-r: git_add_commit_push(repush=True)
-pr: git_pull_request();
-l: git_add_label();
-jk: submit_jenkins_job()""",
)
self.args = self.parse_args(sys.argv[1:])
if __name__ == '__main__':
arg_parser = ArgParser()
args = arg_parser.args
if args.all_steps:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment