Raymond Hettinger <raymond.hettin...@gmail.com> added the comment:

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

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue28657>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to