Use betterhelp.subparser_main instead of decorator.

To get the parser off the global.
This commit is contained in:
Ethan Dalool 2020-10-07 00:32:44 -07:00
parent c27f8038c7
commit 741f47d0b9

View file

@ -50,7 +50,7 @@ TO SEE DETAILS ON EACH COMMAND, RUN
python timesearch.py <command> python timesearch.py <command>
'''.lstrip() '''.lstrip()
MODULE_DOCSTRINGS = dict( SUB_DOCSTRINGS = dict(
breakdown=''' breakdown='''
breakdown: breakdown:
Give the comment / submission counts for users in a subreddit, or Give the comment / submission counts for users in a subreddit, or
@ -279,7 +279,7 @@ offline_reading:
'''.strip(), '''.strip(),
) )
DOCSTRING = betterhelp.add_previews(DOCSTRING, MODULE_DOCSTRINGS) DOCSTRING = betterhelp.add_previews(DOCSTRING, SUB_DOCSTRINGS)
def docstring_preview(text): def docstring_preview(text):
''' '''
@ -300,7 +300,7 @@ def indent(text, spaces=4):
docstring_headers = { docstring_headers = {
key: indent(docstring_preview(value)) key: indent(docstring_preview(value))
for (key, value) in MODULE_DOCSTRINGS.items() for (key, value) in SUB_DOCSTRINGS.items()
} }
DOCSTRING = DOCSTRING.format(**docstring_headers) DOCSTRING = DOCSTRING.format(**docstring_headers)
@ -344,8 +344,8 @@ def get_submissions_gateway(args):
from . import get_submissions from . import get_submissions
get_submissions.get_submissions_argparse(args) get_submissions.get_submissions_argparse(args)
def main(argv):
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser(description=__doc__)
subparsers = parser.add_subparsers() subparsers = parser.add_subparsers()
p_breakdown = subparsers.add_parser('breakdown') p_breakdown = subparsers.add_parser('breakdown')
@ -418,13 +418,15 @@ p_get_submissions.add_argument('-v', '--verbose', dest='verbose', action='store_
p_get_submissions.add_argument('--dont_supplement', '--dont-supplement', dest='do_supplement', action='store_false') p_get_submissions.add_argument('--dont_supplement', '--dont-supplement', dest='do_supplement', action='store_false')
p_get_submissions.set_defaults(func=get_submissions_gateway) p_get_submissions.set_defaults(func=get_submissions_gateway)
@betterhelp.subparser_betterhelp(parser, main_docstring=DOCSTRING, sub_docstrings=MODULE_DOCSTRINGS)
def main(argv):
args = parser.parse_args(argv)
try: try:
return args.func(args) return betterhelp.subparser_main(
except exceptions.DatabaseNotFound as e: argv,
message = str(e) parser,
main_docstring=DOCSTRING,
sub_docstrings=SUB_DOCSTRINGS,
)
except exceptions.DatabaseNotFound as exc:
message = str(exc)
message += '\nHave you used any of the other utilities to collect data?' message += '\nHave you used any of the other utilities to collect data?'
print(message) print(message)
return 1 return 1