Use betterhelp to manage docstrings.

This commit is contained in:
Ethan Dalool 2020-01-30 23:41:42 -08:00
parent 711493a9a8
commit 7afb9fcb7a

View file

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