-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcmd_illustrate_methods.py
More file actions
59 lines (42 loc) · 1.38 KB
/
Copy pathcmd_illustrate_methods.py
File metadata and controls
59 lines (42 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from typing import Optional, Tuple
try:
import gnureadline
import sys
sys.modules["readline"] = gnureadline
except ImportError:
pass
import cmd
class Illustrate(cmd.Cmd):
def cmdloop(self, intro=None) -> None:
print(f"cmdloop({intro})")
return cmd.Cmd.cmdloop(self, intro)
def preloop(self) -> None:
print("preloop()")
def postloop(self) -> None:
print("postloop()")
def parseline(self, line: str) -> Tuple[Optional[str], Optional[str], str]:
print(f"parseline({line!r})", end="")
ret = cmd.Cmd.parseline(self, line)
print(ret)
return ret
def onecmd(self, line: str) -> bool:
print(f"onecmd({line})")
return cmd.Cmd.onecmd(self, line)
def emptyline(self) -> bool:
print("emptyline()")
return cmd.Cmd.emptyline(self)
def default(self, line: str) -> bool:
print(f"default({line})")
return cmd.Cmd.default(self, line)
def precmd(self, line: str) -> str:
print(f"precmd({line})")
return cmd.Cmd.precmd(self, line)
def postcmd(self, stop: bool, line: str) -> bool:
print(f"postcmd({stop}, {line})")
return cmd.Cmd.postcmd(self, stop, line)
def do_greet(self, line):
print("hello", line)
def do_EOF(self, line):
return True
if __name__ == "__main__":
Illustrate().cmdloop()