make --help work properly for custom commands

see: https://github.com/ansible/awx/issues/4559
This commit is contained in:
Ryan Petrello 2019-08-26 12:18:10 -04:00
parent e19035079e
commit 6999d779a8
No known key found for this signature in database
GPG Key ID: F2AA5F2122351777
2 changed files with 14 additions and 2 deletions

View File

@ -152,6 +152,9 @@ class CLI(object):
# control resources are special endpoints that you can only
# do an HTTP GET to, and which return plain JSON metadata
# examples are `/api/v2/ping/`, `/api/v2/config/`, etc...
if self.help:
self.subparsers[self.resource].print_help()
raise SystemExit()
self.method = 'get'
response = getattr(resource, self.method)()
else:

View File

@ -68,6 +68,10 @@ class Login(CustomCommand):
name = 'login'
help_text = 'authenticate and retrieve an OAuth2 token'
def print_help(self, parser):
add_authentication_arguments(parser, os.environ)
parser.print_help()
def handle(self, client, parser):
auth = parser.add_argument_group('OAuth2.0 Options')
auth.add_argument('--conf.client_id', metavar='TEXT')
@ -75,6 +79,9 @@ class Login(CustomCommand):
auth.add_argument(
'--conf.scope', choices=['read', 'write'], default='write'
)
if client.help:
self.print_help(parser)
raise SystemExit()
parsed = parser.parse_known_args()[0]
kwargs = {
'client_id': getattr(parsed, 'conf.client_id', None),
@ -84,8 +91,7 @@ class Login(CustomCommand):
try:
token = api.Api().get_oauth2_token(**kwargs)
except Exception as e:
add_authentication_arguments(parser, os.environ)
parser.print_help()
self.print_help(parser)
cprint(
'Error retrieving an OAuth2.0 token ({}).'.format(e.__class__),
'red'
@ -99,6 +105,9 @@ class Config(CustomCommand):
help_text = 'print current configuration values'
def handle(self, client, parser):
if client.help:
parser.print_help()
raise SystemExit()
return {
'base_url': config.base_url,
'token': client.get_config('token'),