From fd2057d5211486bb22392a91a04316a9a75758bc Mon Sep 17 00:00:00 2001 From: Kamil Rykowski Date: Tue, 24 Feb 2015 12:49:22 +0100 Subject: [PATCH] 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] 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 [] Available categories: db Change-Id: I2c56ccf5a28cdaf9fdfb03d79763b34dc096a858 Closes-Bug: #1394316 --- glance/cmd/manage.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/glance/cmd/manage.py b/glance/cmd/manage.py index 1ad0ec657e..84fed72ea3 100755 --- a/glance/cmd/manage.py +++ b/glance/cmd/manage.py @@ -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 []" % 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] ") + config.parse_args(default_config_files=cfg_files) logging.setup(CONF, 'glance') except RuntimeError as e: sys.exit("ERROR: %s" % e)