def generate_overview(self): help_output = self.cli.help() command_list = HelpParser().parse_help_overview(help_output) self.renderer.render_overview_page(command_list.grouped()) count = 1 for command in command_list.flat(): self.generate_command(command) count += 1 print("Generated pages for %s commands." % count)
def test_parse_help_argument_without_quotes(): assert HelpParser().parse_help_argument( '1. inputs (hex, required) serialized UTXOs to subtract.') == { 'name': 'inputs', 'type': 'hex, required', 'description': 'serialized UTXOs to subtract.' }
def test_parse_help_arguments_without_description(): assert HelpParser().parse_help_argument( '2. options (object, optional)') == { 'name': 'options', 'type': 'object, optional', 'description': '' }
def test_parse_help_argument_without_quotes(): assert HelpParser().parse_help_argument( '1. inputs (hex, required) some arg.') == { 'name': 'inputs', 'type': 'hex, required', 'description': 'some arg.' }
def test_parse_help_result_without_quotes(): assert HelpParser().parse_help_result('hex (string) some thing') == { 'format': 'table', 'name': 'hex', 'type': 'string', 'description': 'some thing' }
def test_parse_help_result_without_quotes(): assert HelpParser().parse_help_result( 'hex (string) the block hash hex encoded') == { 'format': 'table', 'name': 'hex', 'type': 'string', 'description': 'the block hash hex encoded' }
def show_removed(self, cli, markdown_dir): commands = HelpParser().parse_help_overview( CliCaller(cli).help()).flat() removed_commands = [] for markdown_file in os.listdir(markdown_dir): command = os.path.splitext(markdown_file)[0] if not command in commands: removed_commands.append(command) for command in sorted(removed_commands): print(command)
def test_process_command_help(): cmds = [ 'analyzepsbt', 'deriveaddresses', 'getblockstats', ] for cmd in cmds: with open(str(test_data_dir / cmd)) as file: input = file.read() help_data = HelpParser().parse_help_command(input) with open(str(test_data_dir / "rst" / (cmd + ".rst"))) as file: expected_output = file.read() assert RendererRst("").cmd_page(help_data) == expected_output
def test_check_and_set_json_level(): parser = HelpParser() def check(line, expected_json_level): parser.check_opening_json(line) assert parser.json_level == expected_json_level check(' x', 0) check(' {', 1) check(' [', 2) check(' []', 2) check(' {}', 2) check(' {},', 2) check(' [],', 2)
def process_command_help(input): help_data = HelpParser().parse_help(input) output = '``' + help_data["command"] + '``\n\n' output += help_data['description'] + '\n' if help_data['arguments']: number = 1 for argument in help_data['arguments']: title = 'Argument #' + str(number) + ' - ' + argument['name'] output += title + '\n' output += '~' * len(title) + '\n\n' output += '**Type:** ' + argument['type'] + '\n\n' if argument['description']: output += argument['description'] + '\n\n' if 'literal_description' in argument: output += '::\n\n' + argument['literal_description'] + '\n' number += 1 if help_data['results']: for result in help_data['results']: if result and 'format' in result: if result['format'] == 'table': full_title = "Result" if 'title_extension' in result: full_title += result['title_extension'] output += full_title + '\n' output += '~' * len(full_title) + '\n\n' output += table([result]) + '\n' elif result['format'] == 'literal': result_title = 'Result' if 'title_extension' in result: result_title += result['title_extension'] output += result_title + '\n' + '~' * \ len(result_title) + '\n\n::\n\n' + \ result['text'] + '\n' if help_data["examples"]: output += 'Examples\n~~~~~~~~\n\n' output += '\n.. highlight:: shell\n\n' text = '' for example_line in help_data['examples']: if example_line.startswith('> '): output += text + '::\n\n' output += ' ' + example_line[2:].rstrip() + '\n\n' text = '' else: text += example_line return output
def test_process_command_help(): cmds = [ 'abandontransaction', 'addmultisigaddress', 'addnode', 'getbestblockhash', 'getblock', 'gettxoutproof', 'pruneblockchain', 'getmemoryinfo', ] for cmd in cmds: with open(test_data_dir / cmd) as file: input = file.read() help_data = HelpParser().parse_help_command(input) with open(test_data_dir / (cmd + ".md")) as file: expected_output = file.read() assert RendererMarkdown("").process_command_help( help_data) == expected_output
def generate_command(self, command): print("Command %s" % command) command_output = self.cli.help(command) help_data = HelpParser().parse_help_command(command_output) self.renderer.render_cmd_page(command, help_data)
def update_references(self, cli, docs_dir): commands = HelpParser().parse_help_overview( CliCaller(cli).help()).flat() references = References(docs_dir) references.update(commands)
def show_missing(self, cli, annotations_file): commands = HelpParser().parse_help_overview( CliCaller(cli).help()).flat() annotations = Annotations(annotations_file) annotations.show_missing(commands)
def test_parse_help(): with open(test_data_dir / "examplecommand") as file: input = file.read() result = HelpParser().parse_help(input) assert result[ "command"] == 'examplecommand "arg" "object" ( "optional-arg" )' assert result[ "description"] == "Returns the hash of the best (tip) block in the longest blockchain.\n" assert len(result["arguments"]) == 8 assert result["arguments"][0] == { 'name': 'arg', 'type': 'string, required', 'description': 'An argument.' } assert result["arguments"][1] == { 'name': 'otherarg', 'type': 'string, required', 'description': 'Line one\n line two' } assert result["arguments"][2] == { 'name': 'object', 'type': 'array, required', 'description': 'Some data', 'literal_description': ' [ (array of json objects)\n' ' {\n' ' "key": "value", (type) desc\n' ' }\n' ' ,...\n' ' ]\n', } assert result["arguments"][3] == { 'name': 'optional-arg', 'type': 'string, optional', 'description': 'An optional argument.' } assert result["arguments"][4] == { 'name': 'options', 'type': 'json, optional', 'description': '', 'literal_description': ' {\n' ' "rescan": <false>, (xx) yy\n' ' }\n', } assert result["arguments"][5] == { 'name': 'commands', 'type': 'required', 'description': 'list of commands to send:\n' " {'cmd': 'END_PERMISSIONING'}\n" " {'cmd': 'ADD_TO_WHITELIST', 'payload': <keys>}", } assert result["arguments"][6] == { 'name': 'inputs', 'type': 'array', 'description': 'A json array', 'literal_description': ' [\n' ' {\n' ' "txid":"id", (s) id\n' ' [vout_index,...]\n' ' }\n' ' ,...\n' ' ]\n', } assert result["arguments"][7] == { 'name': 'outputs', 'type': 'object', 'description': 'a json object', 'literal_description': ' {\n' ' "address": x.xxx, (ns) a\n' ' "data": "hex" (s) data\n' ' ,...\n' ' }\n', } assert result["results"] == [{ 'format': 'table', 'title_extension': '', 'name': "hex", "type": "string", "description": "the block hash hex encoded" }] assert result["examples"] == [ "> unite-cli examplecommand foo", "> curl --user myusername --data-binary someargs" ]
def test_parse_help(): with open(test_data_dir / "examplecommand") as file: input = file.read() result = HelpParser().parse_help_command(input) assert result[ "command"] == 'examplecommand "arg" "object" ( "optional-arg" )' assert result["description"] == "Returns something.\n" assert len(result["arguments"]) == 7 assert result["arguments"][0] == { 'name': 'arg', 'type': 'string, required', 'description': 'An argument.' } assert result["arguments"][1] == { 'name': 'otherarg', 'type': 'string, required', 'description': 'Line one\n line two' } assert result["arguments"][2] == { 'name': 'object', 'type': 'array, required', 'description': 'Some data', 'literal_description': ' [ (array of json objects)\n' ' {\n' ' "key": "value", (type) desc\n' ' }\n' ' ,...\n' ' ]\n', } assert result["arguments"][3] == { 'name': 'optional-arg', 'type': 'string, optional', 'description': 'An optional argument.' } assert result["arguments"][4] == { 'name': 'options', 'type': 'json, optional', 'description': '', 'literal_description': ' {\n' ' "rescan": <false>, (xx) yy\n' ' }\n', } assert result["arguments"][5] == { 'name': 'inputs', 'type': 'array', 'description': 'A json array', 'literal_description': ' [\n' ' {\n' ' "txid":"id", (s) id\n' ' [vout_index,...]\n' ' }\n' ' ,...\n' ' ]\n', } assert result["arguments"][6] == { 'name': 'outputs', 'type': 'object', 'description': 'a json object', 'literal_description': ' {\n' ' "address": x.xxx, (ns) a\n' ' "data": "hex" (s) data\n' ' ,...\n' ' }\n', } assert result["results"] == [{ 'format': 'table', 'title_extension': '', 'name': "hex", "type": "string", "description": "the result, hex encoded" }] assert result["examples"] == [ "> bitcoin-cli examplecommand foo", "> curl --user myusername --data-binary someargs" ]