pass in global group instead of global parser to global param handlers

This commit is contained in:
Burt Bielicki 2016-05-02 09:05:08 -07:00
Родитель 86a4ba4e54
Коммит aba66c0fb1
4 изменённых файлов: 8 добавлений и 14 удалений

Просмотреть файл

@ -210,9 +210,7 @@ class CommandHelpFile(HelpFile): #pylint: disable=too-few-public-methods
self.parameters.append(HelpParameter(' '.join(sorted(action.option_strings)),
action.help,
required=action.required,
global_param=action.container.description
== parser.get_global_group().description
or action.dest == 'help'))
global_param=self.is_global(action)))
def _load_from_data(self, data):
super(CommandHelpFile, self)._load_from_data(data)
@ -235,6 +233,9 @@ class CommandHelpFile(HelpFile): #pylint: disable=too-few-public-methods
raise HelpAuthoringException('Extra help param {0}'.format(extra_param['name']))
self.parameters = loaded_params
def is_global(self, action):
return action.container.description == 'global arguments' \
or action.dest == 'help'
class HelpParameter(object): #pylint: disable=too-few-public-methods
def __init__(self, param_name, description, required, global_param=False):

Просмотреть файл

@ -50,7 +50,8 @@ class Application(object):
azure.cli.extensions.register_extensions(self)
self.global_parser = AzCliCommandParser(prog='az', add_help=False)
self.raise_event(self.GLOBAL_PARSER_CREATED, self.global_parser)
global_group = self.global_parser.add_argument_group('global', 'global arguments')
self.raise_event(self.GLOBAL_PARSER_CREATED, global_group)
self.parser = AzCliCommandParser(prog='az', parents=[self.global_parser])
self.raise_event(self.COMMAND_PARSER_CREATED, self.parser)
@ -134,9 +135,7 @@ class Application(object):
argcomplete.autocomplete(parser)
@staticmethod
def _register_builtin_arguments(parser):
global_group = parser.get_global_group()
def _register_builtin_arguments(global_group):
global_group.add_argument('--subscription', dest='_subscription_id', help=argparse.SUPPRESS)
global_group.add_argument('--output', '-o', dest='_output_format',
choices=['list', 'json', 'tsv'],

Просмотреть файл

@ -1,8 +1,7 @@
import collections
def _register_global_parameter(parser):
def _register_global_parameter(global_group):
# Let the program know that we are adding a parameter --query
global_group = parser.get_global_group()
global_group.add_argument('--query', dest='_jmespath_query', metavar='JMESPATH',
help='JMESPath query string. See http://jmespath.org/ for more information and examples.') # pylint: disable=line-too-long

Просмотреть файл

@ -17,11 +17,6 @@ class AzCliCommandParser(argparse.ArgumentParser):
self.help_file = kwargs.pop('help_file', None)
super(AzCliCommandParser, self).__init__(**kwargs)
def get_global_group(self):
if len(self._action_groups) < 3:
self.add_argument_group('global', 'global arguments')
return self._action_groups[2]
def load_command_table(self, command_table):
"""Load a command table into our parser.
"""