From f547ca26deeab436e875f4f3fdefe6c733445293 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt Date: Sat, 18 Feb 2017 17:45:03 -0500 Subject: Added optional parameter to cmd2.Cmd.__init() to enable an "ipy" command. If IPython is installed AND the __init__ initilizer is passed a "use_ipython" keyword argument set to "True", then and "ipy" command will be present. This ipy command starts an interactive IPython shell embedded within the cmd2 application. This IPython shell has access to all of the local variables (e.g. self), but any modifications made within it will NOT persist once it is exited. This IPython shell doesn't have tight integration with the Python interpreter running the cmd2 application like the Python interpreter available with the "py" command. However, due to features such as tab-completion and built-in help, the IPython shell is a lot more efficient for developers to use to debug their cmd2 applications - the introspection on self is extremely useful for getting to the bottom of thorny debugging problems. --- example/example.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'example/example.py') diff --git a/example/example.py b/example/example.py index 782c5e23..f39be5de 100755 --- a/example/example.py +++ b/example/example.py @@ -22,6 +22,10 @@ class CmdLineApp(Cmd): # Setting this true makes it run a shell command if a cmd2/cmd command doesn't exist # default_to_shell = True + def __init__(self): + # Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell + Cmd.__init__(self, use_ipython=False) + @options([make_option('-p', '--piglatin', action="store_true", help="atinLay"), make_option('-s', '--shout', action="store_true", help="N00B EMULATION MODE"), make_option('-r', '--repeat', type="int", help="output [n] times") -- cgit v1.2.1