mirror of
https://github.com/JimmXinu/FanFicFare.git
synced 2026-05-09 05:21:13 +02:00
Make doc-getting flags shortcut
This saves on pointless validation/setup work when only getting help information. Moreover, these were the only actions that were in the middle of the parse/validate/setup/run core logic of main(), moving them out clears the way to cleanly breaking it up. Removes -v alias for --version. If this is undesirable, a trick similar to that for --sites-list can be used to shortcut it as well.
This commit is contained in:
parent
e8d2ffb100
commit
0847fc91bf
1 changed files with 10 additions and 17 deletions
|
|
@ -67,7 +67,8 @@ def write_story(config, adapter, writeformat,
|
||||||
def mkParser(calibre, parser=None):
|
def mkParser(calibre, parser=None):
|
||||||
# read in args, anything starting with -- will be treated as --<varible>=<value>
|
# read in args, anything starting with -- will be treated as --<varible>=<value>
|
||||||
if not parser:
|
if not parser:
|
||||||
parser = OptionParser('usage: %prog [options] [STORYURL]...')
|
parser = OptionParser('usage: %prog [options] [STORYURL]...',
|
||||||
|
version="Version: %s" % version)
|
||||||
parser.add_option('-f', '--format', dest='format', default='epub',
|
parser.add_option('-f', '--format', dest='format', default='epub',
|
||||||
help='Write story as FORMAT, epub(default), mobi, txt or html.', metavar='FORMAT')
|
help='Write story as FORMAT, epub(default), mobi, txt or html.', metavar='FORMAT')
|
||||||
if calibre:
|
if calibre:
|
||||||
|
|
@ -141,8 +142,15 @@ def mkParser(calibre, parser=None):
|
||||||
action='store_true', dest='downloadimap',
|
action='store_true', dest='downloadimap',
|
||||||
help='Download valid story URLs from unread email from IMAP account configured in ini. Update existing EPUBs if used with --update-epub.', )
|
help='Download valid story URLs from unread email from IMAP account configured in ini. Update existing EPUBs if used with --update-epub.', )
|
||||||
|
|
||||||
|
def sitesList(*args):
|
||||||
|
for site, examples in adapters.getSiteExamples():
|
||||||
|
print('\n#### %s\nExample URLs:' % site)
|
||||||
|
for u in examples:
|
||||||
|
print(' * %s' % u)
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
parser.add_option('-s', '--sites-list',
|
parser.add_option('-s', '--sites-list',
|
||||||
action='store_true', dest='siteslist', default=False,
|
action='callback', callback=sitesList,
|
||||||
help='Get list of valid story URLs examples.', )
|
help='Get list of valid story URLs examples.', )
|
||||||
parser.add_option('--non-interactive',
|
parser.add_option('--non-interactive',
|
||||||
action='store_false', dest='interactive', default=sys.stdin.isatty() and sys.stdout.isatty(),
|
action='store_false', dest='interactive', default=sys.stdin.isatty() and sys.stdout.isatty(),
|
||||||
|
|
@ -156,9 +164,6 @@ def mkParser(calibre, parser=None):
|
||||||
parser.add_option('--color',
|
parser.add_option('--color',
|
||||||
action='store_true', dest='color',
|
action='store_true', dest='color',
|
||||||
help='Display a errors and warnings in a contrasting color. Requires package colorama on Windows.', )
|
help='Display a errors and warnings in a contrasting color. Requires package colorama on Windows.', )
|
||||||
parser.add_option('-v', '--version',
|
|
||||||
action='store_true', dest='version',
|
|
||||||
help='Display version and quit.', )
|
|
||||||
|
|
||||||
## undocumented feature for development use. Save page cache and
|
## undocumented feature for development use. Save page cache and
|
||||||
## cookies between runs. Saves in PWD as files global_cache and
|
## cookies between runs. Saves in PWD as files global_cache and
|
||||||
|
|
@ -194,10 +199,6 @@ def main(argv=None,
|
||||||
logger.debug("Python Version:%s"%sys.version)
|
logger.debug("Python Version:%s"%sys.version)
|
||||||
logger.debug(" FFF Version:%s"%version)
|
logger.debug(" FFF Version:%s"%version)
|
||||||
|
|
||||||
if options.version:
|
|
||||||
print("Version: %s" % version)
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
if options.color:
|
if options.color:
|
||||||
if 'Windows' in platform.platform():
|
if 'Windows' in platform.platform():
|
||||||
try:
|
try:
|
||||||
|
|
@ -219,7 +220,6 @@ def main(argv=None,
|
||||||
warn = fail = print
|
warn = fail = print
|
||||||
|
|
||||||
list_only = any((options.imaplist,
|
list_only = any((options.imaplist,
|
||||||
options.siteslist,
|
|
||||||
options.list,
|
options.list,
|
||||||
options.normalize,
|
options.normalize,
|
||||||
))
|
))
|
||||||
|
|
@ -228,13 +228,6 @@ def main(argv=None,
|
||||||
options.downloadlist))):
|
options.downloadlist))):
|
||||||
parser.error('Incorrect arguments: Cannot download and list URLs at the same time.')
|
parser.error('Incorrect arguments: Cannot download and list URLs at the same time.')
|
||||||
|
|
||||||
if options.siteslist:
|
|
||||||
for site, examples in adapters.getSiteExamples():
|
|
||||||
print('\n#### %s\nExample URLs:' % site)
|
|
||||||
for u in examples:
|
|
||||||
print(' * %s' % u)
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
# options.updatealways should also invoke most options.update logic.
|
# options.updatealways should also invoke most options.update logic.
|
||||||
if options.updatealways:
|
if options.updatealways:
|
||||||
options.update = True
|
options.update = True
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue