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 main(): az_cli = AzCli(cli_name='az', commands_loader_cls=MainCommandsLoader, invocation_cls=AzCliCommandInvoker, parser_cls=AzCliCommandParser, help_cls=AzCliHelp) create_invoker_and_load_cmds_and_args(az_cli) help_files = get_all_help(az_cli) high_command_set = set() for help_file in help_files: if help_file.command: high_command_set.add(help_file.command.split()[0]) print('high_command_set:') print(high_command_set) # Load and check service_name.json with open('src/azure-cli/service_name.json') as f: service_names = json.load(f) print('Verifying src/azure-cli/service_name.json') service_name_map = {} for service_name in service_names: command = service_name['Command'] service = service_name['AzureServiceName'] if not command.startswith('az '): raise Exception('{} does not start with az!'.format(command)) if not service: raise Exception('AzureServiceName of {} is empty!'.format(command)) service_name_map[command[3:]] = service print('service_name_map:') print(service_name_map) # Check existence in service_name.json for high_command in high_command_set: if high_command not in service_name_map: raise Exception( 'No entry of {} in service_name.json. Please add one to the file.' .format(high_command))
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): # 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 ''