def find_page(command): """Find the command man page in the pages directory.""" repo_directory = get_config()['repo_directory'] default_platform = get_config()['platform'] with io.open(path.join(repo_directory, 'pages/index.json'), encoding='utf-8') as f: index = json.load(f) command_list = [item['name'] for item in index['commands']] if command not in command_list: sys.exit( ("Sorry, we don't support command: {0} right now.\n" "You can file an issue or send a PR on github:\n" " https://github.com/tldr-pages/tldr").format(command)) supported_platforms = index['commands'][ command_list.index(command)]['platform'] if default_platform in supported_platforms: platform = default_platform elif 'common' in supported_platforms: platform = 'common' else: platform = '' if not platform: sys.exit( ("Sorry, command {0} is not supported on your platform.\n" "You can file an issue or send a PR on github:\n" " https://github.com/tldr-pages/tldr").format(command)) page_path = path.join(path.join(repo_directory, 'pages'), path.join(platform, command + '.md')) output_lines = parse_page(page_path) click.echo(''.join(output_lines))
def find_page(command): """Find the command man page in the pages directory.""" repo_directory = get_config()['repo_directory'] default_platform = get_config()['platform'] with io.open(path.join(repo_directory, 'pages/index.json'), encoding='utf-8') as f: index = json.load(f) command_list = [item['name'] for item in index['commands']] if command not in command_list: sys.exit(("Sorry, we don't support command: {0} right now.\n" "You can file an issue or send a PR on github:\n" " https://github.com/tldr-pages/tldr").format(command)) supported_platforms = index['commands'][command_list.index( command)]['platform'] if default_platform in supported_platforms: platform = default_platform elif 'common' in supported_platforms: platform = 'common' else: platform = '' if not platform: sys.exit(("Sorry, command {0} is not supported on your platform.\n" "You can file an issue or send a PR on github:\n" " https://github.com/tldr-pages/tldr").format(command)) page_path = path.join(path.join(repo_directory, 'pages'), path.join(platform, command + '.md')) output_lines = parse_page(page_path) click.echo(''.join(output_lines))
def _assert_mock_read(self, page_content): mock_config = { 'colors': { 'command': 'cyan', 'description': 'blue', 'usage': 'green' }, 'platform': 'linux', 'repo_directory': '/tmp/tldr' } expected_result = ( '\n' '\x1b[0m\x1b[34m Main node command\n' '\x1b[0m\n\x1b[0m\x1b[32m- Call an interactive node shell' '\n\x1b[0m\n\x1b[0m\x1b[36m node\n' '\x1b[0m\n\x1b[0m\x1b[32m- Execute node on a JS file\n' '\x1b[0m\n\x1b[0m\x1b[36m node {{FILENAME}}.js\n' '\x1b[0m\n\x1b[0m' ) with mock.patch('tldr.parser.get_config', return_value=mock_config): with mock.patch('io.open', mock.mock_open(read_data=page_content)): result = parse_page('/repo_directory/pages/common/node.md') assert ''.join(result) == expected_result
def parse_man_page(command): """Parse the man page and return the parsed lines.""" page_path = find_page_location(command) output_lines = parse_page(page_path) return output_lines