def make_rst(self): INDENT = ' ' DOUBLEINDENT = INDENT * 2 az_cli = AzCli(cli_name='az', commands_loader_cls=MainCommandsLoader, invocation_cls=AzCliCommandInvoker, parser_cls=AzCliCommandParser, help_cls=AzCliHelp) help_files = get_help_files(az_cli) doc_source_map = _load_doc_source_map() for help_file in help_files: is_command = isinstance(help_file, CliCommandHelpFile) yield '.. cli{}:: {}'.format('command' if is_command else 'group', help_file.command if help_file.command else 'az') #it is top level group az if command is empty yield '' yield '{}:summary: {}'.format(INDENT, help_file.short_summary) yield '{}:description: {}'.format(INDENT, help_file.long_summary) if not is_command: top_group_name = help_file.command.split()[0] if help_file.command else 'az' yield '{}:docsource: {}'.format(INDENT, doc_source_map[top_group_name] if top_group_name in doc_source_map else '') else: top_command_name = help_file.command.split()[0] if help_file.command else '' if top_command_name in doc_source_map: yield '{}:docsource: {}'.format(INDENT, doc_source_map[top_command_name]) yield '' if is_command and help_file.parameters: group_registry = ArgumentGroupRegistry( [p.group_name for p in help_file.parameters if p.group_name]) for arg in sorted(help_file.parameters, key=lambda p: group_registry.get_group_priority(p.group_name) + str(not p.required) + p.name): yield '{}.. cliarg:: {}'.format(INDENT, arg.name) yield '' yield '{}:required: {}'.format(DOUBLEINDENT, arg.required) short_summary = arg.short_summary or '' possible_values_index = short_summary.find(' Possible values include') short_summary = short_summary[0:possible_values_index if possible_values_index >= 0 else len(short_summary)] short_summary = short_summary.strip() yield '{}:summary: {}'.format(DOUBLEINDENT, short_summary) yield '{}:description: {}'.format(DOUBLEINDENT, arg.long_summary) if arg.choices: yield '{}:values: {}'.format(DOUBLEINDENT, ', '.join(sorted([str(x) for x in arg.choices]))) if arg.default and arg.default != argparse.SUPPRESS: yield '{}:default: {}'.format(DOUBLEINDENT, arg.default) if arg.value_sources: yield '{}:source: {}'.format(DOUBLEINDENT, ', '.join(arg.value_sources)) yield '' yield '' if len(help_file.examples) > 0: for e in help_file.examples: yield '{}.. cliexample:: {}'.format(INDENT, e.name) yield '' yield DOUBLEINDENT + e.text yield ''
def test_help_argument_group_registry(self): groups = [ 'Resource Id Arguments', 'Z Arguments', 'B Arguments', 'Global Arguments', 'A Arguments', 'Generic Update Arguments', 'Resource Id Arguments' ] group_registry = ArgumentGroupRegistry(groups) self.assertEqual(group_registry.get_group_priority('A Arguments'), '000002') self.assertEqual(group_registry.get_group_priority('B Arguments'), '000003') self.assertEqual(group_registry.get_group_priority('Z Arguments'), '000004') self.assertEqual(group_registry.get_group_priority('Resource Id Arguments'), '000001') self.assertEqual(group_registry.get_group_priority('Generic Update Arguments'), '000998') self.assertEqual(group_registry.get_group_priority('Global Arguments'), '001000')
def test_help_argument_group_registry(self): groups = [ "Resource Id Arguments", "Z Arguments", "B Arguments", "Global Arguments", "A Arguments", "Generic Update Arguments", "Resource Id Arguments", ] group_registry = ArgumentGroupRegistry(groups) self.assertEqual(group_registry.get_group_priority("A Arguments"), "000002") self.assertEqual(group_registry.get_group_priority("B Arguments"), "000003") self.assertEqual(group_registry.get_group_priority("Z Arguments"), "000004") self.assertEqual(group_registry.get_group_priority("Resource Id Arguments"), "000001") self.assertEqual(group_registry.get_group_priority("Generic Update Arguments"), "000998") self.assertEqual(group_registry.get_group_priority("Global Arguments"), "001000")
def make_rst(self): INDENT = ' ' DOUBLEINDENT = INDENT * 2 az_cli = AzCli(cli_name='az', commands_loader_cls=MainCommandsLoader, invocation_cls=AzCliCommandInvoker, parser_cls=AzCliCommandParser, help_cls=AzCliHelp) help_files = get_extension_help_files(az_cli) for help_file in help_files: is_command = isinstance(help_file, CliCommandHelpFile) yield '.. cli{}:: {}'.format( 'command' if is_command else 'group', help_file.command if help_file.command else 'az') #it is top level group az if command is empty yield '' yield '{}:summary: {}'.format(INDENT, help_file.short_summary) yield '{}:description: {}'.format(INDENT, help_file.long_summary) if help_file.deprecate_info: yield '{}:deprecated: {}'.format( INDENT, help_file.deprecate_info._get_message( help_file.deprecate_info)) yield '' if is_command and help_file.parameters: group_registry = ArgumentGroupRegistry([ p.group_name for p in help_file.parameters if p.group_name ]) for arg in sorted( help_file.parameters, key=lambda p: group_registry.get_group_priority( p.group_name) + str(not p.required) + p.name): yield '{}.. cliarg:: {}'.format(INDENT, arg.name) yield '' yield '{}:required: {}'.format(DOUBLEINDENT, arg.required) if arg.deprecate_info: yield '{}:deprecated: {}'.format( DOUBLEINDENT, arg.deprecate_info._get_message( arg.deprecate_info)) short_summary = arg.short_summary or '' possible_values_index = short_summary.find( ' Possible values include') short_summary = short_summary[ 0:possible_values_index if possible_values_index >= 0 else len(short_summary)] short_summary = short_summary.strip() yield '{}:summary: {}'.format(DOUBLEINDENT, short_summary) yield '{}:description: {}'.format(DOUBLEINDENT, arg.long_summary) if arg.choices: yield '{}:values: {}'.format( DOUBLEINDENT, ', '.join(sorted([str(x) for x in arg.choices]))) if arg.default and arg.default != argparse.SUPPRESS: try: if arg.default.startswith(USER_HOME): arg.default = arg.default.replace( USER_HOME, '~').replace('\\', '/') except Exception: pass try: arg.default = arg.default.replace("\\", "\\\\") except Exception: pass yield '{}:default: {}'.format(DOUBLEINDENT, arg.default) if arg.value_sources: yield '{}:source: {}'.format( DOUBLEINDENT, ', '.join(arg.value_sources)) yield '' yield '' if len(help_file.examples) > 0: for e in help_file.examples: yield '{}.. cliexample:: {}'.format(INDENT, e.name) yield '' yield DOUBLEINDENT + e.text.replace("\\", "\\\\") yield ''
def make_rst(self): INDENT = ' ' DOUBLEINDENT = INDENT * 2 az_cli = AzCli(cli_name='az', commands_loader_cls=MainCommandsLoader, invocation_cls=AzCliCommandInvoker, parser_cls=AzCliCommandParser, help_cls=AzCliHelp) with patch('getpass.getuser', return_value='your_system_user_login_name'): create_invoker_and_load_cmds_and_args(az_cli) help_files = get_all_help(az_cli) doc_source_map = _load_doc_source_map() for help_file in help_files: is_command = isinstance(help_file, CliCommandHelpFile) yield '.. cli{}:: {}'.format('command' if is_command else 'group', help_file.command if help_file.command else 'az') #it is top level group az if command is empty yield '' yield '{}:summary: {}'.format(INDENT, help_file.short_summary) yield '{}:description: {}'.format(INDENT, help_file.long_summary) if help_file.deprecate_info: yield '{}:deprecated: {}'.format(INDENT, help_file.deprecate_info._get_message(help_file.deprecate_info)) if not is_command: top_group_name = help_file.command.split()[0] if help_file.command else 'az' yield '{}:docsource: {}'.format(INDENT, doc_source_map[top_group_name] if top_group_name in doc_source_map else '') else: top_command_name = help_file.command.split()[0] if help_file.command else '' if top_command_name in doc_source_map: yield '{}:docsource: {}'.format(INDENT, doc_source_map[top_command_name]) yield '' if is_command and help_file.parameters: group_registry = ArgumentGroupRegistry( [p.group_name for p in help_file.parameters if p.group_name]) for arg in sorted(help_file.parameters, key=lambda p: group_registry.get_group_priority(p.group_name) + str(not p.required) + p.name): yield '{}.. cliarg:: {}'.format(INDENT, arg.name) yield '' yield '{}:required: {}'.format(DOUBLEINDENT, arg.required) if arg.deprecate_info: yield '{}:deprecated: {}'.format(DOUBLEINDENT, arg.deprecate_info._get_message(arg.deprecate_info)) short_summary = arg.short_summary or '' possible_values_index = short_summary.find(' Possible values include') short_summary = short_summary[0:possible_values_index if possible_values_index >= 0 else len(short_summary)] short_summary = short_summary.strip() yield '{}:summary: {}'.format(DOUBLEINDENT, short_summary) yield '{}:description: {}'.format(DOUBLEINDENT, arg.long_summary) if arg.choices: yield '{}:values: {}'.format(DOUBLEINDENT, ', '.join(sorted([str(x) for x in arg.choices]))) if arg.default and arg.default != argparse.SUPPRESS: try: if arg.default.startswith(USER_HOME): arg.default = arg.default.replace(USER_HOME, '~').replace('\\', '/') except Exception: pass try: arg.default = arg.default.replace("\\", "\\\\") except Exception: pass yield '{}:default: {}'.format(DOUBLEINDENT, arg.default) if arg.value_sources: yield '{}:source: {}'.format(DOUBLEINDENT, ', '.join(_get_populator_commands(arg))) yield '' yield '' if len(help_file.examples) > 0: for e in help_file.examples: yield '{}.. cliexample:: {}'.format(INDENT, e.short_summary) yield '' yield DOUBLEINDENT + e.command.replace("\\", "\\\\") yield ''
def make_rst(self): # pylint: disable=too-many-statements, too-many-nested-blocks az_cli = AzCli(cli_name='az', commands_loader_cls=MainCommandsLoader, invocation_cls=AzCliCommandInvoker, parser_cls=AzCliCommandParser, help_cls=AzCliHelp) with patch('getpass.getuser', return_value='your_system_user_login_name'): help_files = self._get_help_files(az_cli) doc_source_map = self._load_doc_source_map() group_registry = None for help_file in help_files: # pylint: disable=too-many-nested-blocks is_command = isinstance(help_file, CliCommandHelpFile) # it is top level group az if command is empty yield '.. cli{}:: {}'.format( 'command' if is_command else 'group', help_file.command if help_file.command else 'az') yield '' yield '{}:summary: {}'.format(self._INDENT, help_file.short_summary) yield '{}:description: {}'.format(self._INDENT, help_file.long_summary) if help_file.deprecate_info: yield '{}:deprecated: {}'.format( self._INDENT, help_file.deprecate_info._get_message( help_file.deprecate_info)) # pylint: disable=protected-access doc_source_content = self._get_doc_source_content( doc_source_map, help_file) if doc_source_content: yield doc_source_content yield '' if is_command and help_file.parameters: group_registry = ArgumentGroupRegistry([ p.group_name for p in help_file.parameters if p.group_name ]) for arg in sorted(help_file.parameters, key=lambda p: group_registry.get_group_priority(p.group_name) + str(not p.required) + p.name): # pylint: disable=line-too-long yield '{}.. cliarg:: {}'.format(self._INDENT, arg.name) yield '' yield '{}:required: {}'.format(self._DOUBLE_INDENT, arg.required) if arg.deprecate_info: yield '{}:deprecated: {}'.format( self._DOUBLE_INDENT, arg.deprecate_info._get_message( # pylint: disable=protected-access arg.deprecate_info)) short_summary = arg.short_summary or '' possible_values_index = short_summary.find( ' Possible values include') short_summary_end_idx = possible_values_index if possible_values_index >= 0 else len( short_summary) short_summary = short_summary[0:short_summary_end_idx] short_summary = short_summary.strip() yield '{}:summary: {}'.format(self._DOUBLE_INDENT, short_summary) yield '{}:description: {}'.format(self._DOUBLE_INDENT, arg.long_summary) if arg.choices: yield '{}:values: {}'.format( self._DOUBLE_INDENT, ', '.join(sorted([str(x) for x in arg.choices]))) if arg.default and arg.default != argparse.SUPPRESS: try: if arg.default.startswith(_USER_HOME): arg.default = arg.default.replace( _USER_HOME, '~').replace('\\', '/') except Exception: # pylint: disable=broad-except pass try: arg.default = arg.default.replace("\\", "\\\\") except Exception: # pylint: disable=broad-except pass yield '{}:default: {}'.format(self._DOUBLE_INDENT, arg.default) if arg.value_sources: yield '{}:source: {}'.format( self._DOUBLE_INDENT, ', '.join(self._get_param_value_sources(arg))) yield '' yield '' if help_file.examples: for e in help_file.examples: yield '{}.. cliexample:: {}'.format( self._INDENT, e.short_summary) yield '' yield self._DOUBLE_INDENT + e.command.replace("\\", "\\\\") yield ''