[Pkg-bazaar-commits] ./bzr/unstable r452: - show command usage in help

Martin Pool mbp at sourcefrog.net
Fri Apr 10 08:19:44 UTC 2009


------------------------------------------------------------
revno: 452
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Wed 2005-05-11 11:25:52 +1000
message:
  - show command usage in help
modified:
  bzrlib/help.py
-------------- next part --------------
=== modified file 'bzrlib/help.py'
--- a/bzrlib/help.py	2005-05-09 03:01:21 +0000
+++ b/bzrlib/help.py	2005-05-11 01:25:52 +0000
@@ -66,6 +66,28 @@
         help_on_command(topic)
 
 
+def command_usage(cmdname, cmdclass):
+    """Return single-line grammar for command.
+
+    Only describes arguments, not options.
+    """
+    s = cmdname + ' '
+    for aname in cmdclass.takes_args:
+        aname = aname.upper()
+        if aname[-1] in ['$', '+']:
+            aname = aname[:-1] + '...'
+        elif aname[-1] == '?':
+            aname = '[' + aname[:-1] + ']'
+        elif aname[-1] == '*':
+            aname = '[' + aname[:-1] + '...]'
+        s += aname + ' '
+            
+    assert s[-1] == ' '
+    s = s[:-1]
+    
+    return s
+
+
 def help_on_command(cmdname):
     cmdname = str(cmdname)
 
@@ -83,18 +105,7 @@
         short = doc
         rest = ''
 
-    print 'usage: bzr ' + topic,
-    for aname in cmdclass.takes_args:
-        aname = aname.upper()
-        if aname[-1] in ['$', '+']:
-            aname = aname[:-1] + '...'
-        elif aname[-1] == '?':
-            aname = '[' + aname[:-1] + ']'
-        elif aname[-1] == '*':
-            aname = '[' + aname[:-1] + '...]'
-        print aname,
-    print 
-    print short
+    print 'usage:', command_usage(topic, cmdclass)
 
     if cmdclass.aliases:
         print 'aliases: ' + ', '.join(cmdclass.aliases)
@@ -134,7 +145,7 @@
     for cmdname, cmdclass in accu:
         if cmdclass.hidden:
             continue
-        print cmdname
+        print command_usage(cmdname, cmdclass)
         help = inspect.getdoc(cmdclass)
         if help:
             print "    " + help.split('\n', 1)[0]



More information about the Pkg-bazaar-commits mailing list