evennia/docs/1.0-dev/_modules/evennia/contrib/unixcommand.html
2021-03-06 01:37:43 +01:00

400 lines
No EOL
32 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>evennia.contrib.unixcommand &#8212; Evennia 1.0-dev documentation</title>
<link rel="stylesheet" href="../../../_static/nature.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<link rel="shortcut icon" href="../../../_static/favicon.ico"/>
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 1.0-dev</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../../evennia.html" accesskey="U">evennia</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">evennia.contrib.unixcommand</a></li>
</ul>
<div class="develop">develop branch</div>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for evennia.contrib.unixcommand</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Unix-like Command style parent</span>
<span class="sd">Evennia contribution, Vincent Le Geoff 2017</span>
<span class="sd">This module contains a command class that allows for unix-style command syntax in-game, using</span>
<span class="sd">--options, positional arguments and stuff like -n 10 etc similarly to a unix command. It might not</span>
<span class="sd">the best syntax for the average player but can be really useful for builders when they need to have</span>
<span class="sd">a single command do many things with many options. It uses the ArgumentParser from Python&#39;s standard</span>
<span class="sd">library under the hood.</span>
<span class="sd">To use, inherit `UnixCommand` from this module from your own commands. You need</span>
<span class="sd">to override two methods:</span>
<span class="sd">- The `init_parser` method, which adds options to the parser. Note that you should normally</span>
<span class="sd"> *not* override the normal `parse` method when inheriting from `UnixCommand`.</span>
<span class="sd">- The `func` method, called to execute the command once parsed (like any Command).</span>
<span class="sd">Here&#39;s a short example:</span>
<span class="sd">```python</span>
<span class="sd">class CmdPlant(UnixCommand):</span>
<span class="sd"> &#39;&#39;&#39;</span>
<span class="sd"> Plant a tree or plant.</span>
<span class="sd"> This command is used to plant something in the room you are in.</span>
<span class="sd"> Examples:</span>
<span class="sd"> plant orange -a 8</span>
<span class="sd"> plant strawberry --hidden</span>
<span class="sd"> plant potato --hidden --age 5</span>
<span class="sd"> &#39;&#39;&#39;</span>
<span class="sd"> key = &quot;plant&quot;</span>
<span class="sd"> def init_parser(self):</span>
<span class="sd"> &quot;Add the arguments to the parser.&quot;</span>
<span class="sd"> # &#39;self.parser&#39; inherits `argparse.ArgumentParser`</span>
<span class="sd"> self.parser.add_argument(&quot;key&quot;,</span>
<span class="sd"> help=&quot;the key of the plant to be planted here&quot;)</span>
<span class="sd"> self.parser.add_argument(&quot;-a&quot;, &quot;--age&quot;, type=int,</span>
<span class="sd"> default=1, help=&quot;the age of the plant to be planted&quot;)</span>
<span class="sd"> self.parser.add_argument(&quot;--hidden&quot;, action=&quot;store_true&quot;,</span>
<span class="sd"> help=&quot;should the newly-planted plant be hidden to players?&quot;)</span>
<span class="sd"> def func(self):</span>
<span class="sd"> &quot;func is called only if the parser succeeded.&quot;</span>
<span class="sd"> # &#39;self.opts&#39; contains the parsed options</span>
<span class="sd"> key = self.opts.key</span>
<span class="sd"> age = self.opts.age</span>
<span class="sd"> hidden = self.opts.hidden</span>
<span class="sd"> self.msg(&quot;Going to plant &#39;{}&#39;, age={}, hidden={}.&quot;.format(</span>
<span class="sd"> key, age, hidden))</span>
<span class="sd">```</span>
<span class="sd">To see the full power of argparse and the types of supported options, visit</span>
<span class="sd">[the documentation of argparse](https://docs.python.org/2/library/argparse.html).</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">argparse</span>
<span class="kn">import</span> <span class="nn">shlex</span>
<span class="kn">from</span> <span class="nn">textwrap</span> <span class="kn">import</span> <span class="n">dedent</span>
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span><span class="p">,</span> <span class="n">InterruptCommand</span>
<span class="kn">from</span> <span class="nn">evennia.utils.ansi</span> <span class="kn">import</span> <span class="n">raw</span>
<div class="viewcode-block" id="ParseError"><a class="viewcode-back" href="../../../api/evennia.contrib.unixcommand.html#evennia.contrib.unixcommand.ParseError">[docs]</a><span class="k">class</span> <span class="nc">ParseError</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;An error occurred during parsing.&quot;&quot;&quot;</span>
<span class="k">pass</span></div>
<div class="viewcode-block" id="UnixCommandParser"><a class="viewcode-back" href="../../../api/evennia.contrib.unixcommand.html#evennia.contrib.unixcommand.UnixCommandParser">[docs]</a><span class="k">class</span> <span class="nc">UnixCommandParser</span><span class="p">(</span><span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;A modifier command parser for unix commands.</span>
<span class="sd"> This parser is used to replace `argparse.ArgumentParser`. It</span>
<span class="sd"> is aware of the command calling it, and can more easily report to</span>
<span class="sd"> the caller. Some features (like the &quot;brutal exit&quot; of the original</span>
<span class="sd"> parser) are disabled or replaced. This parser is used by UnixCommand</span>
<span class="sd"> and creating one directly isn&#39;t recommended nor necessary. Even</span>
<span class="sd"> adding a sub-command will use this replaced parser automatically.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<div class="viewcode-block" id="UnixCommandParser.__init__"><a class="viewcode-back" href="../../../api/evennia.contrib.unixcommand.html#evennia.contrib.unixcommand.UnixCommandParser.__init__">[docs]</a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">prog</span><span class="p">,</span> <span class="n">description</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">epilog</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">command</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Build a UnixCommandParser with a link to the command using it.</span>
<span class="sd"> Args:</span>
<span class="sd"> prog (str): the program name (usually the command key).</span>
<span class="sd"> description (str): a very brief line to show in the usage text.</span>
<span class="sd"> epilog (str): the epilog to show below options.</span>
<span class="sd"> command (Command): the command calling the parser.</span>
<span class="sd"> Keyword Args:</span>
<span class="sd"> Additional keyword arguments are directly sent to</span>
<span class="sd"> `argparse.ArgumentParser`. You will find them on the</span>
<span class="sd"> [parser&#39;s documentation](https://docs.python.org/2/library/argparse.html).</span>
<span class="sd"> Note:</span>
<span class="sd"> It&#39;s doubtful you would need to create this parser manually.</span>
<span class="sd"> The `UnixCommand` does that automatically. If you create</span>
<span class="sd"> sub-commands, this class will be used.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">prog</span> <span class="o">=</span> <span class="n">prog</span> <span class="ow">or</span> <span class="n">command</span><span class="o">.</span><span class="n">key</span>
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span>
<span class="n">prog</span><span class="o">=</span><span class="n">prog</span><span class="p">,</span> <span class="n">description</span><span class="o">=</span><span class="n">description</span><span class="p">,</span> <span class="n">conflict_handler</span><span class="o">=</span><span class="s2">&quot;resolve&quot;</span><span class="p">,</span> <span class="n">add_help</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span>
<span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">command</span> <span class="o">=</span> <span class="n">command</span>
<span class="bp">self</span><span class="o">.</span><span class="n">post_help</span> <span class="o">=</span> <span class="n">epilog</span>
<span class="k">def</span> <span class="nf">n_exit</span><span class="p">(</span><span class="n">code</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">msg</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="k">raise</span> <span class="n">ParseError</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">exit</span> <span class="o">=</span> <span class="n">n_exit</span>
<span class="c1"># Replace the -h/--help</span>
<span class="bp">self</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span>
<span class="s2">&quot;-h&quot;</span><span class="p">,</span> <span class="s2">&quot;--help&quot;</span><span class="p">,</span> <span class="n">nargs</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="n">HelpAction</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">&quot;display the command help&quot;</span>
<span class="p">)</span></div>
<div class="viewcode-block" id="UnixCommandParser.format_usage"><a class="viewcode-back" href="../../../api/evennia.contrib.unixcommand.html#evennia.contrib.unixcommand.UnixCommandParser.format_usage">[docs]</a> <span class="k">def</span> <span class="nf">format_usage</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return the usage line.</span>
<span class="sd"> Note:</span>
<span class="sd"> This method is present to return the raw-escaped usage line,</span>
<span class="sd"> in order to avoid unintentional color codes.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">raw</span><span class="p">(</span><span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">format_usage</span><span class="p">())</span></div>
<div class="viewcode-block" id="UnixCommandParser.format_help"><a class="viewcode-back" href="../../../api/evennia.contrib.unixcommand.html#evennia.contrib.unixcommand.UnixCommandParser.format_help">[docs]</a> <span class="k">def</span> <span class="nf">format_help</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return the parser help, including its epilog.</span>
<span class="sd"> Note:</span>
<span class="sd"> This method is present to return the raw-escaped help,</span>
<span class="sd"> in order to avoid unintentional color codes. Color codes</span>
<span class="sd"> in the epilog (the command docstring) are supported.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">autohelp</span> <span class="o">=</span> <span class="n">raw</span><span class="p">(</span><span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">format_help</span><span class="p">())</span>
<span class="k">return</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span> <span class="n">autohelp</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">post_help</span></div>
<div class="viewcode-block" id="UnixCommandParser.print_usage"><a class="viewcode-back" href="../../../api/evennia.contrib.unixcommand.html#evennia.contrib.unixcommand.UnixCommandParser.print_usage">[docs]</a> <span class="k">def</span> <span class="nf">print_usage</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">file</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Print the usage to the caller.</span>
<span class="sd"> Args:</span>
<span class="sd"> file (file-object): not used here, the caller is used.</span>
<span class="sd"> Note:</span>
<span class="sd"> This method will override `argparse.ArgumentParser`&#39;s in order</span>
<span class="sd"> to not display the help on stdout or stderr, but to the</span>
<span class="sd"> command&#39;s caller.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">command</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">command</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">format_usage</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span></div>
<div class="viewcode-block" id="UnixCommandParser.print_help"><a class="viewcode-back" href="../../../api/evennia.contrib.unixcommand.html#evennia.contrib.unixcommand.UnixCommandParser.print_help">[docs]</a> <span class="k">def</span> <span class="nf">print_help</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">file</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Print the help to the caller.</span>
<span class="sd"> Args:</span>
<span class="sd"> file (file-object): not used here, the caller is used.</span>
<span class="sd"> Note:</span>
<span class="sd"> This method will override `argparse.ArgumentParser`&#39;s in order</span>
<span class="sd"> to not display the help on stdout or stderr, but to the</span>
<span class="sd"> command&#39;s caller.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">command</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">command</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">format_help</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span></div></div>
<div class="viewcode-block" id="HelpAction"><a class="viewcode-back" href="../../../api/evennia.contrib.unixcommand.html#evennia.contrib.unixcommand.HelpAction">[docs]</a><span class="k">class</span> <span class="nc">HelpAction</span><span class="p">(</span><span class="n">argparse</span><span class="o">.</span><span class="n">Action</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Override the -h/--help action in the default parser.</span>
<span class="sd"> Using the default -h/--help will call the exit function in different</span>
<span class="sd"> ways, preventing the entire help message to be provided. Hence</span>
<span class="sd"> this override.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parser</span><span class="p">,</span> <span class="n">namespace</span><span class="p">,</span> <span class="n">values</span><span class="p">,</span> <span class="n">option_string</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;If asked for help, display to the caller.&quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">parser</span><span class="o">.</span><span class="n">command</span><span class="p">:</span>
<span class="n">parser</span><span class="o">.</span><span class="n">command</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="n">parser</span><span class="o">.</span><span class="n">format_help</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span>
<span class="n">parser</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span></div>
<div class="viewcode-block" id="UnixCommand"><a class="viewcode-back" href="../../../api/evennia.contrib.unixcommand.html#evennia.contrib.unixcommand.UnixCommand">[docs]</a><span class="k">class</span> <span class="nc">UnixCommand</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Unix-type commands, supporting short and long options.</span>
<span class="sd"> This command syntax uses the Unix-style commands with short options</span>
<span class="sd"> (-X) and long options (--something). The `argparse` module is</span>
<span class="sd"> used to parse the command.</span>
<span class="sd"> In order to use it, you should override two methods:</span>
<span class="sd"> - `init_parser`: this method is called when the command is created.</span>
<span class="sd"> It can be used to set options in the parser. `self.parser`</span>
<span class="sd"> contains the `argparse.ArgumentParser`, so you can add arguments</span>
<span class="sd"> here.</span>
<span class="sd"> - `func`: this method is called to execute the command, but after</span>
<span class="sd"> the parser has checked the arguments given to it are valid.</span>
<span class="sd"> You can access the namespace of valid arguments in `self.opts`</span>
<span class="sd"> at this point.</span>
<span class="sd"> The help of UnixCommands is derived from the docstring, in a</span>
<span class="sd"> slightly different way than usual: the first line of the docstring</span>
<span class="sd"> is used to represent the program description (the very short</span>
<span class="sd"> line at the top of the help message). The other lines below are</span>
<span class="sd"> used as the program&#39;s &quot;epilog&quot;, displayed below the options. It</span>
<span class="sd"> means in your docstring, you don&#39;t have to write the options.</span>
<span class="sd"> They will be automatically provided by the parser and displayed</span>
<span class="sd"> accordingly. The `argparse` module provides a default &#39;-h&#39; or</span>
<span class="sd"> &#39;--help&#39; option on the command. Typing |whelp commandname|n will</span>
<span class="sd"> display the same as |wcommandname -h|n, though this behavior can</span>
<span class="sd"> be changed.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<div class="viewcode-block" id="UnixCommand.__init__"><a class="viewcode-back" href="../../../api/evennia.contrib.unixcommand.html#evennia.contrib.unixcommand.UnixCommand.__init__">[docs]</a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> The lockhandler works the same as for objects.</span>
<span class="sd"> optional kwargs will be set as properties on the Command at runtime,</span>
<span class="sd"> overloading evential same-named class properties.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="c1"># Create the empty UnixCommandParser, inheriting argparse.ArgumentParser</span>
<span class="n">lines</span> <span class="o">=</span> <span class="n">dedent</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="vm">__doc__</span><span class="o">.</span><span class="n">strip</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">))</span><span class="o">.</span><span class="n">splitlines</span><span class="p">()</span>
<span class="n">description</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
<span class="n">epilog</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">:])</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">parser</span> <span class="o">=</span> <span class="n">UnixCommandParser</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="n">description</span><span class="p">,</span> <span class="n">epilog</span><span class="p">,</span> <span class="n">command</span><span class="o">=</span><span class="bp">self</span><span class="p">)</span>
<span class="c1"># Fill the argument parser</span>
<span class="bp">self</span><span class="o">.</span><span class="n">init_parser</span><span class="p">()</span></div>
<div class="viewcode-block" id="UnixCommand.init_parser"><a class="viewcode-back" href="../../../api/evennia.contrib.unixcommand.html#evennia.contrib.unixcommand.UnixCommand.init_parser">[docs]</a> <span class="k">def</span> <span class="nf">init_parser</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Configure the argument parser, adding in options.</span>
<span class="sd"> Note:</span>
<span class="sd"> This method is to be overridden in order to add options</span>
<span class="sd"> to the argument parser. Use `self.parser`, which contains</span>
<span class="sd"> the `argparse.ArgumentParser`. You can, for instance,</span>
<span class="sd"> use its `add_argument` method.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">pass</span></div>
<div class="viewcode-block" id="UnixCommand.func"><a class="viewcode-back" href="../../../api/evennia.contrib.unixcommand.html#evennia.contrib.unixcommand.UnixCommand.func">[docs]</a> <span class="k">def</span> <span class="nf">func</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Override to handle the command execution.&quot;&quot;&quot;</span>
<span class="k">pass</span></div>
<div class="viewcode-block" id="UnixCommand.get_help"><a class="viewcode-back" href="../../../api/evennia.contrib.unixcommand.html#evennia.contrib.unixcommand.UnixCommand.get_help">[docs]</a> <span class="k">def</span> <span class="nf">get_help</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">caller</span><span class="p">,</span> <span class="n">cmdset</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return the help message for this command and this caller.</span>
<span class="sd"> Args:</span>
<span class="sd"> caller (Object or Player): the caller asking for help on the command.</span>
<span class="sd"> cmdset (CmdSet): the command set (if you need additional commands).</span>
<span class="sd"> Returns:</span>
<span class="sd"> docstring (str): the help text to provide the caller for this command.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">parser</span><span class="o">.</span><span class="n">format_help</span><span class="p">()</span></div>
<div class="viewcode-block" id="UnixCommand.parse"><a class="viewcode-back" href="../../../api/evennia.contrib.unixcommand.html#evennia.contrib.unixcommand.UnixCommand.parse">[docs]</a> <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Process arguments provided in `self.args`.</span>
<span class="sd"> Note:</span>
<span class="sd"> You should not override this method. Consider overriding</span>
<span class="sd"> `init_parser` instead.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">try</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">opts</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">(</span><span class="n">shlex</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="p">))</span>
<span class="k">except</span> <span class="n">ParseError</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span>
<span class="n">msg</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)</span>
<span class="k">if</span> <span class="n">msg</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
<span class="k">raise</span> <span class="n">InterruptCommand</span></div></div>
</pre></div>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="../../../index.html">
<img class="logo" src="../../../_static/evennia_logo.png" alt="Logo"/>
</a></p>
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script><h3>Links</h3>
<ul>
<li><a href="https://www.evennia.com">Home page</a> </li>
<li><a href="https://github.com/evennia/evennia">Evennia Github</a> </li>
<li><a href="http://games.evennia.com">Game Index</a> </li>
<li><a href="http://webchat.freenode.net/?channels=evennia&uio=MT1mYWxzZSY5PXRydWUmMTE9MTk1JjEyPXRydWUbb">IRC</a> -
<a href="https://discord.gg/NecFePw">Discord</a> -
<a href="https://groups.google.com/forum/#%21forum/evennia">Forums</a>
</li>
<li><a href="http://evennia.blogspot.com/">Evennia Dev blog</a> </li>
</ul>
<h3>Versions</h3>
<ul>
<li><a href="unixcommand.html">1.0-dev (develop branch)</a></li>
<li><a href="../../../../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../../../index.html">Evennia 1.0-dev</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="../../evennia.html" >evennia</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">evennia.contrib.unixcommand</a></li>
</ul>
<div class="develop">develop branch</div>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2020, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.
</div>
</body>
</html>