Merge "Output subcommand help on argument errors"
This commit is contained in:
commit
2a433d9404
@ -97,10 +97,10 @@ class ZuulClient():
|
||||
return subparsers
|
||||
|
||||
def parseArguments(self, args=None):
|
||||
parser = self.createParser()
|
||||
self.args = parser.parse_args(args)
|
||||
self.parser = self.createParser()
|
||||
self.args = self.parser.parse_args(args)
|
||||
if not getattr(self.args, 'func', None):
|
||||
parser.print_help()
|
||||
self.parser.print_help()
|
||||
sys.exit(1)
|
||||
if self.args.func == self.enqueue_ref:
|
||||
# if oldrev or newrev is set, ensure they're not the same
|
||||
@ -144,12 +144,23 @@ class ZuulClient():
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
def _main(self, args=None):
|
||||
# TODO make func return specific return codes
|
||||
try:
|
||||
self.parseArguments(args)
|
||||
if not self.args.zuul_url:
|
||||
self.readConfig()
|
||||
self.setup_logging()
|
||||
# TODO make func return specific return codes
|
||||
if self.args.func():
|
||||
ret = self.args.func()
|
||||
except ArgumentException:
|
||||
if self.args.func:
|
||||
name = self.args.func.__name__
|
||||
parser = getattr(self, 'cmd_' + name, self.parser)
|
||||
else:
|
||||
parser = self.parser
|
||||
parser.print_help()
|
||||
print()
|
||||
raise
|
||||
if ret:
|
||||
return 0
|
||||
else:
|
||||
return 1
|
||||
@ -199,6 +210,7 @@ class ZuulClient():
|
||||
'(default: scheduler\'s default_hold_expiration value)'),
|
||||
required=False, type=int)
|
||||
cmd_autohold.set_defaults(func=self.autohold)
|
||||
self.cmd_autohold = cmd_autohold
|
||||
|
||||
def autohold(self):
|
||||
if self.args.change and self.args.ref:
|
||||
@ -229,6 +241,7 @@ class ZuulClient():
|
||||
required=False, default='')
|
||||
cmd_autohold_delete.add_argument('id', metavar='REQUEST_ID',
|
||||
help='the hold request ID')
|
||||
self.cmd_autohold_delete = cmd_autohold_delete
|
||||
|
||||
def autohold_delete(self):
|
||||
client = self.get_client()
|
||||
@ -243,6 +256,7 @@ class ZuulClient():
|
||||
required=False, default='')
|
||||
cmd_autohold_info.add_argument('id', metavar='REQUEST_ID',
|
||||
help='the hold request ID')
|
||||
self.cmd_autohold_info = cmd_autohold_info
|
||||
|
||||
def autohold_info(self):
|
||||
client = self.get_client()
|
||||
@ -273,6 +287,7 @@ class ZuulClient():
|
||||
cmd_autohold_list.add_argument('--tenant', help='tenant name',
|
||||
required=False, default='')
|
||||
cmd_autohold_list.set_defaults(func=self.autohold_list)
|
||||
self.cmd_autohold_list = cmd_autohold_list
|
||||
|
||||
def autohold_list(self):
|
||||
client = self.get_client()
|
||||
@ -314,6 +329,7 @@ class ZuulClient():
|
||||
cmd_enqueue.add_argument('--change', help='change id',
|
||||
required=True)
|
||||
cmd_enqueue.set_defaults(func=self.enqueue)
|
||||
self.cmd_enqueue = cmd_enqueue
|
||||
|
||||
def enqueue(self):
|
||||
client = self.get_client()
|
||||
@ -326,7 +342,7 @@ class ZuulClient():
|
||||
return r
|
||||
|
||||
def add_enqueue_ref_subparser(self, subparsers):
|
||||
cmd_enqueue = subparsers.add_parser(
|
||||
cmd_enqueue_ref = subparsers.add_parser(
|
||||
'enqueue-ref', help='enqueue a ref',
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
description=textwrap.dedent('''\
|
||||
@ -335,19 +351,20 @@ class ZuulClient():
|
||||
Directly enqueue a trigger event. This is usually used
|
||||
to manually "replay" a trigger received from an external
|
||||
source such as gerrit.'''))
|
||||
cmd_enqueue.add_argument('--tenant', help='tenant name',
|
||||
cmd_enqueue_ref.add_argument('--tenant', help='tenant name',
|
||||
required=False, default='')
|
||||
cmd_enqueue.add_argument('--pipeline', help='pipeline name',
|
||||
cmd_enqueue_ref.add_argument('--pipeline', help='pipeline name',
|
||||
required=True)
|
||||
cmd_enqueue.add_argument('--project', help='project name',
|
||||
cmd_enqueue_ref.add_argument('--project', help='project name',
|
||||
required=True)
|
||||
cmd_enqueue.add_argument('--ref', help='ref name',
|
||||
cmd_enqueue_ref.add_argument('--ref', help='ref name',
|
||||
required=True)
|
||||
cmd_enqueue.add_argument(
|
||||
cmd_enqueue_ref.add_argument(
|
||||
'--oldrev', help='old revision', default=None)
|
||||
cmd_enqueue.add_argument(
|
||||
cmd_enqueue_ref.add_argument(
|
||||
'--newrev', help='new revision', default=None)
|
||||
cmd_enqueue.set_defaults(func=self.enqueue_ref)
|
||||
cmd_enqueue_ref.set_defaults(func=self.enqueue_ref)
|
||||
self.cmd_enqueue_ref = cmd_enqueue_ref
|
||||
|
||||
def enqueue_ref(self):
|
||||
client = self.get_client()
|
||||
@ -376,6 +393,7 @@ class ZuulClient():
|
||||
cmd_dequeue.add_argument('--ref', help='ref name',
|
||||
default=None)
|
||||
cmd_dequeue.set_defaults(func=self.dequeue)
|
||||
self.cmd_dequeue = cmd_dequeue
|
||||
|
||||
def dequeue(self):
|
||||
client = self.get_client()
|
||||
@ -398,6 +416,7 @@ class ZuulClient():
|
||||
cmd_promote.add_argument('--changes', help='change ids',
|
||||
required=True, nargs='+')
|
||||
cmd_promote.set_defaults(func=self.promote)
|
||||
self.cmd_promote = cmd_promote
|
||||
|
||||
def promote(self):
|
||||
client = self.get_client()
|
||||
@ -485,6 +504,7 @@ class ZuulClient():
|
||||
'supplied, the value will be written '
|
||||
'to standard output.')
|
||||
cmd_encrypt.set_defaults(func=self.encrypt)
|
||||
self.cmd_encrypt = cmd_encrypt
|
||||
|
||||
def encrypt(self):
|
||||
if self.args.project is None and self.args.public_key is None:
|
||||
|
Loading…
Reference in New Issue
Block a user