This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients Błażej Michalik, remi.lapeyre, rhettinger, tuxtimo
Date 2018-06-30.16:46:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1530377192.51.0.56676864532.issue28657@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2018-06-30 16:46:32rhettingersetrecipients: + rhettinger, tuxtimo, Błażej Michalik, remi.lapeyre
2018-06-30 16:46:32rhettingersetmessageid: <1530377192.51.0.56676864532.issue28657@psf.upfronthosting.co.za>
2018-06-30 16:46:32rhettingerlinkissue28657 messages
2018-06-30 16:46:32rhettingercreate