Move helpstrings to global constant.

master
Ethan Dalool 2020-01-30 18:46:47 -08:00
parent f599d7e394
commit dc64fc3c47
1 changed files with 5 additions and 7 deletions

View File

@ -1,5 +1,7 @@
import functools
HELPSTRINGS = {'', 'help', '-h', '--help'}
def docstring_preview(text, indent=None):
text = text.split('\n\n')[0]
if indent:
@ -28,11 +30,9 @@ def add_previews(docstring, sub_docstrings):
def betterhelp(docstring):
def wrapper(main):
def wrapped(argv):
helpstrings = {'', 'help', '-h', '--help'}
argument = listget(argv, 0, '').lower()
if argument in helpstrings:
if argument in HELPSTRINGS:
print(docstring)
return 1
@ -43,20 +43,18 @@ def betterhelp(docstring):
def subparser_betterhelp(main_docstring, sub_docstrings):
def wrapper(main):
def wrapped(argv):
helpstrings = {'', 'help', '-h', '--help'}
command = listget(argv, 0, '').lower()
if command not in sub_docstrings:
print(main_docstring)
if command == '':
print('You are seeing the default help text because you did not choose a command.')
elif command not in helpstrings:
elif command not in HELPSTRINGS:
print(f'You are seeing the default help text because "{command}" was not recognized')
return 1
argument = listget(argv, 1, '').lower()
if argument in helpstrings:
if argument in HELPSTRINGS:
print(sub_docstrings[command])
return 1