+def main():
+ hash_parser = argparse.ArgumentParser(add_help=False, version=False)
+ hash_parser.add_argument(
+ '-h', metavar='HASH', dest='hash', action='store',
+ help='''Lookup by patch hash'''
+ )
+ hash_parser.add_argument(
+ 'id', metavar='ID', nargs='*', action='store', type=int,
+ help='Patch ID',
+ )
+
+ filter_parser = argparse.ArgumentParser(add_help=False, version=False)
+ filter_parser.add_argument(
+ '-s', metavar='STATE',
+ help='''Filter by patch state (e.g., 'New', 'Accepted', etc.)'''
+ )
+ filter_parser.add_argument(
+ '-p', metavar='PROJECT',
+ help='''Filter by project name (see 'projects' for list)'''
+ )
+ filter_parser.add_argument(
+ '-w', metavar='WHO',
+ help='''Filter by submitter (name, e-mail substring search)'''
+ )
+ filter_parser.add_argument(
+ '-d', metavar='WHO',
+ help='''Filter by delegate (name, e-mail substring search)'''
+ )
+ filter_parser.add_argument(
+ '-n', metavar='MAX#',
+ type=int,
+ help='''Restrict number of results'''
+ )
+ filter_parser.add_argument(
+ '-m', metavar='MESSAGEID',
+ help='''Filter by Message-Id'''
+ )
+ filter_parser.add_argument(
+ 'patch_name', metavar='STR', nargs='?',
+ help='substring to search for patches by name',
+ )
+ help_parser = argparse.ArgumentParser(add_help=False, version=False)
+ help_parser.add_argument(
+ '--help', action='help', help=argparse.SUPPRESS,
+ #help='''show this help message and exit'''
+ )
+
+ action_parser = argparse.ArgumentParser(
+ prog='pwclient',
+ add_help=False,
+ version=False,
+ formatter_class=argparse.RawDescriptionHelpFormatter,
+ epilog='''(apply | get | info | view | update) (-h HASH | ID [ID ...])''',
+ )
+ action_parser.add_argument(
+ '--help',
+ #action='help',
+ action=_RecursiveHelpAction,
+ help='''Print this help text'''
+ )
+
+ subparsers = action_parser.add_subparsers(
+ title='Commands',
+ metavar=''
+ )
+ apply_parser = subparsers.add_parser(
+ 'apply', parents=[hash_parser, help_parser],
+ add_help=False,
+ help='''Apply a patch (in the current dir, using -p1)'''
+ )
+ apply_parser.set_defaults(subcmd='apply')
+ git_am_parser = subparsers.add_parser(
+ 'git-am', parents=[hash_parser, help_parser],
+ add_help=False,
+ help='''Apply a patch to current git branch using "git am".'''
+ )
+ git_am_parser.set_defaults(subcmd='git_am')
+ git_am_parser.add_argument(
+ '-s', '--signoff',
+ action='store_true',
+ help='''pass --signoff to git-am'''
+ )
+ get_parser = subparsers.add_parser(
+ 'get', parents=[hash_parser, help_parser],
+ add_help=False,
+ help='''Download a patch and save it locally'''
+ )
+ get_parser.set_defaults(subcmd='get')
+ info_parser = subparsers.add_parser(
+ 'info', parents=[hash_parser, help_parser],
+ add_help=False,
+ help='''Display patchwork info about a given patch ID'''
+ )
+ info_parser.set_defaults(subcmd='info')
+ projects_parser = subparsers.add_parser(
+ 'projects',
+ add_help=False,
+ help='''List all projects'''
+ )
+ projects_parser.set_defaults(subcmd='projects')
+ states_parser = subparsers.add_parser(
+ 'states',
+ add_help=False,
+ help='''Show list of potential patch states'''
+ )
+ states_parser.set_defaults(subcmd='states')
+ view_parser = subparsers.add_parser(
+ 'view', parents=[hash_parser, help_parser],
+ add_help=False,
+ help='''View a patch'''
+ )
+ view_parser.set_defaults(subcmd='view')
+ update_parser = subparsers.add_parser(
+ 'update', parents=[hash_parser, help_parser],
+ add_help=False,
+ help='''Update patch''',
+ epilog='''Using a COMMIT-REF allows for only one ID to be specified''',
+ )
+ update_parser.add_argument(
+ '-c', metavar='COMMIT-REF',
+ help='''commit reference hash'''
+ )
+ update_parser.add_argument(
+ '-s', metavar='STATE',
+ required=True,
+ help='''Set patch state (e.g., 'Accepted', 'Superseded' etc.)'''
+ )
+ update_parser.set_defaults(subcmd='update')
+ list_parser = subparsers.add_parser("list",
+ add_help=False,
+ #aliases=['search'],
+ parents=[filter_parser, help_parser],
+ help='''List patches, using the optional filters specified
+ below and an optional substring to search for patches
+ by name'''
+ )
+ list_parser.set_defaults(subcmd='list')
+ search_parser = subparsers.add_parser("search",
+ add_help=False,
+ parents=[filter_parser, help_parser],
+ help='''Alias for "list"'''
+ )
+ # Poor man's argparse aliases:
+ # We register the "search" parser but effectively use "list" for the
+ # help-text.
+ search_parser.set_defaults(subcmd='list')