summaryrefslogtreecommitdiff
path: root/cmd2/argparse_completer.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-05-06 23:45:03 -0400
committerGitHub <noreply@github.com>2019-05-06 23:45:03 -0400
commit673d8a1bebcada7f0182758acfe7f65637113286 (patch)
tree26e9218f325651e15f7e0f0751ca6e87848055fe /cmd2/argparse_completer.py
parent91e271013c8580f3308d593c2d3224ecf00d8b2f (diff)
parent14b33bb75667aef485119e4616de811e86547f69 (diff)
downloadcmd2-git-673d8a1bebcada7f0182758acfe7f65637113286.tar.gz
Merge pull request #672 from python-cmd2/argparse_error
ACArgumentParser no longer prints complete help text when a parsing error occurs
Diffstat (limited to 'cmd2/argparse_completer.py')
-rw-r--r--cmd2/argparse_completer.py13
1 files changed, 5 insertions, 8 deletions
diff --git a/cmd2/argparse_completer.py b/cmd2/argparse_completer.py
index 7b466342..ac65185b 100644
--- a/cmd2/argparse_completer.py
+++ b/cmd2/argparse_completer.py
@@ -908,7 +908,7 @@ class ACHelpFormatter(argparse.RawTextHelpFormatter):
# join lines into usage
usage = '\n'.join(lines)
- # prefix with 'usage:'
+ # prefix with 'Usage:'
return '%s%s\n\n' % (prefix, usage)
def _format_action_invocation(self, action) -> str:
@@ -970,9 +970,6 @@ class ACHelpFormatter(argparse.RawTextHelpFormatter):
result = super()._format_args(action, default_metavar)
return result
- def format_help(self):
- return super().format_help() + '\n'
-
# noinspection PyCompatibility
class ACArgumentParser(argparse.ArgumentParser):
@@ -1005,7 +1002,7 @@ class ACArgumentParser(argparse.ArgumentParser):
def error(self, message: str) -> None:
"""Custom error override. Allows application to control the error being displayed by argparse"""
- if len(self._custom_error_message) > 0:
+ if self._custom_error_message:
message = self._custom_error_message
self._custom_error_message = ''
@@ -1019,9 +1016,9 @@ class ACArgumentParser(argparse.ArgumentParser):
formatted_message += '\n ' + line
linum += 1
- sys.stderr.write(Fore.LIGHTRED_EX + '{}\n\n'.format(formatted_message) + Fore.RESET)
- # sys.stderr.write('{}\n\n'.format(formatted_message))
- self.print_help()
+ self.print_usage(sys.stderr)
+ sys.stderr.write(Fore.LIGHTRED_EX + '{}\n'.format(formatted_message) + Fore.RESET)
+
sys.exit(1)
def format_help(self) -> str: