summaryrefslogtreecommitdiffstats
path: root/Demo/pdist
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1995-04-27 23:32:47 (GMT)
committerGuido van Rossum <guido@python.org>1995-04-27 23:32:47 (GMT)
commit78016d86304a810e623d03bd9081bcdfe60c5df9 (patch)
treeb97a196d3451990a41799468d0e34fe5e3743cae /Demo/pdist
parent318b80d0974255cefd37da38dc9f3c6b79910247 (diff)
downloadcpython-78016d86304a810e623d03bd9081bcdfe60c5df9.zip
cpython-78016d86304a810e623d03bd9081bcdfe60c5df9.tar.gz
cpython-78016d86304a810e623d03bd9081bcdfe60c5df9.tar.bz2
renamed to CommandFrameWork
added ready() message added PostUsageMessage
Diffstat (limited to 'Demo/pdist')
-rwxr-xr-xDemo/pdist/cmdfw.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/Demo/pdist/cmdfw.py b/Demo/pdist/cmdfw.py
index c6eb916..a0c6f5d 100755
--- a/Demo/pdist/cmdfw.py
+++ b/Demo/pdist/cmdfw.py
@@ -1,7 +1,7 @@
"Framework for command line interfaces like CVS. See class CmdFrameWork."
-class CmdFrameWork:
+class CommandFrameWork:
"""Framework class for command line interfaces like CVS.
@@ -28,6 +28,8 @@ class CmdFrameWork:
UsageMessage = \
"usage: (name)s [flags] subcommand [subflags] [argument] ..."
+ PostUsageMessage = None
+
GlobalFlags = ''
def __init__(self):
@@ -44,6 +46,7 @@ class CmdFrameWork:
return self.usage(msg)
self.options(opts)
if not args:
+ self.ready()
return self.default()
else:
cmd = args[0]
@@ -62,6 +65,7 @@ class CmdFrameWork:
except getopt.error, msg:
return self.usage(
"subcommand %s: " % cmd + str(msg))
+ self.ready()
return method(opts, args)
def options(self, opts):
@@ -74,6 +78,10 @@ class CmdFrameWork:
print 'option', o, 'value', `a`
print "-"*40
+ def ready(self):
+ """Called just before calling the subcommand."""
+ pass
+
def usage(self, msg = None):
"""Print usage message. Return suitable exit code (2)."""
if msg: print msg
@@ -100,6 +108,8 @@ class CmdFrameWork:
names.sort()
for name in names:
print docstrings[name]
+ if self.PostUsageMessage:
+ print self.PostUsageMessage
return 2
def default(self):
@@ -111,7 +121,7 @@ class CmdFrameWork:
def test():
"""Test script -- called when this module is run as a script."""
import sys
- class Hello(CmdFrameWork):
+ class Hello(CommandFrameWork):
def do_hello(self, opts, args):
"hello -- print 'hello world', needs no arguments"
print "Hello, world"