зеркало из https://github.com/microsoft/azure-cli.git
print out all groups without special casing globals
This commit is contained in:
Родитель
4c044539b5
Коммит
fc99ddc5ec
|
@ -75,14 +75,16 @@ def print_arguments(help_file):
|
|||
required_tag = L(' [Required]')
|
||||
max_name_length = max(len(p.name) + (len(required_tag) if p.required else 0)
|
||||
for p in help_file.parameters)
|
||||
added_global_space = False
|
||||
last_group_name = None
|
||||
for p in sorted(help_file.parameters,
|
||||
key=lambda p: str(not p.required) + str(p.global_param) + p.name):
|
||||
key=lambda p: str(p.group_name or 'A') + str(not p.required) + p.name):
|
||||
indent = 1
|
||||
required_text = required_tag if p.required else ''
|
||||
if p.global_param and not added_global_space:
|
||||
print('\nGlobal Arguments')
|
||||
added_global_space = True
|
||||
if p.group_name != last_group_name:
|
||||
if p.group_name:
|
||||
print('')
|
||||
print(p.group_name)
|
||||
last_group_name = p.group_name
|
||||
_print_indent('{0}{1}{2}{3}'.format(p.name,
|
||||
_get_column_indent(p.name + required_text,
|
||||
max_name_length),
|
||||
|
@ -210,7 +212,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=self.is_global(action)))
|
||||
group_name=action.container.description))
|
||||
|
||||
def _load_from_data(self, data):
|
||||
super(CommandHelpFile, self)._load_from_data(data)
|
||||
|
@ -233,20 +235,16 @@ class CommandHelpFile(HelpFile): #pylint: disable=too-few-public-methods
|
|||
raise HelpAuthoringException('Extra help param {0}'.format(extra_param['name']))
|
||||
self.parameters = loaded_params
|
||||
|
||||
@staticmethod
|
||||
def is_global(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):
|
||||
def __init__(self, param_name, description, required, group_name=False):
|
||||
self.name = param_name
|
||||
self.required = required
|
||||
self.type = 'string'
|
||||
self.short_summary = description
|
||||
self.long_summary = ''
|
||||
self.value_sources = []
|
||||
self.global_param = global_param
|
||||
self.group_name = group_name
|
||||
|
||||
def update_from_data(self, data):
|
||||
if self.name != data.get('name'):
|
||||
|
|
|
@ -50,7 +50,7 @@ class Application(object):
|
|||
azure.cli.extensions.register_extensions(self)
|
||||
|
||||
self.global_parser = AzCliCommandParser(prog='az', add_help=False)
|
||||
global_group = self.global_parser.add_argument_group('global', 'global arguments')
|
||||
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])
|
||||
|
@ -143,9 +143,11 @@ class Application(object):
|
|||
# The arguments for verbosity don't get parsed by argparse but we add it here for help.
|
||||
global_group.add_argument('--verbose', dest='_log_verbosity_verbose',
|
||||
help='Increase logging verbosity.'
|
||||
' Use --debug for full debug logs.')
|
||||
' Use --debug for full debug logs.',
|
||||
action='store_true')
|
||||
global_group.add_argument('--debug', dest='_log_verbosity_debug',
|
||||
help='Increase logging verbosity to show all debug logs.')
|
||||
help='Increase logging verbosity to show all debug logs.',
|
||||
action='store_true')
|
||||
|
||||
def _handle_builtin_arguments(self, args):
|
||||
self.configuration.output_format = args._output_format #pylint: disable=protected-access
|
||||
|
|
Загрузка…
Ссылка в новой задаче