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
This commit is contained in:
		| @@ -76,7 +76,8 @@ class OpenStackShell(app.App): | |||||||
|         super(OpenStackShell, self).__init__( |         super(OpenStackShell, self).__init__( | ||||||
|             description=__doc__.strip(), |             description=__doc__.strip(), | ||||||
|             version=openstackclient.__version__, |             version=openstackclient.__version__, | ||||||
|             command_manager=commandmanager.CommandManager('openstack.cli')) |             command_manager=commandmanager.CommandManager('openstack.cli'), | ||||||
|  |             deferred_help=True) | ||||||
|  |  | ||||||
|         self.api_version = {} |         self.api_version = {} | ||||||
|  |  | ||||||
| @@ -92,35 +93,6 @@ class OpenStackShell(app.App): | |||||||
|  |  | ||||||
|         self.client_manager = None |         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): |     def configure_logging(self): | ||||||
|         """Configure logging for the app |         """Configure logging for the app | ||||||
|  |  | ||||||
| @@ -276,8 +248,7 @@ class OpenStackShell(app.App): | |||||||
|         # set up additional clients to stuff in to client_manager?? |         # set up additional clients to stuff in to client_manager?? | ||||||
|  |  | ||||||
|         # Handle deferred help and exit |         # Handle deferred help and exit | ||||||
|         if self.options.deferred_help: |         self.print_help_if_requested() | ||||||
|             self.DeferredHelpAction(self.parser, self.parser, None, None) |  | ||||||
|  |  | ||||||
|         # Set up common client session |         # Set up common client session | ||||||
|         if self.options.os_cacert: |         if self.options.os_cacert: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Cedric Brandily
					Cedric Brandily