def clean_from_http_answer(http_answer): example = HelpExample() example.short_summary = http_answer['title'].strip() example.command = http_answer['snippet'].strip() if example.short_summary.startswith("az "): example.short_summary, example.command = example.command, example.short_summary example.short_summary = example.short_summary.split('\r\n')[0] elif '```azurecli\r\n' in example.command: start_index = example.command.index('```azurecli\r\n') + len('```azurecli\r\n') example.command = example.command[start_index:] example.command = example.command.replace('```', '').replace(example.short_summary, '').strip() example.command = re.sub(r'\[.*\]', '', example.command).strip() # Add a '\n' to comply with the existing examples format example.command = example.command + '\n' return example
def load_help_examples(self, help_obj): if help_obj.type == "command" and self._entry_data.get("examples"): help_obj.examples = [HelpExample(**ex) for ex in self._entry_data["examples"] if help_obj._should_include_example(ex)] # pylint: disable=line-too-long, protected-access