diff --git a/voussoirkit/betterhelp.py b/voussoirkit/betterhelp.py index b6da2cd..322dbb8 100644 --- a/voussoirkit/betterhelp.py +++ b/voussoirkit/betterhelp.py @@ -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