glance-manage output when ran without any arguments

The glance-manage command isn't very helpful when it is run without any
arguments. The current output looks like following:

$ glance-manage
usage: glance-manage [options] <cmd>
glance-manage: error: too few arguments

This patch extends the default output to look similar to what can be
seen in the cinder-manage tool. The new output is:

$ glance-manage
/usr/local/bin/glance-manage category action [<args>]
Available categories:
	db

Change-Id: I2c56ccf5a28cdaf9fdfb03d79763b34dc096a858
Closes-Bug: #1394316
This commit is contained in:
Kamil Rykowski 2015-02-24 12:49:22 +01:00
parent 0d7b292b82
commit fd2057d521

View File

@ -55,6 +55,7 @@ from glance import i18n
CONF = cfg.CONF
LOG = logging.getLogger(__name__)
_ = i18n._
_LW = i18n._LW
@ -270,6 +271,11 @@ command_opt = cfg.SubCommandOpt('command',
handler=add_command_parsers)
CATEGORIES = {
'db': DbCommands,
}
def methods_of(obj):
"""Get all callable methods of an object that don't start with underscore
@ -284,6 +290,14 @@ def methods_of(obj):
def main():
CONF.register_cli_opt(command_opt)
if len(sys.argv) < 2:
script_name = sys.argv[0]
print("%s category action [<args>]" % script_name)
print(_("Available categories:"))
for category in CATEGORIES:
print(_("\t%s") % category)
sys.exit(2)
try:
logging.register_options(CONF)
cfg_files = cfg.find_config_files(project='glance',
@ -292,8 +306,7 @@ def main():
prog='glance-api'))
cfg_files.extend(cfg.find_config_files(project='glance',
prog='glance-manage'))
config.parse_args(default_config_files=cfg_files,
usage="%(prog)s [options] <cmd>")
config.parse_args(default_config_files=cfg_files)
logging.setup(CONF, 'glance')
except RuntimeError as e:
sys.exit("ERROR: %s" % e)