From dc64fc3c473afacd956d46e19280072abb9e536c Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Thu, 30 Jan 2020 18:46:47 -0800 Subject: [PATCH] Move helpstrings to global constant. --- voussoirkit/betterhelp.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) 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