[PATCH] bzr help commands extension
Koen Witters
kwitters at pandora.be
Fri May 6 11:06:23 BST 2005
Hello all,
Since this is my first post I would like to congratulate the people
involved in bazaar-ng for their nice ideas/work. Bzr is definitely the
revision control system I was looking for, only problem is that it isn't
finished yet ;-). By the way, I think using Python was an excellent choice.
I've upgrade the 'bzr help commands' a bit to represent some sort of
handy reference (much like the command listing in 'bzr help'). Please
let me know if you like it or not. Here is a snipet of the output to get
the idea:
--------------[ Info Commands ]---------------------------------------
bzr help [COMMAND]
Show help screen
bzr version
Show software version/licence/non-warranty.
bzr whoami
Show bzr user id.
bzr rocks
Statement of optimism.
--------------[ Branch Commands ]-------------------------------------
bzr init
Start versioning the current directory
bzr root
Print the branch root.
...
Koen.
(Watch out at the end of this patch: the long lines in show_reference()
will probalby be wrapped by my mail client)
*** modified file 'bzrlib/commands.py'
--- bzrlib/commands.py
+++ bzrlib/commands.py
@@ -30,37 +30,7 @@
* No merge operators yet.
-Interesting commands:
-
- bzr help [COMMAND]
- Show help screen
- bzr version
- Show software version/licence/non-warranty.
- bzr init
- Start versioning the current directory
- bzr add FILE...
- Make files versioned.
- bzr log
- Show revision history.
- bzr rename FROM TO
- Rename one file.
- bzr move FROM... DESTDIR
- Move one or more files to a different directory.
- bzr diff [FILE...]
- Show changes from last revision to working copy.
- bzr commit -m 'MESSAGE'
- Store current state as new revision.
- bzr export REVNO DESTINATION
- Export the branch state at a previous version.
- bzr status
- Show summary of pending changes.
- bzr remove FILE...
- Make a file not versioned.
- bzr info
- Show statistics about this branch.
- bzr check
- Verify history is stored safely.
- (for more type 'bzr help commands')
+Interesting commands: (for more type 'bzr help commands')
"""
@@ -173,6 +143,8 @@
def cmd_add(file_list, verbose=False):
"""Add specified files or directories.
+
+ usage: bzr add FILE...
In non-recursive mode, all the named items are added, regardless
of whether they were previously ignored. A warning is given if
@@ -220,6 +192,10 @@
# special behaviour of Unix?
def cmd_move(source_list, dest):
+ """Move one or more files to a different directory.
+
+ usage: bzr move FROM DESTDIR
+ """
b = Branch('.')
b.move([b.relpath(s) for s in source_list], b.relpath(dest))
@@ -269,7 +245,7 @@
def cmd_info():
- """info: Show statistical information for this branch
+ """Show statistical information for this branch
usage: bzr info"""
import info
@@ -278,6 +254,10 @@
def cmd_remove(file_list, verbose=False):
+ """Make a file not versioned.
+
+ usage: bzr remove FILE...
+ """
b = Branch(file_list[0])
b.remove([b.relpath(f) for f in file_list], verbose=verbose)
@@ -335,6 +315,8 @@
def cmd_init():
+ """Start versioning the current directory
+ """
# TODO: Check we're not already in a working directory? At the
# moment you'll get an ugly error.
@@ -349,7 +331,7 @@
def cmd_diff(revision=None, file_list=None):
"""bzr diff: Show differences in working tree.
-
+
usage: bzr diff [-r REV] [FILE...]
--revision REV
@@ -626,7 +608,10 @@
def cmd_export(revno, dest):
- """Export past revision to destination directory."""
+ """Export past revision to destination directory.
+
+ usage: bzr export REVNO DESTINATION
+ """
b = Branch('.')
rh = b.lookup_revision(int(revno))
t = b.revision_tree(rh)
@@ -655,6 +640,8 @@
def cmd_commit(message=None, verbose=False):
"""Commit changes to a new revision.
+
+ usage: bzr commit -m 'MESSAGE'
--message MESSAGE
Description of changes in this revision; free form text.
@@ -762,12 +749,21 @@
######################################################################
# help
+import help
+
def cmd_help(topic=None):
+ """Show help screen
+
+ usage: bzr help [COMMAND]
+ """
if topic == None:
print __doc__
+ help.show_docs( ['help', 'version', 'init', 'add', 'log', 'rename',
+ 'move', 'diff', 'commit', 'export', 'status',
+ 'remove', 'info', 'check'] )
elif topic == 'commands':
- help_commands()
+ help.show_reference()
else:
# otherwise, maybe the name of a command?
topic, cmdfn = get_cmd_handler(topic)
@@ -779,24 +775,18 @@
print doc
-def help_commands():
- """List all commands"""
+def get_commands():
accu = []
for k in globals().keys():
if k.startswith('cmd_'):
accu.append(k[4:].replace('_','-'))
accu.sort()
- print "bzr commands: "
- for x in accu:
- print " " + x
- print "note: some of these commands are internal-use or obsolete"
- # TODO: Some kind of marker for internal-use commands?
- # TODO: Show aliases?
-
-
+ return accu
def cmd_version():
+ """Show software version/licence/non-warranty.
+ """
print "bzr (bazaar-ng) %s" % bzrlib.__version__
print bzrlib.__copyright__
print "http://bazaar-ng.org/"
*** added file 'bzrlib/help.py'
--- /dev/null
+++ bzrlib/help.py
@@ -1,0 +1,63 @@
+# Copyright (C) 2004, 2005 by Martin Pool
+# Copyright (C) 2005 by Canonical Ltd
+
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+import commands
+import re
+from inspect import getdoc
+
+
+def show_reference():
+ print "\n--------------[ Info Commands
]---------------------------------------"
+ show_docs( ['help', 'version', 'whoami', 'rocks'] )
+
+ print "\n--------------[ Branch Commands
]-------------------------------------"
+ show_docs( ['init', 'root', 'info', 'status', 'log', 'diff', 'check'] )
+
+ print "\n--------------[ Revision Commands
]-----------------------------------"
+ show_docs( ['commit', 'export', 'get-revision'] )
+
+ print "\n--------------[ File Commands
]---------------------------------------"
+ show_docs( ['file-id', 'ls', 'cat', 'add', 'move', 'rename',
'remove', 'relpath',
+ 'ignored', 'missing', 'get-file-text', 'renames',
'deleted',
+ 'directories', 'file-id-path'] )
+
+ print "\nFor more help on a command type 'bzr help [COMMAND]'"
+
+
+def show_docs( commands ):
+ for cmd in commands:
+ show_short_doc( cmd )
+
+
+def show_short_doc( command ):
+ command, cmd_handle = commands.get_cmd_handler( command )
+ doc = getdoc( cmd_handle )
+
+ if( doc != None ):
+ reg = re.search( r"usage:(.*)$", doc, re.MULTILINE )
+ if( reg != None ):
+ print " " + reg.group(1).strip()
+ else:
+ print " bzr " + command
+
+ print " " + doc.splitlines()[0]
+ else:
+ print " bzr " + command
+ print
+
+
More information about the bazaar
mailing list