aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-12-28 10:56:04 -0500
committerW. Trevor King <wking@drexel.edu>2009-12-28 10:56:04 -0500
commite2b648f2148d7b6550fb3a4bcfde4eff714a7ec6 (patch)
tree0d4e90ed1ce25f2d22a9f08a19ead6af614ef785
parent4fbf5d1d222610b0775f95472fe1a60aaedea29f (diff)
downloadbugseverywhere-e2b648f2148d7b6550fb3a4bcfde4eff714a7ec6.tar.gz
Allow external use of Command.usage() and use CmdOptionParser.set_usage()
This fixes $ python be diff -2 Usage: be [options] be: error: no such option: -2 and we now get the correct output $ python be diff -2 Usage: be diff [options] [REVISION] be: error: no such option: -2
-rw-r--r--libbe/command/base.py4
-rw-r--r--libbe/command/target.py2
-rwxr-xr-xlibbe/ui/command_line.py4
3 files changed, 6 insertions, 4 deletions
diff --git a/libbe/command/base.py b/libbe/command/base.py
index ac6a58b..cdb4043 100644
--- a/libbe/command/base.py
+++ b/libbe/command/base.py
@@ -264,11 +264,11 @@ class Command (object):
self.stdout.encoding = output_encoding
def help(self, *args):
- return '\n\n'.join([self._usage(),
+ return '\n\n'.join([self.usage(),
self._option_help(),
self._long_help().rstrip('\n')])
- def _usage(self):
+ def usage(self):
usage = 'usage: be %s [options]' % self.name
num_optional = 0
for arg in self.args:
diff --git a/libbe/command/target.py b/libbe/command/target.py
index df836db..3195f95 100644
--- a/libbe/command/target.py
+++ b/libbe/command/target.py
@@ -107,7 +107,7 @@ class Target (libbe.command.Command):
target = add_target(bugdir, bug, params['target'])
return 0
- def _usage(self):
+ def usage(self):
return 'usage: be %(name)s BUG-ID [TARGET]\nor: be %(name)s --resolve [TARGET]' \
% vars(self)
diff --git a/libbe/ui/command_line.py b/libbe/ui/command_line.py
index 856f810..b5a3991 100755
--- a/libbe/ui/command_line.py
+++ b/libbe/ui/command_line.py
@@ -48,6 +48,8 @@ class CmdOptionParser(optparse.OptionParser):
self._option_by_name = {}
for option in self.command.options:
self._add_option(option)
+ self.set_usage(command.usage())
+
def _add_option(self, option):
option.validate()
@@ -215,7 +217,7 @@ class BE (libbe.command.Command):
name='args', optional=True, repeatable=True)
])
- def _usage(self):
+ def usage(self):
return 'usage: be [options] [COMMAND [command-options] [COMMAND-ARGS ...]]'
def _long_help(self):