Use betterhelp to manage docstrings.
This commit is contained in:
parent
711493a9a8
commit
7afb9fcb7a
1 changed files with 56 additions and 57 deletions
37
epubfile.py
37
epubfile.py
|
@ -1175,6 +1175,9 @@ from voussoirkit import betterhelp
|
|||
from voussoirkit import winglob
|
||||
|
||||
DOCSTRING = '''
|
||||
Epubfile
|
||||
The simple python .epub scripting tool.
|
||||
|
||||
{addfile}
|
||||
|
||||
{covercomesfirst}
|
||||
|
@ -1186,19 +1189,20 @@ DOCSTRING = '''
|
|||
{merge}
|
||||
|
||||
{normalize}
|
||||
|
||||
TO SEE DETAILS ON EACH COMMAND, RUN
|
||||
> epubfile.py <command>
|
||||
'''.lstrip()
|
||||
|
||||
SUB_DOCSTRINGS = {
|
||||
'addfile':
|
||||
'''
|
||||
SUB_DOCSTRINGS = dict(
|
||||
addfile='''
|
||||
addfile:
|
||||
Add files into the book.
|
||||
|
||||
> epubfile.py addfile book.epub page1.html image.jpg
|
||||
'''.strip(),
|
||||
|
||||
'covercomesfirst':
|
||||
'''
|
||||
covercomesfirst='''
|
||||
covercomesfirst:
|
||||
Rename the cover image file so that it is the alphabetically-first image.
|
||||
|
||||
|
@ -1213,16 +1217,14 @@ covercomesfirst:
|
|||
first, otherwise some /a/image.jpg will always be before /images/cover.jpg.
|
||||
'''.strip(),
|
||||
|
||||
'exec':
|
||||
'''
|
||||
exec='''
|
||||
exec:
|
||||
Execute your own Python code against the book.
|
||||
|
||||
> epubfile.py exec book.epub --command "book._____()"
|
||||
'''.strip(),
|
||||
|
||||
'generate_toc':
|
||||
'''
|
||||
generate_toc='''
|
||||
generate_toc:
|
||||
Regenerate the toc.ncx and nav.xhtml based on headers in the files.
|
||||
|
||||
|
@ -1234,16 +1236,14 @@ generate_toc:
|
|||
That is, h1, h2, ... hX.
|
||||
'''.strip(),
|
||||
|
||||
'holdit':
|
||||
'''
|
||||
holdit='''
|
||||
holdit:
|
||||
Extract the book and leave it open for manual editing, then save.
|
||||
|
||||
> epubfile.py holdit book.epub
|
||||
'''.strip(),
|
||||
|
||||
'merge':
|
||||
'''
|
||||
merge='''
|
||||
merge:
|
||||
Merge multiple books into one.
|
||||
|
||||
|
@ -1261,8 +1261,7 @@ merge:
|
|||
Overwrite the output file without prompting.
|
||||
'''.strip(),
|
||||
|
||||
'normalize':
|
||||
'''
|
||||
normalize='''
|
||||
normalize:
|
||||
Rename files and directories in the book to match a common structure.
|
||||
|
||||
|
@ -1270,8 +1269,8 @@ normalize:
|
|||
subdirectories by type: Text, Images, Styles, etc.
|
||||
|
||||
> epubfile.py normalize book.epub
|
||||
'''.strip()
|
||||
}
|
||||
'''.strip(),
|
||||
)
|
||||
|
||||
DOCSTRING = betterhelp.add_previews(DOCSTRING, SUB_DOCSTRINGS)
|
||||
|
||||
|
@ -1470,8 +1469,6 @@ def normalize_argparse(args):
|
|||
book.move_nav_to_end()
|
||||
book.save(epub)
|
||||
|
||||
@betterhelp.subparser_betterhelp(main_docstring=DOCSTRING, sub_docstrings=SUB_DOCSTRINGS)
|
||||
def main(argv):
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
subparsers = parser.add_subparsers()
|
||||
|
||||
|
@ -1511,6 +1508,8 @@ def main(argv):
|
|||
p_normalize.add_argument('epubs', nargs='+', default=[])
|
||||
p_normalize.set_defaults(func=normalize_argparse)
|
||||
|
||||
@betterhelp.subparser_betterhelp(parser, main_docstring=DOCSTRING, sub_docstrings=SUB_DOCSTRINGS)
|
||||
def main(argv):
|
||||
args = parser.parse_args(argv)
|
||||
args.func(args)
|
||||
|
||||
|
|
Loading…
Reference in a new issue