From e2b648f2148d7b6550fb3a4bcfde4eff714a7ec6 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 28 Dec 2009 10:56:04 -0500 Subject: [PATCH] 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 --- libbe/command/base.py | 4 ++-- libbe/command/target.py | 2 +- libbe/ui/command_line.py | 4 +++- 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): -- 2.26.2