diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-11-17 15:47:08 -0500 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-11-17 15:47:08 -0500 |
commit | 393bf67b0b1c193e9a75cf02ba1acfa55d8706fb (patch) | |
tree | ced76911369c4f67b81149dead1887b7901d301c /docs/features | |
parent | 73535e1ff82b49c594fc694ef0ea898d46742750 (diff) | |
download | cmd2-git-393bf67b0b1c193e9a75cf02ba1acfa55d8706fb.tar.gz |
Started adding Pyscript documentation
Diffstat (limited to 'docs/features')
-rw-r--r-- | docs/features/scripting.rst | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/docs/features/scripting.rst b/docs/features/scripting.rst index b41855ca..62af2e6d 100644 --- a/docs/features/scripting.rst +++ b/docs/features/scripting.rst @@ -59,7 +59,31 @@ session. Python Scripts -------------- +.. _arg_printer: + https://github.com/python-cmd2/cmd2/blob/master/examples/scripts/arg_printer.py + If you require logic flow, loops, branching, or other advanced features, you can write a python script which executes in the context of your ``cmd2`` app. -This script is run using the ``run_pyscript`` command. See -:ref:`features/embedded_python_shells:Embedded Python Shells`. +This script is run using the ``run_pyscript`` command. A simple example of +using ``run_pyscript`` is shown below along with the arg_printer_ script:: + + (Cmd) run_pyscript examples/scripts/arg_printer.py foo bar 'baz 23' + Running Python script 'arg_printer.py' which was called with 3 arguments + arg 1: 'foo' + arg 2: 'bar' + arg 3: 'baz 23' + +``run_pyscript`` supports tab-completion of file system paths, and as shown +above it has the ability to pass command-line arguments to the scripts invoked. + +Python scripts executed with ``run_pyscript`` can run ``cmd2`` application +commands by using the syntax:: + + app(‘command args’) + +where: + +* ``app`` is a configurable name which can be changed by setting the + ``py_bridge_name`` attribute of your ``cmd2.Cmd`` class instance +* ``command`` and ``args`` are entered exactly like they would be entered on + the command line of your ``cmd2`` application |