mirror of
https://github.com/evennia/evennia.git
synced 2026-03-18 22:06:30 +01:00
444 lines
No EOL
34 KiB
HTML
444 lines
No EOL
34 KiB
HTML
|
||
<!DOCTYPE html>
|
||
|
||
<html>
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||
|
||
<title>evennia.contrib.base_systems.unixcommand.unixcommand — Evennia 2.x 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" />
|
||
<link rel="next" title="evennia.contrib.full_systems" href="evennia.contrib.full_systems.html" />
|
||
<link rel="prev" title="evennia.contrib.base_systems.unixcommand.tests" href="evennia.contrib.base_systems.unixcommand.tests.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="right" >
|
||
<a href="evennia.contrib.full_systems.html" title="evennia.contrib.full_systems"
|
||
accesskey="N">next</a> |</li>
|
||
<li class="right" >
|
||
<a href="evennia.contrib.base_systems.unixcommand.tests.html" title="evennia.contrib.base_systems.unixcommand.tests"
|
||
accesskey="P">previous</a> |</li>
|
||
<li class="nav-item nav-item-0"><a href="../index.html">Evennia 2.x</a> »</li>
|
||
<li class="nav-item nav-item-1"><a href="../Evennia-API.html" >API Summary</a> »</li>
|
||
<li class="nav-item nav-item-2"><a href="evennia-api.html" >evennia</a> »</li>
|
||
<li class="nav-item nav-item-3"><a href="evennia.html" >evennia</a> »</li>
|
||
<li class="nav-item nav-item-4"><a href="evennia.contrib.html" >evennia.contrib</a> »</li>
|
||
<li class="nav-item nav-item-5"><a href="evennia.contrib.base_systems.html" >evennia.contrib.base_systems</a> »</li>
|
||
<li class="nav-item nav-item-6"><a href="evennia.contrib.base_systems.unixcommand.html" accesskey="U">evennia.contrib.base_systems.unixcommand</a> »</li>
|
||
<li class="nav-item nav-item-this"><a href="">evennia.contrib.base_systems.unixcommand.unixcommand</a></li>
|
||
</ul>
|
||
</div>
|
||
|
||
<div class="document">
|
||
|
||
<div class="documentwrapper">
|
||
<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>
|
||
<h4>Previous topic</h4>
|
||
<p class="topless"><a href="evennia.contrib.base_systems.unixcommand.tests.html"
|
||
title="previous chapter">evennia.contrib.base_systems.unixcommand.tests</a></p>
|
||
<h4>Next topic</h4>
|
||
<p class="topless"><a href="evennia.contrib.full_systems.html"
|
||
title="next chapter">evennia.contrib.full_systems</a></p>
|
||
<div role="note" aria-label="source link">
|
||
<!--h3>This Page</h3-->
|
||
<ul class="this-page-menu">
|
||
<li><a href="../_sources/api/evennia.contrib.base_systems.unixcommand.unixcommand.md.txt"
|
||
rel="nofollow">Show Page Source</a></li>
|
||
</ul>
|
||
</div><h3>Links</h3>
|
||
<ul>
|
||
<li><a href="https://www.evennia.com/docs/latest/index.html">Documentation Top</a> </li>
|
||
<li><a href="https://www.evennia.com">Evennia Home</a> </li>
|
||
<li><a href="https://github.com/evennia/evennia">Github</a> </li>
|
||
<li><a href="http://games.evennia.com">Game Index</a> </li>
|
||
<li>
|
||
<a href="https://discord.gg/AJJpcRUhtF">Discord</a> -
|
||
<a href="https://github.com/evennia/evennia/discussions">Discussions</a> -
|
||
<a href="https://evennia.blogspot.com/">Blog</a>
|
||
</li>
|
||
</ul>
|
||
<h3>Doc Versions</h3>
|
||
<ul>
|
||
|
||
<li><a href="evennia.contrib.base_systems.unixcommand.unixcommand.html">2.x (main branch)</a></li>
|
||
<ul>
|
||
<li><a href="../1.3.0/index.html">1.3.0 (v1.3.0 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="bodywrapper">
|
||
<div class="body" role="main">
|
||
|
||
<section id="module-evennia.contrib.base_systems.unixcommand.unixcommand">
|
||
<span id="evennia-contrib-base-systems-unixcommand-unixcommand"></span><h1>evennia.contrib.base_systems.unixcommand.unixcommand<a class="headerlink" href="#module-evennia.contrib.base_systems.unixcommand.unixcommand" title="Permalink to this headline">¶</a></h1>
|
||
<p>Unix-like Command style parent</p>
|
||
<p>Evennia contribution, Vincent Le Geoff 2017</p>
|
||
<p>This module contains a command class that allows for unix-style command syntax in-game, using
|
||
–options, positional arguments and stuff like -n 10 etc similarly to a unix command. It might not
|
||
the best syntax for the average player but can be really useful for builders when they need to have
|
||
a single command do many things with many options. It uses the ArgumentParser from Python’s standard
|
||
library under the hood.</p>
|
||
<p>To use, inherit <strong>UnixCommand</strong> from this module from your own commands. You need
|
||
to override two methods:</p>
|
||
<ul class="simple">
|
||
<li><dl class="simple">
|
||
<dt>The <strong>init_parser</strong> method, which adds options to the parser. Note that you should normally</dt><dd><p><em>not</em> override the normal <strong>parse</strong> method when inheriting from <strong>UnixCommand</strong>.</p>
|
||
</dd>
|
||
</dl>
|
||
</li>
|
||
<li><p>The <strong>func</strong> method, called to execute the command once parsed (like any Command).</p></li>
|
||
</ul>
|
||
<p>Here’s a short example:</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia.contrib.base_systems.unixcommand</span> <span class="kn">import</span> <span class="n">UnixCommand</span>
|
||
|
||
|
||
<span class="k">class</span> <span class="nc">CmdPlant</span><span class="p">(</span><span class="n">UnixCommand</span><span class="p">):</span>
|
||
|
||
<span class="w"> </span><span class="sd">'''</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"> '''</span>
|
||
|
||
<span class="n">key</span> <span class="o">=</span> <span class="s2">"plant"</span>
|
||
|
||
<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="s2">"Add the arguments to the parser."</span>
|
||
<span class="c1"># 'self.parser' inherits **argparse.ArgumentParser**</span>
|
||
<span class="bp">self</span><span class="o">.</span><span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">"key"</span><span class="p">,</span>
|
||
<span class="n">help</span><span class="o">=</span><span class="s2">"the key of the plant to be planted here"</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">add_argument</span><span class="p">(</span><span class="s2">"-a"</span><span class="p">,</span> <span class="s2">"--age"</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">int</span><span class="p">,</span>
|
||
<span class="n">default</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">"the age of the plant to be planted"</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">add_argument</span><span class="p">(</span><span class="s2">"--hidden"</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">"store_true"</span><span class="p">,</span>
|
||
<span class="n">help</span><span class="o">=</span><span class="s2">"should the newly-planted plant be hidden to players?"</span><span class="p">)</span>
|
||
|
||
<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="s2">"func is called only if the parser succeeded."</span>
|
||
<span class="c1"># 'self.opts' contains the parsed options</span>
|
||
<span class="n">key</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">opts</span><span class="o">.</span><span class="n">key</span>
|
||
<span class="n">age</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">opts</span><span class="o">.</span><span class="n">age</span>
|
||
<span class="n">hidden</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">opts</span><span class="o">.</span><span class="n">hidden</span>
|
||
<span class="bp">self</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="s2">"Going to plant '</span><span class="si">{}</span><span class="s2">', age=</span><span class="si">{}</span><span class="s2">, hidden=</span><span class="si">{}</span><span class="s2">."</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
|
||
<span class="n">key</span><span class="p">,</span> <span class="n">age</span><span class="p">,</span> <span class="n">hidden</span><span class="p">))</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>To see the full power of argparse and the types of supported options, visit
|
||
[the documentation of argparse](<a class="reference external" href="https://docs.python.org/2/library/argparse.html">https://docs.python.org/2/library/argparse.html</a>).</p>
|
||
<dl class="py exception">
|
||
<dt id="evennia.contrib.base_systems.unixcommand.unixcommand.ParseError">
|
||
<em class="property">exception </em><code class="sig-prename descclassname">evennia.contrib.base_systems.unixcommand.unixcommand.</code><code class="sig-name descname">ParseError</code><a class="reference internal" href="../_modules/evennia/contrib/base_systems/unixcommand/unixcommand.html#ParseError"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.base_systems.unixcommand.unixcommand.ParseError" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">Exception</span></code></p>
|
||
<p>An error occurred during parsing.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py class">
|
||
<dt id="evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommandParser">
|
||
<em class="property">class </em><code class="sig-prename descclassname">evennia.contrib.base_systems.unixcommand.unixcommand.</code><code class="sig-name descname">UnixCommandParser</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">prog</span></em>, <em class="sig-param"><span class="n">description</span><span class="o">=</span><span class="default_value">''</span></em>, <em class="sig-param"><span class="n">epilog</span><span class="o">=</span><span class="default_value">''</span></em>, <em class="sig-param"><span class="n">command</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/base_systems/unixcommand/unixcommand.html#UnixCommandParser"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommandParser" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">argparse.ArgumentParser</span></code></p>
|
||
<p>A modifier command parser for unix commands.</p>
|
||
<p>This parser is used to replace <strong>argparse.ArgumentParser</strong>. It
|
||
is aware of the command calling it, and can more easily report to
|
||
the caller. Some features (like the “brutal exit” of the original
|
||
parser) are disabled or replaced. This parser is used by UnixCommand
|
||
and creating one directly isn’t recommended nor necessary. Even
|
||
adding a sub-command will use this replaced parser automatically.</p>
|
||
<dl class="py method">
|
||
<dt id="evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommandParser.__init__">
|
||
<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">prog</span></em>, <em class="sig-param"><span class="n">description</span><span class="o">=</span><span class="default_value">''</span></em>, <em class="sig-param"><span class="n">epilog</span><span class="o">=</span><span class="default_value">''</span></em>, <em class="sig-param"><span class="n">command</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/base_systems/unixcommand/unixcommand.html#UnixCommandParser.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommandParser.__init__" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Build a UnixCommandParser with a link to the command using it.</p>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Parameters</dt>
|
||
<dd class="field-odd"><ul class="simple">
|
||
<li><p><strong>prog</strong> (<em>str</em>) – the program name (usually the command key).</p></li>
|
||
<li><p><strong>description</strong> (<em>str</em>) – a very brief line to show in the usage text.</p></li>
|
||
<li><p><strong>epilog</strong> (<em>str</em>) – the epilog to show below options.</p></li>
|
||
<li><p><strong>command</strong> (<a class="reference internal" href="evennia.commands.command.html#evennia.commands.command.Command" title="evennia.commands.command.Command"><em>Command</em></a>) – the command calling the parser.</p></li>
|
||
</ul>
|
||
</dd>
|
||
<dt class="field-even">Keyword Arguments</dt>
|
||
<dd class="field-even"><ul class="simple">
|
||
<li><p><strong>keyword arguments are directly sent to</strong> (<em>Additional</em>) – </p></li>
|
||
<li><p><strong>You will find them on the</strong> (<em>argparse.ArgumentParser.</em>) – </p></li>
|
||
<li><p><strong>documentation</strong><strong>]</strong><strong>(</strong><strong>https</strong> (<em>[</em><em>parser's</em>) – //docs.python.org/2/library/argparse.html).</p></li>
|
||
</ul>
|
||
</dd>
|
||
</dl>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>It’s doubtful you would need to create this parser manually.
|
||
The <strong>UnixCommand</strong> does that automatically. If you create
|
||
sub-commands, this class will be used.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommandParser.format_usage">
|
||
<code class="sig-name descname">format_usage</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/base_systems/unixcommand/unixcommand.html#UnixCommandParser.format_usage"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommandParser.format_usage" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Return the usage line.</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>This method is present to return the raw-escaped usage line,
|
||
in order to avoid unintentional color codes.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommandParser.format_help">
|
||
<code class="sig-name descname">format_help</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/base_systems/unixcommand/unixcommand.html#UnixCommandParser.format_help"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommandParser.format_help" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Return the parser help, including its epilog.</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>This method is present to return the raw-escaped help,
|
||
in order to avoid unintentional color codes. Color codes
|
||
in the epilog (the command docstring) are supported.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommandParser.print_usage">
|
||
<code class="sig-name descname">print_usage</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">file</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/base_systems/unixcommand/unixcommand.html#UnixCommandParser.print_usage"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommandParser.print_usage" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Print the usage to the caller.</p>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Parameters</dt>
|
||
<dd class="field-odd"><p><strong>file</strong> (<em>file-object</em>) – not used here, the caller is used.</p>
|
||
</dd>
|
||
</dl>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>This method will override <strong>argparse.ArgumentParser</strong>’s in order
|
||
to not display the help on stdout or stderr, but to the
|
||
command’s caller.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommandParser.print_help">
|
||
<code class="sig-name descname">print_help</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">file</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/base_systems/unixcommand/unixcommand.html#UnixCommandParser.print_help"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommandParser.print_help" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Print the help to the caller.</p>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Parameters</dt>
|
||
<dd class="field-odd"><p><strong>file</strong> (<em>file-object</em>) – not used here, the caller is used.</p>
|
||
</dd>
|
||
</dl>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>This method will override <strong>argparse.ArgumentParser</strong>’s in order
|
||
to not display the help on stdout or stderr, but to the
|
||
command’s caller.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
</dd></dl>
|
||
|
||
<dl class="py class">
|
||
<dt id="evennia.contrib.base_systems.unixcommand.unixcommand.HelpAction">
|
||
<em class="property">class </em><code class="sig-prename descclassname">evennia.contrib.base_systems.unixcommand.unixcommand.</code><code class="sig-name descname">HelpAction</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">option_strings</span></em>, <em class="sig-param"><span class="n">dest</span></em>, <em class="sig-param"><span class="n">nargs</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">const</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">default</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">type</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">choices</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">required</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">help</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">metavar</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/base_systems/unixcommand/unixcommand.html#HelpAction"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.base_systems.unixcommand.unixcommand.HelpAction" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">argparse.Action</span></code></p>
|
||
<p>Override the -h/–help action in the default parser.</p>
|
||
<p>Using the default -h/–help will call the exit function in different
|
||
ways, preventing the entire help message to be provided. Hence
|
||
this override.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py class">
|
||
<dt id="evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommand">
|
||
<em class="property">class </em><code class="sig-prename descclassname">evennia.contrib.base_systems.unixcommand.unixcommand.</code><code class="sig-name descname">UnixCommand</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/base_systems/unixcommand/unixcommand.html#UnixCommand"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommand" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Bases: <a class="reference internal" href="evennia.commands.command.html#evennia.commands.command.Command" title="evennia.commands.command.Command"><code class="xref py py-class docutils literal notranslate"><span class="pre">evennia.commands.command.Command</span></code></a></p>
|
||
<p>Unix-type commands, supporting short and long options.</p>
|
||
<p>This command syntax uses the Unix-style commands with short options
|
||
(-X) and long options (–something). The <strong>argparse</strong> module is
|
||
used to parse the command.</p>
|
||
<p>In order to use it, you should override two methods:
|
||
- <strong>init_parser</strong>: this method is called when the command is created.</p>
|
||
<blockquote>
|
||
<div><p>It can be used to set options in the parser. <strong>self.parser</strong>
|
||
contains the <strong>argparse.ArgumentParser</strong>, so you can add arguments
|
||
here.</p>
|
||
</div></blockquote>
|
||
<ul class="simple">
|
||
<li><p><strong>func</strong>: this method is called to execute the command, but after
|
||
the parser has checked the arguments given to it are valid.
|
||
You can access the namespace of valid arguments in <strong>self.opts</strong>
|
||
at this point.</p></li>
|
||
</ul>
|
||
<p>The help of UnixCommands is derived from the docstring, in a
|
||
slightly different way than usual: the first line of the docstring
|
||
is used to represent the program description (the very short
|
||
line at the top of the help message). The other lines below are
|
||
used as the program’s “epilog”, displayed below the options. It
|
||
means in your docstring, you don’t have to write the options.
|
||
They will be automatically provided by the parser and displayed
|
||
accordingly. The <strong>argparse</strong> module provides a default ‘-h’ or
|
||
‘–help’ option on the command. Typing <a href="#id1"><span class="problematic" id="id2">|</span></a>whelp commandname|n will
|
||
display the same as <a href="#id3"><span class="problematic" id="id4">|</span></a>wcommandname -h|n, though this behavior can
|
||
be changed.</p>
|
||
<dl class="py method">
|
||
<dt id="evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommand.__init__">
|
||
<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/base_systems/unixcommand/unixcommand.html#UnixCommand.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommand.__init__" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>The lockhandler works the same as for objects.
|
||
optional kwargs will be set as properties on the Command at runtime,
|
||
overloading evential same-named class properties.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommand.init_parser">
|
||
<code class="sig-name descname">init_parser</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/base_systems/unixcommand/unixcommand.html#UnixCommand.init_parser"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommand.init_parser" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Configure the argument parser, adding in options.</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>This method is to be overridden in order to add options
|
||
to the argument parser. Use <strong>self.parser</strong>, which contains
|
||
the <strong>argparse.ArgumentParser</strong>. You can, for instance,
|
||
use its <strong>add_argument</strong> method.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommand.func">
|
||
<code class="sig-name descname">func</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/base_systems/unixcommand/unixcommand.html#UnixCommand.func"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommand.func" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Override to handle the command execution.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommand.get_help">
|
||
<code class="sig-name descname">get_help</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">caller</span></em>, <em class="sig-param"><span class="n">cmdset</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/base_systems/unixcommand/unixcommand.html#UnixCommand.get_help"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommand.get_help" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Return the help message for this command and this caller.</p>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Parameters</dt>
|
||
<dd class="field-odd"><ul class="simple">
|
||
<li><p><strong>caller</strong> (<em>Object</em><em> or </em><em>Player</em>) – the caller asking for help on the command.</p></li>
|
||
<li><p><strong>cmdset</strong> (<a class="reference internal" href="evennia.commands.cmdset.html#evennia.commands.cmdset.CmdSet" title="evennia.commands.cmdset.CmdSet"><em>CmdSet</em></a>) – the command set (if you need additional commands).</p></li>
|
||
</ul>
|
||
</dd>
|
||
<dt class="field-even">Returns</dt>
|
||
<dd class="field-even"><p><em>docstring (str)</em> – the help text to provide the caller for this command.</p>
|
||
</dd>
|
||
</dl>
|
||
</dd></dl>
|
||
|
||
<dl class="py method">
|
||
<dt id="evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommand.parse">
|
||
<code class="sig-name descname">parse</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/base_systems/unixcommand/unixcommand.html#UnixCommand.parse"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommand.parse" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Process arguments provided in <strong>self.args</strong>.</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>You should not override this method. Consider overriding
|
||
<strong>init_parser</strong> instead.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt id="evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommand.aliases">
|
||
<code class="sig-name descname">aliases</code><em class="property"> = []</em><a class="headerlink" href="#evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommand.aliases" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt id="evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommand.help_category">
|
||
<code class="sig-name descname">help_category</code><em class="property"> = 'general'</em><a class="headerlink" href="#evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommand.help_category" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt id="evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommand.key">
|
||
<code class="sig-name descname">key</code><em class="property"> = 'command'</em><a class="headerlink" href="#evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommand.key" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt id="evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommand.lock_storage">
|
||
<code class="sig-name descname">lock_storage</code><em class="property"> = 'cmd:all();'</em><a class="headerlink" href="#evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommand.lock_storage" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
<dl class="py attribute">
|
||
<dt id="evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommand.search_index_entry">
|
||
<code class="sig-name descname">search_index_entry</code><em class="property"> = {'aliases': '', 'category': 'general', 'key': 'command', 'no_prefix': ' ', 'tags': '', 'text': '\n Unix-type commands, supporting short and long options.\n\n This command syntax uses the Unix-style commands with short options\n (-X) and long options (--something). The `argparse` module is\n used to parse the command.\n\n In order to use it, you should override two methods:\n - `init_parser`: this method is called when the command is created.\n It can be used to set options in the parser. `self.parser`\n contains the `argparse.ArgumentParser`, so you can add arguments\n here.\n - `func`: this method is called to execute the command, but after\n the parser has checked the arguments given to it are valid.\n You can access the namespace of valid arguments in `self.opts`\n at this point.\n\n The help of UnixCommands is derived from the docstring, in a\n slightly different way than usual: the first line of the docstring\n is used to represent the program description (the very short\n line at the top of the help message). The other lines below are\n used as the program\'s "epilog", displayed below the options. It\n means in your docstring, you don\'t have to write the options.\n They will be automatically provided by the parser and displayed\n accordingly. The `argparse` module provides a default \'-h\' or\n \'--help\' option on the command. Typing |whelp commandname|n will\n display the same as |wcommandname -h|n, though this behavior can\n be changed.\n\n '}</em><a class="headerlink" href="#evennia.contrib.base_systems.unixcommand.unixcommand.UnixCommand.search_index_entry" title="Permalink to this definition">¶</a></dt>
|
||
<dd></dd></dl>
|
||
|
||
</dd></dl>
|
||
|
||
</section>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
</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="right" >
|
||
<a href="evennia.contrib.full_systems.html" title="evennia.contrib.full_systems"
|
||
>next</a> |</li>
|
||
<li class="right" >
|
||
<a href="evennia.contrib.base_systems.unixcommand.tests.html" title="evennia.contrib.base_systems.unixcommand.tests"
|
||
>previous</a> |</li>
|
||
<li class="nav-item nav-item-0"><a href="../index.html">Evennia 2.x</a> »</li>
|
||
<li class="nav-item nav-item-1"><a href="../Evennia-API.html" >API Summary</a> »</li>
|
||
<li class="nav-item nav-item-2"><a href="evennia-api.html" >evennia</a> »</li>
|
||
<li class="nav-item nav-item-3"><a href="evennia.html" >evennia</a> »</li>
|
||
<li class="nav-item nav-item-4"><a href="evennia.contrib.html" >evennia.contrib</a> »</li>
|
||
<li class="nav-item nav-item-5"><a href="evennia.contrib.base_systems.html" >evennia.contrib.base_systems</a> »</li>
|
||
<li class="nav-item nav-item-6"><a href="evennia.contrib.base_systems.unixcommand.html" >evennia.contrib.base_systems.unixcommand</a> »</li>
|
||
<li class="nav-item nav-item-this"><a href="">evennia.contrib.base_systems.unixcommand.unixcommand</a></li>
|
||
</ul>
|
||
</div>
|
||
|
||
|
||
|
||
<div class="footer" role="contentinfo">
|
||
© Copyright 2023, The Evennia developer community.
|
||
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.
|
||
</div>
|
||
</body>
|
||
</html> |