From 6999d779a880227f653826df8b1ca2e2cf1ba4ef Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Mon, 26 Aug 2019 12:18:10 -0400 Subject: [PATCH] make --help work properly for custom commands see: https://github.com/ansible/awx/issues/4559 --- awxkit/awxkit/cli/client.py | 3 +++ awxkit/awxkit/cli/resource.py | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/awxkit/awxkit/cli/client.py b/awxkit/awxkit/cli/client.py index 0c130c079e..7c4b7ba95a 100755 --- a/awxkit/awxkit/cli/client.py +++ b/awxkit/awxkit/cli/client.py @@ -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: diff --git a/awxkit/awxkit/cli/resource.py b/awxkit/awxkit/cli/resource.py index 318a4d180e..9cd963536b 100644 --- a/awxkit/awxkit/cli/resource.py +++ b/awxkit/awxkit/cli/resource.py @@ -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'),