Skip to content

Commit 8e92dfc

Browse files
committed
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
1 parent a8c4407 commit 8e92dfc

1 file changed

Lines changed: 3 additions & 32 deletions

File tree

‎openstackclient/shell.py‎

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ def __init__(self):
7676
super(OpenStackShell, self).__init__(
7777
description=__doc__.strip(),
7878
version=openstackclient.__version__,
79-
command_manager=commandmanager.CommandManager('openstack.cli'))
79+
command_manager=commandmanager.CommandManager('openstack.cli'),
80+
deferred_help=True)
8081

8182
self.api_version = {}
8283

@@ -92,35 +93,6 @@ def __init__(self):
9293

9394
self.client_manager = None
9495

95-
# NOTE(dtroyer): This hack changes the help action that Cliff
96-
# automatically adds to the parser so we can defer
97-
# its execution until after the api-versioned commands
98-
# have been loaded. There doesn't seem to be a
99-
# way to edit/remove anything from an existing parser.
100-
101-
# Replace the cliff-added help.HelpAction to defer its execution
102-
self.DeferredHelpAction = None
103-
for a in self.parser._actions:
104-
if type(a) == help.HelpAction:
105-
# Found it, save and replace it
106-
self.DeferredHelpAction = a
107-
108-
# These steps are argparse-implementation-dependent
109-
self.parser._actions.remove(a)
110-
if self.parser._option_string_actions['-h']:
111-
del self.parser._option_string_actions['-h']
112-
if self.parser._option_string_actions['--help']:
113-
del self.parser._option_string_actions['--help']
114-
115-
# Make a new help option to just set a flag
116-
self.parser.add_argument(
117-
'-h', '--help',
118-
action='store_true',
119-
dest='deferred_help',
120-
default=False,
121-
help="Show this help message and exit",
122-
)
123-
12496
def configure_logging(self):
12597
"""Configure logging for the app
12698
@@ -276,8 +248,7 @@ def initialize_app(self, argv):
276248
# set up additional clients to stuff in to client_manager??
277249

278250
# Handle deferred help and exit
279-
if self.options.deferred_help:
280-
self.DeferredHelpAction(self.parser, self.parser, None, None)
251+
self.print_help_if_requested()
281252

282253
# Set up common client session
283254
if self.options.os_cacert:

0 commit comments

Comments
 (0)