Use betterhelp.subparser_main instead of decorator.
To get the parser off the global.
This commit is contained in:
parent
c27f8038c7
commit
741f47d0b9
1 changed files with 84 additions and 82 deletions
|
@ -50,7 +50,7 @@ TO SEE DETAILS ON EACH COMMAND, RUN
|
|||
python timesearch.py <command>
|
||||
'''.lstrip()
|
||||
|
||||
MODULE_DOCSTRINGS = dict(
|
||||
SUB_DOCSTRINGS = dict(
|
||||
breakdown='''
|
||||
breakdown:
|
||||
Give the comment / submission counts for users in a subreddit, or
|
||||
|
@ -279,7 +279,7 @@ offline_reading:
|
|||
'''.strip(),
|
||||
)
|
||||
|
||||
DOCSTRING = betterhelp.add_previews(DOCSTRING, MODULE_DOCSTRINGS)
|
||||
DOCSTRING = betterhelp.add_previews(DOCSTRING, SUB_DOCSTRINGS)
|
||||
|
||||
def docstring_preview(text):
|
||||
'''
|
||||
|
@ -300,7 +300,7 @@ def indent(text, spaces=4):
|
|||
|
||||
docstring_headers = {
|
||||
key: indent(docstring_preview(value))
|
||||
for (key, value) in MODULE_DOCSTRINGS.items()
|
||||
for (key, value) in SUB_DOCSTRINGS.items()
|
||||
}
|
||||
|
||||
DOCSTRING = DOCSTRING.format(**docstring_headers)
|
||||
|
@ -344,8 +344,8 @@ def get_submissions_gateway(args):
|
|||
from . import get_submissions
|
||||
get_submissions.get_submissions_argparse(args)
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
def main(argv):
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
subparsers = parser.add_subparsers()
|
||||
|
||||
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.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:
|
||||
return args.func(args)
|
||||
except exceptions.DatabaseNotFound as e:
|
||||
message = str(e)
|
||||
return betterhelp.subparser_main(
|
||||
argv,
|
||||
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?'
|
||||
print(message)
|
||||
return 1
|
||||
|
|
Loading…
Reference in a new issue