User friendly help message

Fixes bug #892066

Change-Id: Ibeb86c5a9ae0f1dcc313c77fdf923a2eb37de505
This commit is contained in:
lzyeval 2011-12-20 11:49:45 +08:00
parent e20dcd8cd7
commit 487032ae07

@ -42,10 +42,28 @@ def env(*vars):
return ''
class NovaClientArgumentParser(argparse.ArgumentParser):
def __init__(self, *args, **kwargs):
super(NovaClientArgumentParser, self).__init__(*args, **kwargs)
def error(self, message):
"""error(message: string)
Prints a usage message incorporating the message to stderr and
exits.
"""
self.print_usage(sys.stderr)
#FIXME(lzyeval): if changes occur in argparse.ArgParser._check_value
choose_from = ' (choose from'
self.exit(2, "error: %s\nTry `%s help' for more information.\n" %
(message.split(choose_from)[0], self.prog))
class OpenStackComputeShell(object):
def get_base_parser(self):
parser = argparse.ArgumentParser(
parser = NovaClientArgumentParser(
prog='nova',
description=__doc__.strip(),
epilog='See "nova help COMMAND" '\