def generate_calibredb_help(preamble, app): from calibre.library.cli import COMMANDS, get_parser import calibre.library.cli as cli preamble = preamble[:preamble.find('\n\n\n', preamble.find('code-block'))] preamble += textwrap.dedent(''' :command:`calibredb` is the command line interface to the calibre database. It has several sub-commands, documented below: ''') global_parser = get_parser('') groups = [] for grp in global_parser.option_groups: groups.append((titlecase(app, grp.title), grp.description, grp.option_list)) global_options = '\n'.join( render_options('calibredb', groups, False, False)) lines = [] for cmd in COMMANDS: args = [] if cmd == 'catalog': args = [['doc.xml', '-h']] parser = getattr(cli, cmd + '_option_parser')(*args) if cmd == 'catalog': parser = parser[0] lines += ['.. _calibredb-%s-%s:' % (app.config.language, cmd), ''] lines += [cmd, '~' * 20, ''] usage = parser.usage.strip() usage = [i for i in usage.replace('%prog', 'calibredb').splitlines()] cmdline = ' ' + usage[0] usage = usage[1:] usage = [ re.sub(r'(%s)([^a-zA-Z0-9])' % cmd, r':command:`\1`\2', i) for i in usage ] lines += ['.. code-block:: none', '', cmdline, ''] lines += usage groups = [(None, None, parser.option_list)] lines += [''] lines += render_options('calibredb ' + cmd, groups, False) lines += [''] for group in parser.option_groups: if not getattr(group, 'is_global_options', False): lines.extend( render_options('calibredb_' + cmd, [[ titlecase(app, group.title), group.description, group.option_list ]], False, False, header_level='^')) lines += [''] raw = preamble + '\n\n' + '.. contents::\n :local:' + '\n\n' + global_options + '\n\n' + '\n'.join( lines) update_cli_doc('calibredb', raw, app)
def generate_calibredb_help(preamble, app): from calibre.library.cli import COMMANDS, get_parser import calibre.library.cli as cli preamble = preamble[:preamble.find('\n\n\n', preamble.find('code-block'))] preamble += textwrap.dedent(''' :command:`calibredb` is the command line interface to the |app| database. It has several sub-commands, documented below: ''') global_parser = get_parser('') groups = [] for grp in global_parser.option_groups: groups.append( (grp.title.capitalize(), grp.description, grp.option_list)) global_options = '\n'.join( render_options('calibredb', groups, False, False)) lines, toc = [], [] for cmd in COMMANDS: args = [] if cmd == 'catalog': args = [['doc.xml', '-h']] parser = getattr(cli, cmd + '_option_parser')(*args) if cmd == 'catalog': parser = parser[0] toc.append(' * :ref:`calibredb-%s`' % cmd) lines += ['.. _calibredb-' + cmd + ':', ''] lines += [cmd, '~' * 20, ''] usage = parser.usage.strip() usage = [i for i in usage.replace('%prog', 'calibredb').splitlines()] cmdline = ' ' + usage[0] usage = usage[1:] usage = [ re.sub(r'(%s)([^a-zA-Z0-9])' % cmd, r':command:`\1`\2', i) for i in usage ] lines += ['.. code-block:: none', '', cmdline, ''] lines += usage groups = [(None, None, parser.option_list)] lines += [''] lines += render_options('calibredb ' + cmd, groups, False) lines += [''] toc = '\n'.join(toc) raw = preamble + '\n\n' + toc + '\n\n' + global_options + '\n\n' + '\n'.join( lines) update_cli_doc('calibredb', raw, app)
def generate_calibredb_help(preamble, app): from calibre.library.cli import COMMANDS, get_parser import calibre.library.cli as cli preamble = preamble[:preamble.find('\n\n\n', preamble.find('code-block'))] preamble += textwrap.dedent(''' :command:`calibredb` is the command line interface to the calibre database. It has several sub-commands, documented below: ''') global_parser = get_parser('') groups = [] for grp in global_parser.option_groups: groups.append((titlecase(app, grp.title), grp.description, grp.option_list)) global_options = '\n'.join(render_options('calibredb', groups, False, False)) lines = [] for cmd in COMMANDS: args = [] if cmd == 'catalog': args = [['doc.xml', '-h']] parser = getattr(cli, cmd+'_option_parser')(*args) if cmd == 'catalog': parser = parser[0] lines += ['.. _calibredb-%s-%s:' % (app.config.language, cmd), ''] lines += [cmd, '~'*20, ''] usage = parser.usage.strip() usage = [i for i in usage.replace('%prog', 'calibredb').splitlines()] cmdline = ' '+usage[0] usage = usage[1:] usage = [re.sub(r'(%s)([^a-zA-Z0-9])'%cmd, r':command:`\1`\2', i) for i in usage] lines += ['.. code-block:: none', '', cmdline, ''] lines += usage groups = [(None, None, parser.option_list)] lines += [''] lines += render_options('calibredb '+cmd, groups, False) lines += [''] for group in parser.option_groups: if not getattr(group, 'is_global_options', False): lines.extend(render_options( 'calibredb_' + cmd, [[titlecase(app, group.title), group.description, group.option_list]], False, False, header_level='^')) lines += [''] raw = preamble + '\n\n'+'.. contents::\n :local:'+ '\n\n' + global_options+'\n\n'+'\n'.join(lines) update_cli_doc('calibredb', raw, app)
def generate_calibredb_help(preamble, info): from calibre.library.cli import COMMANDS, get_parser import calibre.library.cli as cli preamble = preamble[:preamble.find('\n\n\n', preamble.find('code-block'))] preamble += textwrap.dedent(''' :command:`calibredb` is the command line interface to the |app| database. It has several sub-commands, documented below: ''') global_parser = get_parser('') groups = [] for grp in global_parser.option_groups: groups.append((grp.title.capitalize(), grp.description, grp.option_list)) global_options = '\n'.join(render_options('calibredb', groups, False, False)) lines, toc = [], [] for cmd in COMMANDS: args = [] if cmd == 'catalog': args = [['doc.xml', '-h']] parser = getattr(cli, cmd+'_option_parser')(*args) if cmd == 'catalog': parser = parser[0] toc.append(' * :ref:`calibredb-%s`'%cmd) lines += ['.. _calibredb-'+cmd+':', ''] lines += [cmd, '~'*20, ''] usage = parser.usage.strip() usage = [i for i in usage.replace('%prog', 'calibredb').splitlines()] cmdline = ' '+usage[0] usage = usage[1:] usage = [i.replace(cmd, ':command:`%s`'%cmd) for i in usage] lines += ['.. code-block:: none', '', cmdline, ''] lines += usage groups = [(None, None, parser.option_list)] lines += [''] lines += render_options('calibredb '+cmd, groups, False) lines += [''] toc = '\n'.join(toc) raw = preamble + '\n\n'+toc + '\n\n' + global_options+'\n\n'+'\n'.join(lines) update_cli_doc(os.path.join('cli', 'calibredb.rst'), raw, info)