From 41666d60c88e4b70bceb7898459a93e6cf389382 Mon Sep 17 00:00:00 2001
From: Shashirekha Gundur <shashirekha.j.gundur@intel.com>
Date: Sun, 23 Oct 2016 19:59:11 +0000
Subject: [PATCH] =?UTF-8?q?modify=20'swift=20<sub=5Fcommand>=20=E2=80=94he?=
 =?UTF-8?q?lp'=20display?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

In python swiftclient:  swift <sub_command> —help will now
display st_<sub_command>_options + st_<sub_command>_help texts
e.g. http://paste.openstack.org/show/589752/

Change-Id: I34e4b2ac29ef395f8ca474ce7a82f59a1fd8c7f4
Closes-Bug: #1621415
---
 swiftclient/shell.py     | 18 ++++++++++++------
 tests/unit/test_shell.py |  7 +++++--
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/swiftclient/shell.py b/swiftclient/shell.py
index 3f8aad63..259379ed 100755
--- a/swiftclient/shell.py
+++ b/swiftclient/shell.py
@@ -861,7 +861,8 @@ st_upload_options = '''[--changed] [--skip-identical] [--segment-size <size>]
                     <container> <file_or_directory> [<file_or_directory>] [...]
 '''
 
-st_upload_help = ''' Uploads specified files and directories to the given container.
+st_upload_help = '''
+Uploads specified files and directories to the given container.
 
 Positional arguments:
   <container>           Name of container to upload to.
@@ -1098,7 +1099,8 @@ def st_upload(parser, args, output_manager):
             output_manager.error(e.value)
 
 
-st_capabilities_options = "[--json] [<proxy_url>]"
+st_capabilities_options = '''[--json] [<proxy_url>]
+'''
 st_info_options = st_capabilities_options
 st_capabilities_help = '''
 Retrieve capability of the proxy.
@@ -1198,7 +1200,8 @@ def st_auth(parser, args, thread_manager):
 
 
 st_tempurl_options = '''[--absolute]
-                     <method> <seconds> <path> <key>'''
+                     <method> <seconds> <path> <key>
+'''
 
 
 st_tempurl_help = '''
@@ -1306,9 +1309,12 @@ def parse_args(parser, args, enforce_requires=True):
             logging.basicConfig(level=logging.INFO)
 
     if args and options.get('help'):
-        _help = globals().get('st_%s_help' % args[0],
-                              "no help for %s" % args[0])
-        print(_help)
+        _help = globals().get('st_%s_help' % args[0])
+        _options = globals().get('st_%s_options' % args[0], "\n")
+        if _help:
+            print("Usage: %s %s %s\n%s" % (BASENAME, args[0], _options, _help))
+        else:
+            print("no such command: %s" % args[0])
         exit()
 
     # Short circuit for tempurl, which doesn't need auth
diff --git a/tests/unit/test_shell.py b/tests/unit/test_shell.py
index 718615d6..70ac696d 100644
--- a/tests/unit/test_shell.py
+++ b/tests/unit/test_shell.py
@@ -1545,18 +1545,21 @@ class TestSubcommandHelp(unittest.TestCase):
     def test_subcommand_help(self):
         for command in swiftclient.shell.commands:
             help_var = 'st_%s_help' % command
+            options_var = 'st_%s_options' % command
             self.assertTrue(hasattr(swiftclient.shell, help_var))
             with CaptureOutput() as out:
                 argv = ['', command, '--help']
                 self.assertRaises(SystemExit, swiftclient.shell.main, argv)
-            expected = vars(swiftclient.shell)[help_var]
+            expected = 'Usage: swift %s %s\n%s' % (
+                command, vars(swiftclient.shell).get(options_var, "\n"),
+                vars(swiftclient.shell)[help_var])
             self.assertEqual(out.strip('\n'), expected)
 
     def test_no_help(self):
         with CaptureOutput() as out:
             argv = ['', 'bad_command', '--help']
             self.assertRaises(SystemExit, swiftclient.shell.main, argv)
-        expected = 'no help for bad_command'
+        expected = 'no such command: bad_command'
         self.assertEqual(out.strip('\n'), expected)