mirror of
https://github.com/ansible/awx.git
synced 2026-01-10 15:32:07 -03:30
make --help work properly for custom commands
see: https://github.com/ansible/awx/issues/4559
This commit is contained in:
parent
e19035079e
commit
6999d779a8
@ -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:
|
||||
|
||||
@ -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'),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user