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