From 8e92dfc2a56c47579c77276cd2c4ce43053603b6 Mon Sep 17 00:00:00 2001
From: Cedric Brandily <zzelle@gmail.com>
Date: Tue, 17 Mar 2015 23:44:53 +0100
Subject: [PATCH] Use cliff deferred help instead of homemade one

This change removes openstackclient homemade hack to defer help
printing in initialize_app and uses cliff (new) option to defer
help printing.

Change-Id: Ie3e94ec96254745bfef8c5ff5abc405facfe1bea
Related-Bug: #1316622
---
 openstackclient/shell.py | 35 +++--------------------------------
 1 file changed, 3 insertions(+), 32 deletions(-)

diff --git a/openstackclient/shell.py b/openstackclient/shell.py
index 3cfd731219..141dcd667b 100644
--- a/openstackclient/shell.py
+++ b/openstackclient/shell.py
@@ -76,7 +76,8 @@ class OpenStackShell(app.App):
         super(OpenStackShell, self).__init__(
             description=__doc__.strip(),
             version=openstackclient.__version__,
-            command_manager=commandmanager.CommandManager('openstack.cli'))
+            command_manager=commandmanager.CommandManager('openstack.cli'),
+            deferred_help=True)
 
         self.api_version = {}
 
@@ -92,35 +93,6 @@ class OpenStackShell(app.App):
 
         self.client_manager = None
 
-        # NOTE(dtroyer): This hack changes the help action that Cliff
-        #                automatically adds to the parser so we can defer
-        #                its execution until after the api-versioned commands
-        #                have been loaded.  There doesn't seem to be a
-        #                way to edit/remove anything from an existing parser.
-
-        # Replace the cliff-added help.HelpAction to defer its execution
-        self.DeferredHelpAction = None
-        for a in self.parser._actions:
-            if type(a) == help.HelpAction:
-                # Found it, save and replace it
-                self.DeferredHelpAction = a
-
-                # These steps are argparse-implementation-dependent
-                self.parser._actions.remove(a)
-                if self.parser._option_string_actions['-h']:
-                    del self.parser._option_string_actions['-h']
-                if self.parser._option_string_actions['--help']:
-                    del self.parser._option_string_actions['--help']
-
-                # Make a new help option to just set a flag
-                self.parser.add_argument(
-                    '-h', '--help',
-                    action='store_true',
-                    dest='deferred_help',
-                    default=False,
-                    help="Show this help message and exit",
-                )
-
     def configure_logging(self):
         """Configure logging for the app
 
@@ -276,8 +248,7 @@ class OpenStackShell(app.App):
         # set up additional clients to stuff in to client_manager??
 
         # Handle deferred help and exit
-        if self.options.deferred_help:
-            self.DeferredHelpAction(self.parser, self.parser, None, None)
+        self.print_help_if_requested()
 
         # Set up common client session
         if self.options.os_cacert: