Skip to content

Commit 3f1b75d

Browse files
authored
Merge pull request #813 from python-cmd2/pyscript_docs
Pyscript docs
2 parents 7dbb331 + 712070b commit 3f1b75d

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

docs/features/scripting.rst

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,31 @@ session.
5959
Python Scripts
6060
--------------
6161

62+
.. _arg_printer:
63+
https://github.com/python-cmd2/cmd2/blob/master/examples/scripts/arg_printer.py
64+
6265
If you require logic flow, loops, branching, or other advanced features, you
6366
can write a python script which executes in the context of your ``cmd2`` app.
64-
This script is run using the ``run_pyscript`` command. See
65-
:ref:`features/embedded_python_shells:Embedded Python Shells`.
67+
This script is run using the ``run_pyscript`` command. A simple example of
68+
using ``run_pyscript`` is shown below along with the arg_printer_ script::
69+
70+
(Cmd) run_pyscript examples/scripts/arg_printer.py foo bar 'baz 23'
71+
Running Python script 'arg_printer.py' which was called with 3 arguments
72+
arg 1: 'foo'
73+
arg 2: 'bar'
74+
arg 3: 'baz 23'
75+
76+
``run_pyscript`` supports tab-completion of file system paths, and as shown
77+
above it has the ability to pass command-line arguments to the scripts invoked.
78+
79+
Python scripts executed with ``run_pyscript`` can run ``cmd2`` application
80+
commands by using the syntax::
81+
82+
app(‘command args’)
83+
84+
where:
85+
86+
* ``app`` is a configurable name which can be changed by setting the
87+
``py_bridge_name`` attribute of your ``cmd2.Cmd`` class instance
88+
* ``command`` and ``args`` are entered exactly like they would be entered on
89+
the command line of your ``cmd2`` application

0 commit comments

Comments
 (0)