mirror of
https://github.com/ansible/awx.git
synced 2026-05-11 11:27:36 -02:30
make --help work properly for custom commands
see: https://github.com/ansible/awx/issues/4559
This commit is contained in:
@@ -152,6 +152,9 @@ class CLI(object):
|
|||||||
# control resources are special endpoints that you can only
|
# control resources are special endpoints that you can only
|
||||||
# do an HTTP GET to, and which return plain JSON metadata
|
# do an HTTP GET to, and which return plain JSON metadata
|
||||||
# examples are `/api/v2/ping/`, `/api/v2/config/`, etc...
|
# examples are `/api/v2/ping/`, `/api/v2/config/`, etc...
|
||||||
|
if self.help:
|
||||||
|
self.subparsers[self.resource].print_help()
|
||||||
|
raise SystemExit()
|
||||||
self.method = 'get'
|
self.method = 'get'
|
||||||
response = getattr(resource, self.method)()
|
response = getattr(resource, self.method)()
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -68,6 +68,10 @@ class Login(CustomCommand):
|
|||||||
name = 'login'
|
name = 'login'
|
||||||
help_text = 'authenticate and retrieve an OAuth2 token'
|
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):
|
def handle(self, client, parser):
|
||||||
auth = parser.add_argument_group('OAuth2.0 Options')
|
auth = parser.add_argument_group('OAuth2.0 Options')
|
||||||
auth.add_argument('--conf.client_id', metavar='TEXT')
|
auth.add_argument('--conf.client_id', metavar='TEXT')
|
||||||
@@ -75,6 +79,9 @@ class Login(CustomCommand):
|
|||||||
auth.add_argument(
|
auth.add_argument(
|
||||||
'--conf.scope', choices=['read', 'write'], default='write'
|
'--conf.scope', choices=['read', 'write'], default='write'
|
||||||
)
|
)
|
||||||
|
if client.help:
|
||||||
|
self.print_help(parser)
|
||||||
|
raise SystemExit()
|
||||||
parsed = parser.parse_known_args()[0]
|
parsed = parser.parse_known_args()[0]
|
||||||
kwargs = {
|
kwargs = {
|
||||||
'client_id': getattr(parsed, 'conf.client_id', None),
|
'client_id': getattr(parsed, 'conf.client_id', None),
|
||||||
@@ -84,8 +91,7 @@ class Login(CustomCommand):
|
|||||||
try:
|
try:
|
||||||
token = api.Api().get_oauth2_token(**kwargs)
|
token = api.Api().get_oauth2_token(**kwargs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
add_authentication_arguments(parser, os.environ)
|
self.print_help(parser)
|
||||||
parser.print_help()
|
|
||||||
cprint(
|
cprint(
|
||||||
'Error retrieving an OAuth2.0 token ({}).'.format(e.__class__),
|
'Error retrieving an OAuth2.0 token ({}).'.format(e.__class__),
|
||||||
'red'
|
'red'
|
||||||
@@ -99,6 +105,9 @@ class Config(CustomCommand):
|
|||||||
help_text = 'print current configuration values'
|
help_text = 'print current configuration values'
|
||||||
|
|
||||||
def handle(self, client, parser):
|
def handle(self, client, parser):
|
||||||
|
if client.help:
|
||||||
|
parser.print_help()
|
||||||
|
raise SystemExit()
|
||||||
return {
|
return {
|
||||||
'base_url': config.base_url,
|
'base_url': config.base_url,
|
||||||
'token': client.get_config('token'),
|
'token': client.get_config('token'),
|
||||||
|
|||||||
Reference in New Issue
Block a user