Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
78016d86
Commit
78016d86
authored
Apr 27, 1995
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
renamed to CommandFrameWork
added ready() message added PostUsageMessage
parent
318b80d0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
2 deletions
+12
-2
Demo/pdist/cmdfw.py
Demo/pdist/cmdfw.py
+12
-2
No files found.
Demo/pdist/cmdfw.py
View file @
78016d86
"Framework for command line interfaces like CVS. See class CmdFrameWork."
"Framework for command line interfaces like CVS. See class CmdFrameWork."
class
C
m
dFrameWork
:
class
C
omman
dFrameWork
:
"""Framework class for command line interfaces like CVS.
"""Framework class for command line interfaces like CVS.
...
@@ -28,6 +28,8 @@ class CmdFrameWork:
...
@@ -28,6 +28,8 @@ class CmdFrameWork:
UsageMessage
=
\
UsageMessage
=
\
"usage: (name)s [flags] subcommand [subflags] [argument] ..."
"usage: (name)s [flags] subcommand [subflags] [argument] ..."
PostUsageMessage
=
None
GlobalFlags
=
''
GlobalFlags
=
''
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -44,6 +46,7 @@ class CmdFrameWork:
...
@@ -44,6 +46,7 @@ class CmdFrameWork:
return
self
.
usage
(
msg
)
return
self
.
usage
(
msg
)
self
.
options
(
opts
)
self
.
options
(
opts
)
if
not
args
:
if
not
args
:
self
.
ready
()
return
self
.
default
()
return
self
.
default
()
else
:
else
:
cmd
=
args
[
0
]
cmd
=
args
[
0
]
...
@@ -62,6 +65,7 @@ class CmdFrameWork:
...
@@ -62,6 +65,7 @@ class CmdFrameWork:
except
getopt
.
error
,
msg
:
except
getopt
.
error
,
msg
:
return
self
.
usage
(
return
self
.
usage
(
"subcommand %s: "
%
cmd
+
str
(
msg
))
"subcommand %s: "
%
cmd
+
str
(
msg
))
self
.
ready
()
return
method
(
opts
,
args
)
return
method
(
opts
,
args
)
def
options
(
self
,
opts
):
def
options
(
self
,
opts
):
...
@@ -74,6 +78,10 @@ class CmdFrameWork:
...
@@ -74,6 +78,10 @@ class CmdFrameWork:
print
'option'
,
o
,
'value'
,
`a`
print
'option'
,
o
,
'value'
,
`a`
print
"-"
*
40
print
"-"
*
40
def
ready
(
self
):
"""Called just before calling the subcommand."""
pass
def
usage
(
self
,
msg
=
None
):
def
usage
(
self
,
msg
=
None
):
"""Print usage message. Return suitable exit code (2)."""
"""Print usage message. Return suitable exit code (2)."""
if
msg
:
print
msg
if
msg
:
print
msg
...
@@ -100,6 +108,8 @@ class CmdFrameWork:
...
@@ -100,6 +108,8 @@ class CmdFrameWork:
names
.
sort
()
names
.
sort
()
for
name
in
names
:
for
name
in
names
:
print
docstrings
[
name
]
print
docstrings
[
name
]
if
self
.
PostUsageMessage
:
print
self
.
PostUsageMessage
return
2
return
2
def
default
(
self
):
def
default
(
self
):
...
@@ -111,7 +121,7 @@ class CmdFrameWork:
...
@@ -111,7 +121,7 @@ class CmdFrameWork:
def
test
():
def
test
():
"""Test script -- called when this module is run as a script."""
"""Test script -- called when this module is run as a script."""
import
sys
import
sys
class
Hello
(
C
m
dFrameWork
):
class
Hello
(
C
omman
dFrameWork
):
def
do_hello
(
self
,
opts
,
args
):
def
do_hello
(
self
,
opts
,
args
):
"hello -- print 'hello world', needs no arguments"
"hello -- print 'hello world', needs no arguments"
print
"Hello, world"
print
"Hello, world"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment