summaryrefslogtreecommitdiff
path: root/clcommands.py
diff options
context:
space:
mode:
authorSylvain Th?nault <sylvain.thenault@logilab.fr>2010-01-26 10:20:48 +0100
committerSylvain Th?nault <sylvain.thenault@logilab.fr>2010-01-26 10:20:48 +0100
commit7b6a2b4e1c0c15f49c2f0747a9ef4ed524b755a2 (patch)
tree6177e9e3beb8913aea624059e6e6640ea6116051 /clcommands.py
parentad424c7b3d190aebc976eb43278bc4217bf8d84f (diff)
downloadlogilab-common-7b6a2b4e1c0c15f49c2f0747a9ef4ed524b755a2.tar.gz
main_usage / main_run api fixes:
- __doc__ is not a good local variable name (in main_usage) - main_run now accept 'copyright' as argument - main_usage handle cases where copyright is empty
Diffstat (limited to 'clcommands.py')
-rw-r--r--clcommands.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/clcommands.py b/clcommands.py
index 5683cf8..c8586f1 100644
--- a/clcommands.py
+++ b/clcommands.py
@@ -80,16 +80,15 @@ def register_commands(commands):
_COMMANDS[command_klass.name] = command_klass
-def main_usage(status=0, __doc__=DEFAULT_DOC, copyright=DEFAULT_COPYRIGHT):
+def main_usage(status=0, doc=DEFAULT_DOC, copyright=DEFAULT_COPYRIGHT):
"""display usage for the main program (i.e. when no command supplied)
and exit
"""
commands = _COMMANDS.keys()
commands.sort()
- doc = __doc__
if doc != DEFAULT_DOC:
try:
- doc = __doc__ % ('<command>', '<command arguments>',
+ doc = doc % ('<command>', '<command arguments>',
'''\
Type "%prog <command> --help" for more information about a specific
command. Available commands are :\n''')
@@ -104,7 +103,8 @@ command. Available commands are :\n''')
if not cmd.hidden:
title = cmd.__doc__.split('.')[0]
print ' ', (command+padding)[:max_len], title
- print '\n', copyright
+ if copyright:
+ print '\n', copyright
sys.exit(status)
@@ -124,19 +124,19 @@ def cmd_run(cmdname, *args):
print command.help()
-def main_run(args, doc=DEFAULT_DOC):
+def main_run(args, doc=DEFAULT_DOC, copyright=DEFAULT_COPYRIGHT):
"""command line tool"""
try:
arg = args.pop(0)
except IndexError:
- main_usage(status=1, __doc__=doc)
+ main_usage(status=1, doc=doc, copyright=copyright)
if arg in ('-h', '--help'):
- main_usage(__doc__=doc)
+ main_usage(doc=doc, copyright=copyright)
try:
cmd_run(arg, *args)
except BadCommandUsage, err:
print 'ERROR: ', err
- main_usage(1, doc)
+ main_usage(1, doc=doc, copyright=copyright)
class ListCommandsCommand(Command):