aboutsummaryrefslogtreecommitdiffstats
path: root/libbe/ui/command_line.py
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2011-05-02 17:48:18 -0400
committerW. Trevor King <wking@drexel.edu>2011-05-02 17:48:24 -0400
commit1fcb1dd9114fba59a5d75570b9acc3b87d575821 (patch)
treeaaed83677449589e1ef149a22d5bda1dac3ed9d8 /libbe/ui/command_line.py
parent741abdd7453d400049a089c22686af9000a91db5 (diff)
downloadbugseverywhere-1fcb1dd9114fba59a5d75570b9acc3b87d575821.tar.gz
Revive the UserError/UsageError distinction
UsageError was removed back in commit bf3d434b244c57556bec979acbc658c30eb58221 Author: W. Trevor King <wking@drexel.edu> Date: Sat Dec 12 00:31:55 2009 -0500 Added libbe.command.base (with Command class)... because the distinction between UsageError and UserError was unclear. I've brought it back to satisfy a request by Christian Heinrich: On Sun, May 01, 2011 at 02:52:13AM +0200, Christian Heinrich wrote: > 3.) Using wrong syntax should receive better help messages. > > Current: > > "be new" -> ERROR: > Missing required argument SUMMARY > > Should be: > > "be new" -> usage: be new [options] SUMMARY > ... He suggested we print the full option list as well, but I've decided to just print the usage summary and remind the user how to get the full help message if they want it.
Diffstat (limited to 'libbe/ui/command_line.py')
-rw-r--r--libbe/ui/command_line.py26
1 files changed, 19 insertions, 7 deletions
diff --git a/libbe/ui/command_line.py b/libbe/ui/command_line.py
index 52daa4b..3f70962 100644
--- a/libbe/ui/command_line.py
+++ b/libbe/ui/command_line.py
@@ -137,8 +137,9 @@ class CmdOptionParser(optparse.OptionParser):
raise libbe.command.UserError('Too many arguments')
for arg in self.command.args[len(parsed_args):]:
if arg.optional == False:
- raise libbe.command.UserError(
- 'Missing required argument %s' % arg.metavar)
+ raise libbe.command.UsageError(
+ command=self.command,
+ message='Missing required argument %s' % arg.metavar)
return (options, parsed_args)
def callback(self, option, opt, value, parser):
@@ -289,6 +290,13 @@ def dispatch(ui, command, args):
'See http://docs.python.org/library/locale.html for details',
])
return 1
+ except libbe.command.UsageError, e:
+ print >> ui.io.stdout, 'Usage Error:\n', e
+ if e.command:
+ print >> ui.io.stdout, e.command.usage()
+ print >> ui.io.stdout, 'For usage information, try'
+ print >> ui.io.stdout, ' be help %s' % e.command_name
+ return 1
except libbe.command.UserError, e:
print >> ui.io.stdout, 'ERROR:\n', e
return 1
@@ -314,15 +322,19 @@ def main():
options,args = parser.parse_args()
except CallbackExit:
return 0
- except libbe.command.UserError, e:
- if str(e).endswith('COMMAND'):
+ except libbe.command.UsageError, e:
+ if isinstance(e.command, BE):
# no command given, print usage string
- print >> ui.io.stdout, 'ERROR:'
- print >> ui.io.stdout, be.usage(), '\n', e
+ print >> ui.io.stdout, 'Usage Error:\n', e
+ print >> ui.io.stdout, be.usage()
print >> ui.io.stdout, 'For example, try'
print >> ui.io.stdout, ' be help'
else:
- print >> ui.io.stdout, 'ERROR:\n', e
+ print >> ui.io.stdout, 'Usage Error:\n', e
+ if e.command:
+ print >> ui.io.stdout, e.command.usage()
+ print >> ui.io.stdout, 'For usage information, try'
+ print >> ui.io.stdout, ' be help %s' % e.command_name
return 1
command_name = args.pop(0)