Merge pull request #200 from BurtBiel/help/ChoiceLists

Support displaying choice lists in help
This commit is contained in:
Burt Bielicki 2016-05-04 15:34:28 -07:00
Родитель af6bd59025 a23c1a3850
Коммит f94ef2f00d
3 изменённых файлов: 19 добавлений и 5 удалений

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

@ -78,6 +78,7 @@ def print_arguments(help_file):
for p in sorted(help_file.parameters, key=lambda p: str(not p.required) + p.name):
indent = 1
required_text = required_tag if p.required else ''
p.short_summary = (p.short_summary if p.short_summary else '') + _get_choices_str(p)
_print_indent('{0}{1}{2}{3}'.format(p.name,
_get_column_indent(p.name + required_text,
max_name_length),
@ -127,6 +128,14 @@ def _print_groups(help_file):
indent)
_print_indent('')
def _get_choices_str(p):
choice_str = ""
if p.choices:
choice_str = (' ' if p.short_summary else '') \
+ '[{}{}]'.format(', '.join(p.choices),
('; default: ' + p.default) if p.default else '')
return choice_str
def _print_examples(help_file):
indent = 0
_print_indent(L('Examples'), indent)
@ -207,7 +216,9 @@ class CommandHelpFile(HelpFile): #pylint: disable=too-few-public-methods
for action in [a for a in parser._actions if a.help != argparse.SUPPRESS]: # pylint: disable=protected-access
self.parameters.append(HelpParameter(' '.join(sorted(action.option_strings)),
action.help,
required=action.required))
required=action.required,
choices=action.choices,
default=action.default))
def _load_from_data(self, data):
super(CommandHelpFile, self)._load_from_data(data)
@ -231,14 +242,16 @@ class CommandHelpFile(HelpFile): #pylint: disable=too-few-public-methods
self.parameters = loaded_params
class HelpParameter(object): #pylint: disable=too-few-public-methods
def __init__(self, param_name, description, required):
class HelpParameter(object): #pylint: disable=too-few-public-methods, too-many-instance-attributes
def __init__(self, param_name, description, required, choices=None, default=None): #pylint: disable=too-many-arguments
self.name = param_name
self.required = required
self.type = 'string'
self.short_summary = description
self.long_summary = ''
self.value_sources = []
self.choices = choices
self.default = default
def update_from_data(self, data):
if self.name != data.get('name'):

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

@ -138,7 +138,8 @@ class Application(object):
parser.add_argument('--subscription', dest='_subscription_id', help=argparse.SUPPRESS)
parser.add_argument('--output', '-o', dest='_output_format',
choices=['list', 'json', 'tsv'],
help='Output format of type "list", "json" or "tsv"')
default='list',
help='Output format')
# The arguments for verbosity don't get parsed by argparse but we add it here for help.
parser.add_argument('--verbose', dest='_log_verbosity_verbose',
help='Increase logging verbosity. Use --debug for full debug logs.')

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

@ -303,7 +303,7 @@ blob_types_str = ' '.join(blob_types.keys())
@command_table.option(**PARAMETER_ALIASES['container_name'])
@command_table.option(**PARAMETER_ALIASES['blob_name'])
@command_table.option('--type', required=True, choices=blob_types.keys(),
help=L('type of blob to upload ({})'.format(blob_types_str)))
help=L('type of blob to upload'))
@command_table.option('--upload-from', required=True,
help=L('local path to upload from'))
@command_table.option_set(STORAGE_DATA_CLIENT_ARGS)