Allow external use of Command.usage() and use CmdOptionParser.set_usage()
authorW. Trevor King <wking@drexel.edu>
Mon, 28 Dec 2009 15:56:04 +0000 (10:56 -0500)
committerW. Trevor King <wking@drexel.edu>
Mon, 28 Dec 2009 15:56:04 +0000 (10:56 -0500)
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

libbe/command/base.py
libbe/command/target.py
libbe/ui/command_line.py

index ac6a58b79d1f0139963ec171409c6840784a6a25..cdb404388269b3cf42829a9ef40bd12e9e1c1335 100644 (file)
@@ -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:
index df836db24e3376c529a4fd08a97db2082bd274b1..3195f9555d73c3d152d029c505d660c7cc1e4457 100644 (file)
@@ -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)
 
index 856f810110c5c475a63313970cbbf0596cdef5c4..b5a3991922dce484eb4f17b61dae30dfd9bfa305 100755 (executable)
@@ -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):