Message320791
Błażej, why is there a need to attach a function to the cli instance rather than the MyCmd class (which would be the norm for Python)?
from cmd import Cmd
class MyCmd(Cmd):
def do_documented_at_definition(self, arg):
""" This one is documented with docstring. """
print('dad', arg)
def do_documented_afterwards(self, arg):
print('documented afterwards', arg)
cli = MyCmd()
def do_new_command(self, arg):
print('new command', arg)
MyCmd.do_new_command = do_new_command
def help_documented_afterwards(*args):
print("I'm documenting", args)
MyCmd.help_documented_afterwards = help_documented_afterwards
cli.cmdloop()
Sample session:
(Cmd) help
Documented commands (type help <topic>):
========================================
documented_afterwards documented_at_definition help
Undocumented commands:
======================
new_command
(Cmd) help documented_at_definition
This one is documented with docstring.
(Cmd) help documented_afterwards
I'm documenting (<__main__.MyCmd object at 0x10eaf0c88>,)
(Cmd) documented_at_definition x
dad x
(Cmd) documented_afterwards y
documented afterwards y
(Cmd) new_command z
new command z
(Cmd) help new_command
*** No help on new_command |
|
Date |
User |
Action |
Args |
2018-06-30 16:46:32 | rhettinger | set | recipients:
+ rhettinger, tuxtimo, Błażej Michalik, remi.lapeyre |
2018-06-30 16:46:32 | rhettinger | set | messageid: <1530377192.51.0.56676864532.issue28657@psf.upfronthosting.co.za> |
2018-06-30 16:46:32 | rhettinger | link | issue28657 messages |
2018-06-30 16:46:32 | rhettinger | create | |
|