mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 11:02:20 +00:00
Added docs, updated README
This commit is contained in:
103
README.md
103
README.md
@@ -4,34 +4,95 @@
|
|||||||
|
|
||||||
argparse is a feature-rich command line parser for Lua inspired by argparse for Python.
|
argparse is a feature-rich command line parser for Lua inspired by argparse for Python.
|
||||||
|
|
||||||
|
argparse supports positional arguments, options, flags, optional arguments, subcommands and more. argparse automatically generates usage, help and error messages.
|
||||||
|
|
||||||
|
Quick glance:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
-- script.lua
|
||||||
|
local argparse = require "argparse"
|
||||||
|
local parser = argparse()
|
||||||
|
:description "An example."
|
||||||
|
parser:argument "input"
|
||||||
|
:description "Input file."
|
||||||
|
parser:option "-o" "--output"
|
||||||
|
:default "a.out"
|
||||||
|
:description "Output file."
|
||||||
|
parser:option "-I" "--include"
|
||||||
|
:count "*"
|
||||||
|
:description "Include locations."
|
||||||
|
local args = parser:parse()
|
||||||
|
prettyprint(args)
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ lua script.lua foo
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
input: foo
|
||||||
|
output: a.out
|
||||||
|
include: {}
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ lua script.lua foo -I/usr/local/include -I/src -o bar
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
input: foo
|
||||||
|
output: bar
|
||||||
|
include: {/usr/local/include, /src}
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ lua script.lua foo bar
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: script.lua [-o <output>] [-I <include>] [-h] <input>
|
||||||
|
|
||||||
|
Error: too many arguments
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ lua script.lua --help
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: script.lua [-o <output>] [-I <include>] [-h] <input>
|
||||||
|
|
||||||
|
An example.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
input Input file.
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-o <output>, --output <output>
|
||||||
|
Output file. (default: a.out)
|
||||||
|
-I <include>, --include <include>
|
||||||
|
Include locations.
|
||||||
|
-h, --help Show this help message and exit.
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ lua script.lua foo --outptu=bar
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: script.lua [-o <output>] [-I <include>] [-h] <input>
|
||||||
|
|
||||||
|
Error: unknown option '--outptu'
|
||||||
|
Did you mean '--output'?
|
||||||
|
```
|
||||||
|
|
||||||
## Contents
|
## Contents
|
||||||
|
|
||||||
* [Status](#status)
|
|
||||||
* [Installation](#installation)
|
* [Installation](#installation)
|
||||||
* [Tutorial](#tutorial)
|
* [Tutorial](#tutorial)
|
||||||
* [Testing](#testing)
|
* [Testing](#testing)
|
||||||
* [License](#license)
|
* [License](#license)
|
||||||
|
|
||||||
## Status
|
|
||||||
|
|
||||||
Almost everything is implemented, and a WIP version will be available soon.
|
|
||||||
|
|
||||||
TODO till first release:
|
|
||||||
|
|
||||||
* Add `Content` section to this README.
|
|
||||||
* Add a small example to the beginning of this README.
|
|
||||||
* Check the grammar in this README.
|
|
||||||
* Generate .html file from the tutorial part of this README and put it into `doc` directory.
|
|
||||||
* Write a rockspec for `v0.1` and push it to moonrocks.
|
|
||||||
|
|
||||||
TODO till first 'stable' release:
|
|
||||||
|
|
||||||
* Write a formal reference.
|
|
||||||
* Write more tests. Some cases are still poorly covered.
|
|
||||||
* Add mutually exclusive groups(`:mutex{option1, option2, ...}`).
|
|
||||||
* Optionally(?): Add comments to the source.
|
|
||||||
* Optionally: get rid of `30log` dependency. It's great but can cause problems with old luarocks versions.
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
### Using luarocks
|
### Using luarocks
|
||||||
|
BIN
doc/images/bg_hr.png
Normal file
BIN
doc/images/bg_hr.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 943 B |
BIN
doc/images/blacktocat.png
Normal file
BIN
doc/images/blacktocat.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
832
doc/index.html
Normal file
832
doc/index.html
Normal file
@@ -0,0 +1,832 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset='utf-8' />
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="chrome=1" />
|
||||||
|
<meta name="description" content="Argparse tutorial : " />
|
||||||
|
|
||||||
|
<link rel="stylesheet" type="text/css" media="screen" href="stylesheets/stylesheet.css">
|
||||||
|
|
||||||
|
<title>Argparse tutorial</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<!-- HEADER -->
|
||||||
|
<div id="header_wrap" class="outer">
|
||||||
|
<header class="inner">
|
||||||
|
<a id="forkme_banner" href="https://github.com/mpeterv/argparse">View on GitHub</a>
|
||||||
|
|
||||||
|
<h1 id="project_title">Argparse tutorial</h1>
|
||||||
|
<h2 id="project_tagline"></h2>
|
||||||
|
</header>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- MAIN CONTENT -->
|
||||||
|
<div id="main_content_wrap" class="outer">
|
||||||
|
<section id="main_content" class="inner">
|
||||||
|
<ul>
|
||||||
|
<li><a href="#creating-a-parser">Creating a parser</a></li>
|
||||||
|
<li>
|
||||||
|
<a href="#parsing-command-line-arguments">Parsing command line arguments</a>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><a href="#error-handling">Error handling</a></li>
|
||||||
|
<li><a href="#help-option">Help option</a></li>
|
||||||
|
<li><a href="#typo-autocorrection">Typo autocorrection</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li><a href="#configuring-parser">Configuring parser</a></li>
|
||||||
|
<li>
|
||||||
|
<a href="#adding-arguments">Adding arguments</a>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><a href="#setting-number-of-arguments">Setting number of arguments</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="#adding-options">Adding options</a>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><a href="#flags">Flags</a></li>
|
||||||
|
<li><a href="#control-characters">Control characters</a></li>
|
||||||
|
<li><a href="#setting-number-of-arguments-1">Setting number of arguments</a></li>
|
||||||
|
<li><a href="#setting-number-of-invocations">Setting number of invocations</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="#commands">Commands</a>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><a href="#adding-elements-to-commands">Adding elements to commands</a></li>
|
||||||
|
<li><a href="#making-a-command-optional">Making a command optional</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="#default-values">Default values</a>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><a href="#default-mode">Default mode</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="#converters">Converters</a>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><a href="#table-converters">Table converters</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li><a href="#actions">Actions</a></li>
|
||||||
|
<li>
|
||||||
|
<a href="#miscellaneous">Miscellaneous</a>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><a href="#overwriting-default-help-option">Overwriting default help option</a></li>
|
||||||
|
<li>
|
||||||
|
<a href="#configuring-usage-and-help-messages">Configuring usage and help messages</a>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><a href="#description-and-epilog">Description and epilog</a></li>
|
||||||
|
<li><a href="#argument-placeholder">Argument placeholder</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li><a href="#prohibiting-overuse-of-options">Prohibiting overuse of options</a></li>
|
||||||
|
<li><a href="#generating-usage-and-help-messages">Generating usage and help messages</a></li>
|
||||||
|
<li><a href="#parsing-algorithm">Parsing algorithm</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
</ul><h2>
|
||||||
|
<a name="creating-a-parser" class="anchor" href="#creating-a-parser"><span class="octicon octicon-link"></span></a>Creating a parser</h2>
|
||||||
|
|
||||||
|
<p>The module is a function which, when called, creates an instance of the Parser class. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="c1">-- script.lua</span>
|
||||||
|
<span class="kd">local</span> <span class="n">argparse</span> <span class="o">=</span> <span class="nb">require</span> <span class="s2">"</span><span class="s">argparse"</span>
|
||||||
|
<span class="kd">local</span> <span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="p">()</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<p><code>parser</code> is now an empty parser which does not recognize any command line arguments or options. </p>
|
||||||
|
|
||||||
|
<h2>
|
||||||
|
<a name="parsing-command-line-arguments" class="anchor" href="#parsing-command-line-arguments"><span class="octicon octicon-link"></span></a>Parsing command line arguments</h2>
|
||||||
|
|
||||||
|
<p><code>:parse([cmdline])</code> method of the Parser class returns a table with processed data from the command line or <code>cmdline</code> array. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="kd">local</span> <span class="n">args</span> <span class="o">=</span> <span class="n">parser</span><span class="p">:</span><span class="n">parse</span><span class="p">()</span>
|
||||||
|
<span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="k">in</span> <span class="nb">pairs</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="k">do</span> <span class="nb">print</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span> <span class="k">end</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<p>When executed, this script prints nothing because the parser is empty and no command line arguments were supplied. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<h3>
|
||||||
|
<a name="error-handling" class="anchor" href="#error-handling"><span class="octicon octicon-link"></span></a>Error handling</h3>
|
||||||
|
|
||||||
|
<p>If the provided command line arguments are not recognized by the parser, it will print an error message and call <code>os.exit(1)</code>. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua foo
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>Usage: script.lua [-h]
|
||||||
|
|
||||||
|
Error: too many arguments
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<p>If halting the program is undesirable, <code>:pparse([cmdline])</code> method should be used. It returns boolean flag indicating success of parsing and result or error message. </p>
|
||||||
|
|
||||||
|
<p>An error can raised manually using <code>:error()</code> method. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="n">parser</span><span class="p">:</span><span class="nb">error</span><span class="p">(</span><span class="s2">"</span><span class="s">manual argument validation failed"</span><span class="p">)</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>Usage: script.lua [-h]
|
||||||
|
|
||||||
|
Error: manual argument validation failed
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<h3>
|
||||||
|
<a name="help-option" class="anchor" href="#help-option"><span class="octicon octicon-link"></span></a>Help option</h3>
|
||||||
|
|
||||||
|
<p>As the automatically generated usage message states, there is a help option <code>-h</code> added to any parser by default. </p>
|
||||||
|
|
||||||
|
<p>When a help option is used, parser will print a help message and call <code>os.exit(0)</code>. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua -h
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>Usage: script.lua [-h]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h, --help Show this help message and exit.
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<h3>
|
||||||
|
<a name="typo-autocorrection" class="anchor" href="#typo-autocorrection"><span class="octicon octicon-link"></span></a>Typo autocorrection</h3>
|
||||||
|
|
||||||
|
<p>When an option is not recognized by the parser, but there is an option with a similar name, a suggestion is automatically added to the error message. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua --hepl
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>Usage: script.lua [-h]
|
||||||
|
|
||||||
|
Error: unknown option '--hepl'
|
||||||
|
Did you mean '--help'?
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<h2>
|
||||||
|
<a name="configuring-parser" class="anchor" href="#configuring-parser"><span class="octicon octicon-link"></span></a>Configuring parser</h2>
|
||||||
|
|
||||||
|
<p>Parsers have several fields affecting their behavior. For example, <code>description</code> field sets the text to be displayed in the help message between the usage message and the listings of options and arguments. Another is <code>name</code>, which overwrites the name of the program which is used in the usage message(default value is inferred from command line arguments). </p>
|
||||||
|
|
||||||
|
<p>There are several ways to set fields. The first is to call a parser with a table containing some fields. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="kd">local</span> <span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="p">()</span> <span class="p">{</span>
|
||||||
|
<span class="n">name</span> <span class="o">=</span> <span class="s2">"</span><span class="s">script"</span><span class="p">,</span>
|
||||||
|
<span class="n">description</span> <span class="o">=</span> <span class="s2">"</span><span class="s">A testing script. "</span>
|
||||||
|
<span class="p">}</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<p>The second is to chain setter methods of Parser object. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="kd">local</span> <span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="p">()</span>
|
||||||
|
<span class="p">:</span><span class="n">name</span> <span class="s2">"</span><span class="s">script"</span>
|
||||||
|
<span class="p">:</span><span class="n">description</span> <span class="s2">"</span><span class="s">A testing script. "</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<p>As a special case, <code>name</code> field can be set by calling a parser with a string. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="kd">local</span> <span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span> <span class="s2">"</span><span class="s">script"</span>
|
||||||
|
<span class="p">:</span><span class="n">description</span> <span class="s2">"</span><span class="s">A testing script. "</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<h2>
|
||||||
|
<a name="adding-arguments" class="anchor" href="#adding-arguments"><span class="octicon octicon-link"></span></a>Adding arguments</h2>
|
||||||
|
|
||||||
|
<p>Positional arguments can be added using <code>:argument()</code> method. It returns an Argument instance, which can be configured in the same way as Parsers. The <code>name</code> field is required. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="n">parser</span><span class="p">:</span><span class="n">argument</span> <span class="s2">"</span><span class="s">input"</span> <span class="c1">-- sugar for :argument():name "input"</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua foo
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>input foo
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<p>The data passed to the argument is stored in the result table at index <code>input</code> because it is the argument's name. The index can be changed using <code>target</code> field. </p>
|
||||||
|
|
||||||
|
<h3>
|
||||||
|
<a name="setting-number-of-arguments" class="anchor" href="#setting-number-of-arguments"><span class="octicon octicon-link"></span></a>Setting number of arguments</h3>
|
||||||
|
|
||||||
|
<p><code>args</code> field sets how many command line arguments the argument consumes. Its value is interpreted as follows: </p>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead><tr>
|
||||||
|
<th>Value</th>
|
||||||
|
<th>Interpretation</th>
|
||||||
|
</tr></thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>Number <code>N</code>
|
||||||
|
</td>
|
||||||
|
<td>Exactly <code>N</code> arguments</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>String <code>"A-B"</code>, where <code>A</code> and <code>B</code> are numbers</td>
|
||||||
|
<td>From <code>A</code> to <code>B</code> arguments</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>String <code>"N+"</code>, where <code>N</code> is a number</td>
|
||||||
|
<td>
|
||||||
|
<code>N</code> or more arguments</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>String <code>"?"</code>
|
||||||
|
</td>
|
||||||
|
<td>An optional argument</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>String <code>"*"</code>
|
||||||
|
</td>
|
||||||
|
<td>Any number of arguments</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>String <code>"+"</code>
|
||||||
|
</td>
|
||||||
|
<td>At least one argument</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table><p>If more than one argument can be passed, a table is used to store the data. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="n">parser</span><span class="p">:</span><span class="n">argument</span> <span class="s2">"</span><span class="s">pair"</span>
|
||||||
|
<span class="p">:</span><span class="n">args</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
|
||||||
|
<span class="p">:</span><span class="n">description</span> <span class="s2">"</span><span class="s">A pair of arguments. "</span>
|
||||||
|
<span class="n">parser</span><span class="p">:</span><span class="n">argument</span> <span class="s2">"</span><span class="s">optional"</span>
|
||||||
|
<span class="p">:</span><span class="n">args</span> <span class="s2">"</span><span class="s">?"</span>
|
||||||
|
<span class="p">:</span><span class="n">description</span> <span class="s2">"</span><span class="s">An optional argument. "</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua foo bar
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>pair {foo, bar}
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua foo bar baz
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>pair {foo, bar}
|
||||||
|
optional baz
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<h2>
|
||||||
|
<a name="adding-options" class="anchor" href="#adding-options"><span class="octicon octicon-link"></span></a>Adding options</h2>
|
||||||
|
|
||||||
|
<p>Options can be added using <code>:option()</code> method. It returns an Option instance, which can be configured in the same way as Parsers. The <code>name</code> field is required. An option can have several aliases, which can be set using <code>aliases</code> field or by continuously calling the Option instance. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="n">parser</span><span class="p">:</span><span class="n">option</span> <span class="s2">"</span><span class="s">-f"</span> <span class="s2">"</span><span class="s">--from"</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua --from there
|
||||||
|
<span class="nv">$ </span>lua script.lua --from<span class="o">=</span>there
|
||||||
|
<span class="nv">$ </span>lua script.lua -f there
|
||||||
|
<span class="nv">$ </span>lua script.lua -fthere
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>from there
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<p>For an option, default index used to store data is the first 'long' alias (an alias starting with two control characters) or just the first alias, without control characters. </p>
|
||||||
|
|
||||||
|
<p>Sometimes it is useful to explicitly set the index using <code>target</code> field to improve readability of help messages. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="n">parser</span><span class="p">:</span><span class="n">option</span> <span class="s2">"</span><span class="s">-f"</span> <span class="s2">"</span><span class="s">--from"</span>
|
||||||
|
<span class="p">:</span><span class="n">target</span> <span class="s2">"</span><span class="s">server"</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua --help
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>Usage: script.lua [-f <server>] [-h]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-f <server>, --from <server>
|
||||||
|
-h, --help Show this help message and exit.
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua --from there
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>server there
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<h3>
|
||||||
|
<a name="flags" class="anchor" href="#flags"><span class="octicon octicon-link"></span></a>Flags</h3>
|
||||||
|
|
||||||
|
<p>Flags are almost identical to options, except that they don't take an argument by default. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="n">parser</span><span class="p">:</span><span class="n">flag</span> <span class="s2">"</span><span class="s">-q"</span> <span class="s2">"</span><span class="s">--quiet"</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua -q
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>quiet true
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<h3>
|
||||||
|
<a name="control-characters" class="anchor" href="#control-characters"><span class="octicon octicon-link"></span></a>Control characters</h3>
|
||||||
|
|
||||||
|
<p>The first characters of all aliases of all options of a parser form the set of control characters, used to distinguish options from arguments. Typically the set only consists of a hyphen. </p>
|
||||||
|
|
||||||
|
<h3>
|
||||||
|
<a name="setting-number-of-arguments-1" class="anchor" href="#setting-number-of-arguments-1"><span class="octicon octicon-link"></span></a>Setting number of arguments</h3>
|
||||||
|
|
||||||
|
<p>Just as arguments, options can be configured to take several command line arguments. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="n">parser</span><span class="p">:</span><span class="n">option</span> <span class="s2">"</span><span class="s">--pair"</span>
|
||||||
|
<span class="p">:</span><span class="n">args</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
|
||||||
|
<span class="n">parser</span><span class="p">:</span><span class="n">option</span> <span class="s2">"</span><span class="s">--optional"</span>
|
||||||
|
<span class="p">:</span><span class="n">args</span> <span class="s2">"</span><span class="s">?"</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua --pair foo bar
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>pair {foo, bar}
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua --pair foo bar --optional
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>pair {foo, bar}
|
||||||
|
optional {}
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua --optional<span class="o">=</span>baz
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>optional {baz}
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<p>Note that the data passed to <code>optional</code> option is stored in an array. That is necessary to distinguish whether the option was invoked without an argument or it was not invoked at all. </p>
|
||||||
|
|
||||||
|
<h3>
|
||||||
|
<a name="setting-number-of-invocations" class="anchor" href="#setting-number-of-invocations"><span class="octicon octicon-link"></span></a>Setting number of invocations</h3>
|
||||||
|
|
||||||
|
<p>For options, it is possible to control how many times they can be used. argparse uses <code>count</code> field to set how many times an option can be invoked. The value of the field is interpreted in the same way <code>args</code> is. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="n">parser</span><span class="p">:</span><span class="n">option</span> <span class="s2">"</span><span class="s">-e"</span> <span class="s2">"</span><span class="s">--exclude"</span>
|
||||||
|
<span class="p">:</span><span class="n">count</span> <span class="s2">"</span><span class="s">*"</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua -eFOO -eBAR
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>exclude {FOO, BAR}
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<p>If an option can be used more than once and it can consume more than one argument, the data is stored as an array of invocations, each being an array of arguments. </p>
|
||||||
|
|
||||||
|
<p>As a special case, if an option can be used more than once and it consumes no arguments(e.g. it's a flag), than the number of invocations is stored in associated field of the result table. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="n">parser</span><span class="p">:</span><span class="n">flag</span> <span class="s2">"</span><span class="s">-v"</span> <span class="s2">"</span><span class="s">--verbose"</span>
|
||||||
|
<span class="p">:</span><span class="n">count</span> <span class="s2">"</span><span class="s">0-2"</span>
|
||||||
|
<span class="p">:</span><span class="n">target</span> <span class="s2">"</span><span class="s">verbosity"</span>
|
||||||
|
<span class="p">:</span><span class="n">description</span> <span class="s">[[Sets verbosity level. </span>
|
||||||
|
<span class="s">-v: Report all warning. </span>
|
||||||
|
<span class="s">-vv: Report all debugging information. ]]</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua -vv
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>verbosity 2
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<h2>
|
||||||
|
<a name="commands" class="anchor" href="#commands"><span class="octicon octicon-link"></span></a>Commands</h2>
|
||||||
|
|
||||||
|
<p>A command is a subparser invoked when its name is passed as an argument. For example, in luarocks CLI <code>install</code>, <code>make</code>, <code>build</code>, etc. are commands. Each command has its own set of arguments and options. </p>
|
||||||
|
|
||||||
|
<p>Commands can be added using <code>:command()</code> method. Just as options, commands can have several aliases. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="n">parser</span><span class="p">:</span><span class="n">command</span> <span class="s2">"</span><span class="s">install"</span> <span class="s2">"</span><span class="s">i"</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<p>If a command it used, <code>true</code> is stored in the corresponding field of the result table. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua install
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>install true
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<p>A typo will result in an appropriate error message: </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua instal
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>Usage: script.lua [-h] <command> ...
|
||||||
|
|
||||||
|
Error: unknown command 'instal'
|
||||||
|
Did you mean 'install'?
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<h3>
|
||||||
|
<a name="adding-elements-to-commands" class="anchor" href="#adding-elements-to-commands"><span class="octicon octicon-link"></span></a>Adding elements to commands</h3>
|
||||||
|
|
||||||
|
<p>The Command class is a subclass of the Parser class, so all the Parser's methods for adding elements work on commands, too. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="kd">local</span> <span class="n">install</span> <span class="o">=</span> <span class="n">parser</span><span class="p">:</span><span class="n">command</span> <span class="s2">"</span><span class="s">install"</span>
|
||||||
|
<span class="n">install</span><span class="p">:</span><span class="n">argument</span> <span class="s2">"</span><span class="s">rock"</span>
|
||||||
|
<span class="n">install</span><span class="p">:</span><span class="n">option</span> <span class="s2">"</span><span class="s">-f"</span> <span class="s2">"</span><span class="s">--from"</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua install foo --from<span class="o">=</span>bar
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>install true
|
||||||
|
rock foo
|
||||||
|
from bar
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<p>Commands have their own usage and help messages. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua install
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>Usage: script.lua install [-f <from>] [-h] <rock>
|
||||||
|
|
||||||
|
Error: too few arguments
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua install --help
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>Usage: script.lua install [-f <from>] [-h] <rock>
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
rock
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-f <from>, --from <from>
|
||||||
|
-h, --help Show this help message and exit.
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<h3>
|
||||||
|
<a name="making-a-command-optional" class="anchor" href="#making-a-command-optional"><span class="octicon octicon-link"></span></a>Making a command optional</h3>
|
||||||
|
|
||||||
|
<p>By default, if a parser has commands, using one of them is obligatory. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="kd">local</span> <span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="p">()</span>
|
||||||
|
<span class="n">parser</span><span class="p">:</span><span class="n">command</span> <span class="s2">"</span><span class="s">install"</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>Usage: script.lua [-h] <command> ...
|
||||||
|
|
||||||
|
Error: a command is required
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<p>This can be changed using the <code>require_command</code> field. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="kd">local</span> <span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="p">()</span>
|
||||||
|
<span class="p">:</span><span class="n">require_command</span><span class="p">(</span><span class="kc">false</span><span class="p">)</span>
|
||||||
|
<span class="n">parser</span><span class="p">:</span><span class="n">command</span> <span class="s2">"</span><span class="s">install"</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<p>Now not using a command is not an error:</p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<p>produces nothing. </p>
|
||||||
|
|
||||||
|
<h2>
|
||||||
|
<a name="default-values" class="anchor" href="#default-values"><span class="octicon octicon-link"></span></a>Default values</h2>
|
||||||
|
|
||||||
|
<p>For elements such as arguments and options, if <code>default</code> field is set, its value is stored in case the element was not used. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="n">parser</span><span class="p">:</span><span class="n">option</span> <span class="s2">"</span><span class="s">-o"</span> <span class="s2">"</span><span class="s">--output"</span>
|
||||||
|
<span class="p">:</span><span class="n">default</span> <span class="s2">"</span><span class="s">a.out"</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>output a.out
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<p>The existence of a default value is reflected in help message. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua --help
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>Usage: script [-o <output>] [-h]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-o <output>, --output <output>
|
||||||
|
default: a.out
|
||||||
|
-h, --help Show this help message and exit.
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<p>Note that invocation without required arguments is still an error. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua -o
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>Usage: script [-o <output>] [-h]
|
||||||
|
|
||||||
|
Error: too few arguments
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<h3>
|
||||||
|
<a name="default-mode" class="anchor" href="#default-mode"><span class="octicon octicon-link"></span></a>Default mode</h3>
|
||||||
|
|
||||||
|
<p>The <code>defmode</code> field regulates how argparse should use the default value of an element. </p>
|
||||||
|
|
||||||
|
<p>If <code>defmode</code> contains <code>"u"</code>(for <code>unused</code>), the default value will be automatically passed to the element if it was not invoked at all. This is the default behavior. </p>
|
||||||
|
|
||||||
|
<p>If <code>defmode</code> contains <code>"a"</code>(for <code>argument</code>), the default value will be automatically passed to the element if not enough arguments were passed, or not enough invocations were made. </p>
|
||||||
|
|
||||||
|
<p>Consider the difference: </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="n">parser</span><span class="p">:</span><span class="n">option</span> <span class="s2">"</span><span class="s">-o"</span>
|
||||||
|
<span class="p">:</span><span class="n">default</span> <span class="s2">"</span><span class="s">a.out"</span>
|
||||||
|
<span class="n">parser</span><span class="p">:</span><span class="n">option</span> <span class="s2">"</span><span class="s">-p"</span>
|
||||||
|
<span class="p">:</span><span class="n">default</span> <span class="s2">"</span><span class="s">password"</span>
|
||||||
|
<span class="p">:</span><span class="n">defmode</span> <span class="s2">"</span><span class="s">arg"</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua -h
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>Usage: script [-o <o>] [-p [<p>]] [-h]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-o <o> default: a.out
|
||||||
|
-p [<p>] default: password
|
||||||
|
-h, --help Show this help message and exit.
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>o a.out
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua -p
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>o a.out
|
||||||
|
p password
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua -o
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>Usage: script [-o <o>] [-p [<p>]] [-h]
|
||||||
|
|
||||||
|
Error: too few arguments
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<h2>
|
||||||
|
<a name="converters" class="anchor" href="#converters"><span class="octicon octicon-link"></span></a>Converters</h2>
|
||||||
|
|
||||||
|
<p>argparse can perform automatic validation and conversion on arguments. If <code>convert</code> field of an element is a function, it will be applied to all the arguments passed to it. The function should return <code>nil</code> and, optionally, an error message if conversion failed. Standard <code>tonumber</code> and <code>io.open</code> functions work exactly like that. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="n">parser</span><span class="p">:</span><span class="n">argument</span> <span class="s2">"</span><span class="s">input"</span>
|
||||||
|
<span class="p">:</span><span class="n">convert</span><span class="p">(</span><span class="nb">io.open</span><span class="p">)</span>
|
||||||
|
<span class="n">parser</span><span class="p">:</span><span class="n">option</span> <span class="s2">"</span><span class="s">-t"</span> <span class="s2">"</span><span class="s">--times"</span>
|
||||||
|
<span class="p">:</span><span class="n">convert</span><span class="p">(</span><span class="nb">tonumber</span><span class="p">)</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua foo.txt -t5
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>input file (0xaddress)
|
||||||
|
times 5 (number)
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua nonexistent.txt
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>Usage: script.lua [-t <times>] [-h] <input>
|
||||||
|
|
||||||
|
Error: nonexistent.txt: No such file or directory
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua foo.txt --times<span class="o">=</span>many
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>Usage: script.lua [-t <times>] [-h] <input>
|
||||||
|
|
||||||
|
Error: malformed argument 'many'
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<h3>
|
||||||
|
<a name="table-converters" class="anchor" href="#table-converters"><span class="octicon octicon-link"></span></a>Table converters</h3>
|
||||||
|
|
||||||
|
<p>If <code>convert</code> field of an element contains a table, arguments passed to it will be used as keys. If a key is missing, an error is raised. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="n">parser</span><span class="p">:</span><span class="n">argument</span> <span class="s2">"</span><span class="s">choice"</span>
|
||||||
|
<span class="p">:</span><span class="n">convert</span> <span class="p">{</span>
|
||||||
|
<span class="n">foo</span> <span class="o">=</span> <span class="s2">"</span><span class="s">Something foo-related"</span><span class="p">,</span>
|
||||||
|
<span class="n">bar</span> <span class="o">=</span> <span class="s2">"</span><span class="s">Something bar-related"</span>
|
||||||
|
<span class="p">}</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua bar
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>choice Something bar-related
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua baz
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>Usage: script.lua [-h] <choice>
|
||||||
|
|
||||||
|
Error: malformed argument 'baz'
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<h2>
|
||||||
|
<a name="actions" class="anchor" href="#actions"><span class="octicon octicon-link"></span></a>Actions</h2>
|
||||||
|
|
||||||
|
<p>argparse can trigger a callback when an option or a command is encountered. The callback can be set using <code>action</code> field. Actions are called regardless of whether the rest of command line arguments are correct. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="n">parser</span><span class="p">:</span><span class="n">flag</span> <span class="s2">"</span><span class="s">-v"</span> <span class="s2">"</span><span class="s">--version"</span>
|
||||||
|
<span class="p">:</span><span class="n">description</span> <span class="s2">"</span><span class="s">Show version info and exit. "</span>
|
||||||
|
<span class="p">:</span><span class="n">action</span><span class="p">(</span><span class="k">function</span><span class="p">()</span>
|
||||||
|
<span class="nb">print</span><span class="p">(</span><span class="s2">"</span><span class="s">script.lua v1.0.0"</span><span class="p">)</span>
|
||||||
|
<span class="nb">os.exit</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
|
||||||
|
<span class="k">end</span><span class="p">)</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua -v
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>script.lua v1.0.0
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<p>This example would work even if the script had mandatory arguments. </p>
|
||||||
|
|
||||||
|
<h2>
|
||||||
|
<a name="miscellaneous" class="anchor" href="#miscellaneous"><span class="octicon octicon-link"></span></a>Miscellaneous</h2>
|
||||||
|
|
||||||
|
<h3>
|
||||||
|
<a name="overwriting-default-help-option" class="anchor" href="#overwriting-default-help-option"><span class="octicon octicon-link"></span></a>Overwriting default help option</h3>
|
||||||
|
|
||||||
|
<p>If the field <code>add_help</code> of a parser is set to false, no help option will be added to it. Otherwise, the value of the field will be used to configure it. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="kd">local</span> <span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="p">()</span>
|
||||||
|
<span class="p">:</span><span class="n">add_help</span> <span class="p">{</span><span class="n">name</span> <span class="o">=</span> <span class="s2">"</span><span class="s">/?"</span><span class="p">}</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua /?
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>Usage: script.lua [/?]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
/? Show this help message and exit.
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<h3>
|
||||||
|
<a name="configuring-usage-and-help-messages" class="anchor" href="#configuring-usage-and-help-messages"><span class="octicon octicon-link"></span></a>Configuring usage and help messages</h3>
|
||||||
|
|
||||||
|
<h4>
|
||||||
|
<a name="description-and-epilog" class="anchor" href="#description-and-epilog"><span class="octicon octicon-link"></span></a>Description and epilog</h4>
|
||||||
|
|
||||||
|
<p>The value of <code>description</code> field of a parser is placed between the usage message and the argument list in the help message. </p>
|
||||||
|
|
||||||
|
<p>The value of <code>epilog</code> field is appended to the help message. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="kd">local</span> <span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span> <span class="s2">"</span><span class="s">script"</span>
|
||||||
|
<span class="p">:</span><span class="n">description</span> <span class="s2">"</span><span class="s">A description. "</span>
|
||||||
|
<span class="p">:</span><span class="n">epilog</span> <span class="s2">"</span><span class="s">An epilog. "</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua --help
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>Usage: script [-h]
|
||||||
|
|
||||||
|
A description.
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h, --help Show this help message and exit.
|
||||||
|
|
||||||
|
An epilog.
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<h4>
|
||||||
|
<a name="argument-placeholder" class="anchor" href="#argument-placeholder"><span class="octicon octicon-link"></span></a>Argument placeholder</h4>
|
||||||
|
|
||||||
|
<p>For options and arguments, <code>argname</code> field controls the placeholder for the argument in the usage message. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="n">parser</span><span class="p">:</span><span class="n">option</span> <span class="s2">"</span><span class="s">-f"</span> <span class="s2">"</span><span class="s">--from"</span>
|
||||||
|
<span class="p">:</span><span class="n">argname</span> <span class="s2">"</span><span class="s"><server>"</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua --help
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>Usage: script.lua [-f <server>] [-h]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-f <server>, --from <server>
|
||||||
|
-h, --help Show this help message and exit.
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<h3>
|
||||||
|
<a name="prohibiting-overuse-of-options" class="anchor" href="#prohibiting-overuse-of-options"><span class="octicon octicon-link"></span></a>Prohibiting overuse of options</h3>
|
||||||
|
|
||||||
|
<p>By default, if an option is invoked too many times, latest invocations overwrite the data passed earlier. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="n">parser</span><span class="p">:</span><span class="n">option</span> <span class="s2">"</span><span class="s">-o"</span> <span class="s2">"</span><span class="s">--output"</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua -oFOO -oBAR
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>output BAR
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<p>Set the <code>overwrite</code> field to false to prohibit this behavior. </p>
|
||||||
|
|
||||||
|
<div class="highlight highlight-lua"><pre><span class="n">parser</span><span class="p">:</span><span class="n">option</span> <span class="s2">"</span><span class="s">-o"</span> <span class="s2">"</span><span class="s">--output"</span>
|
||||||
|
<span class="p">:</span><span class="n">overwrite</span><span class="p">(</span><span class="kc">false</span><span class="p">)</span>
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>lua script.lua -oFOO -oBAR
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<pre><code>Usage: script.lua [-o <output>] [-h]
|
||||||
|
|
||||||
|
Error: option '-o' must be used at most 1 time
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<h3>
|
||||||
|
<a name="generating-usage-and-help-messages" class="anchor" href="#generating-usage-and-help-messages"><span class="octicon octicon-link"></span></a>Generating usage and help messages</h3>
|
||||||
|
|
||||||
|
<p><code>:get_help()</code> and <code>get_usage:()</code> methods of Parser and Command classes can be used to generate their help and usage messages. </p>
|
||||||
|
|
||||||
|
<h3>
|
||||||
|
<a name="parsing-algorithm" class="anchor" href="#parsing-algorithm"><span class="octicon octicon-link"></span></a>Parsing algorithm</h3>
|
||||||
|
|
||||||
|
<p>argparse interprets command line arguments in the following way: </p>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead><tr>
|
||||||
|
<th>Argument</th>
|
||||||
|
<th>Interpretation</th>
|
||||||
|
</tr></thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td><code>foo</code></td>
|
||||||
|
<td>An argument of an option or a positional argument.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><code>--foo</code></td>
|
||||||
|
<td>An option.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><code>--foo=bar</code></td>
|
||||||
|
<td>An option and its argument. The option must be able to take arguments.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><code>-f</code></td>
|
||||||
|
<td>An option.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><code>-abcdef</code></td>
|
||||||
|
<td>Letters are interpreted as options. If one of them can take an argument, the rest of the string is passed to it.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><code>--</code></td>
|
||||||
|
<td>The rest of the command line arguments will be interpreted as positional arguments.</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- FOOTER -->
|
||||||
|
<div id="footer_wrap" class="outer">
|
||||||
|
<footer class="inner">
|
||||||
|
<p class="copyright">Argparse is maintained by <a href="https://github.com/mpeterv">mpeterv</a></p>
|
||||||
|
</footer>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
70
doc/stylesheets/pygment_trac.css
Normal file
70
doc/stylesheets/pygment_trac.css
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
.highlight .hll { background-color: #ffffcc }
|
||||||
|
.highlight { background: #f0f3f3; }
|
||||||
|
.highlight .c { color: #0099FF; font-style: italic } /* Comment */
|
||||||
|
.highlight .err { color: #AA0000; background-color: #FFAAAA } /* Error */
|
||||||
|
.highlight .k { color: #006699; font-weight: bold } /* Keyword */
|
||||||
|
.highlight .o { color: #555555 } /* Operator */
|
||||||
|
.highlight .cm { color: #0099FF; font-style: italic } /* Comment.Multiline */
|
||||||
|
.highlight .cp { color: #009999 } /* Comment.Preproc */
|
||||||
|
.highlight .c1 { color: #0099FF; font-style: italic } /* Comment.Single */
|
||||||
|
.highlight .cs { color: #0099FF; font-weight: bold; font-style: italic } /* Comment.Special */
|
||||||
|
.highlight .gd { background-color: #FFCCCC; border: 1px solid #CC0000 } /* Generic.Deleted */
|
||||||
|
.highlight .ge { font-style: italic } /* Generic.Emph */
|
||||||
|
.highlight .gr { color: #FF0000 } /* Generic.Error */
|
||||||
|
.highlight .gh { color: #003300; font-weight: bold } /* Generic.Heading */
|
||||||
|
.highlight .gi { background-color: #CCFFCC; border: 1px solid #00CC00 } /* Generic.Inserted */
|
||||||
|
.highlight .go { color: #AAAAAA } /* Generic.Output */
|
||||||
|
.highlight .gp { color: #000099; font-weight: bold } /* Generic.Prompt */
|
||||||
|
.highlight .gs { font-weight: bold } /* Generic.Strong */
|
||||||
|
.highlight .gu { color: #003300; font-weight: bold } /* Generic.Subheading */
|
||||||
|
.highlight .gt { color: #99CC66 } /* Generic.Traceback */
|
||||||
|
.highlight .kc { color: #006699; font-weight: bold } /* Keyword.Constant */
|
||||||
|
.highlight .kd { color: #006699; font-weight: bold } /* Keyword.Declaration */
|
||||||
|
.highlight .kn { color: #006699; font-weight: bold } /* Keyword.Namespace */
|
||||||
|
.highlight .kp { color: #006699 } /* Keyword.Pseudo */
|
||||||
|
.highlight .kr { color: #006699; font-weight: bold } /* Keyword.Reserved */
|
||||||
|
.highlight .kt { color: #007788; font-weight: bold } /* Keyword.Type */
|
||||||
|
.highlight .m { color: #FF6600 } /* Literal.Number */
|
||||||
|
.highlight .s { color: #CC3300 } /* Literal.String */
|
||||||
|
.highlight .na { color: #330099 } /* Name.Attribute */
|
||||||
|
.highlight .nb { color: #336666 } /* Name.Builtin */
|
||||||
|
.highlight .nc { color: #00AA88; font-weight: bold } /* Name.Class */
|
||||||
|
.highlight .no { color: #336600 } /* Name.Constant */
|
||||||
|
.highlight .nd { color: #9999FF } /* Name.Decorator */
|
||||||
|
.highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */
|
||||||
|
.highlight .ne { color: #CC0000; font-weight: bold } /* Name.Exception */
|
||||||
|
.highlight .nf { color: #CC00FF } /* Name.Function */
|
||||||
|
.highlight .nl { color: #9999FF } /* Name.Label */
|
||||||
|
.highlight .nn { color: #00CCFF; font-weight: bold } /* Name.Namespace */
|
||||||
|
.highlight .nt { color: #330099; font-weight: bold } /* Name.Tag */
|
||||||
|
.highlight .nv { color: #003333 } /* Name.Variable */
|
||||||
|
.highlight .ow { color: #000000; font-weight: bold } /* Operator.Word */
|
||||||
|
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
|
||||||
|
.highlight .mf { color: #FF6600 } /* Literal.Number.Float */
|
||||||
|
.highlight .mh { color: #FF6600 } /* Literal.Number.Hex */
|
||||||
|
.highlight .mi { color: #FF6600 } /* Literal.Number.Integer */
|
||||||
|
.highlight .mo { color: #FF6600 } /* Literal.Number.Oct */
|
||||||
|
.highlight .sb { color: #CC3300 } /* Literal.String.Backtick */
|
||||||
|
.highlight .sc { color: #CC3300 } /* Literal.String.Char */
|
||||||
|
.highlight .sd { color: #CC3300; font-style: italic } /* Literal.String.Doc */
|
||||||
|
.highlight .s2 { color: #CC3300 } /* Literal.String.Double */
|
||||||
|
.highlight .se { color: #CC3300; font-weight: bold } /* Literal.String.Escape */
|
||||||
|
.highlight .sh { color: #CC3300 } /* Literal.String.Heredoc */
|
||||||
|
.highlight .si { color: #AA0000 } /* Literal.String.Interpol */
|
||||||
|
.highlight .sx { color: #CC3300 } /* Literal.String.Other */
|
||||||
|
.highlight .sr { color: #33AAAA } /* Literal.String.Regex */
|
||||||
|
.highlight .s1 { color: #CC3300 } /* Literal.String.Single */
|
||||||
|
.highlight .ss { color: #FFCC33 } /* Literal.String.Symbol */
|
||||||
|
.highlight .bp { color: #336666 } /* Name.Builtin.Pseudo */
|
||||||
|
.highlight .vc { color: #003333 } /* Name.Variable.Class */
|
||||||
|
.highlight .vg { color: #003333 } /* Name.Variable.Global */
|
||||||
|
.highlight .vi { color: #003333 } /* Name.Variable.Instance */
|
||||||
|
.highlight .il { color: #FF6600 } /* Literal.Number.Integer.Long */
|
||||||
|
|
||||||
|
.type-csharp .highlight .k { color: #0000FF }
|
||||||
|
.type-csharp .highlight .kt { color: #0000FF }
|
||||||
|
.type-csharp .highlight .nf { color: #000000; font-weight: normal }
|
||||||
|
.type-csharp .highlight .nc { color: #2B91AF }
|
||||||
|
.type-csharp .highlight .nn { color: #000000 }
|
||||||
|
.type-csharp .highlight .s { color: #A31515 }
|
||||||
|
.type-csharp .highlight .sc { color: #A31515 }
|
423
doc/stylesheets/stylesheet.css
Normal file
423
doc/stylesheets/stylesheet.css
Normal file
@@ -0,0 +1,423 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
Slate Theme for GitHub Pages
|
||||||
|
by Jason Costello, @jsncostello
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
@import url(pygment_trac.css);
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
MeyerWeb Reset
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
html, body, div, span, applet, object, iframe,
|
||||||
|
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
|
||||||
|
a, abbr, acronym, address, big, cite, code,
|
||||||
|
del, dfn, em, img, ins, kbd, q, s, samp,
|
||||||
|
small, strike, strong, sub, sup, tt, var,
|
||||||
|
b, u, i, center,
|
||||||
|
dl, dt, dd, ol, ul, li,
|
||||||
|
fieldset, form, label, legend,
|
||||||
|
table, caption, tbody, tfoot, thead, tr, th, td,
|
||||||
|
article, aside, canvas, details, embed,
|
||||||
|
figure, figcaption, footer, header, hgroup,
|
||||||
|
menu, nav, output, ruby, section, summary,
|
||||||
|
time, mark, audio, video {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
border: 0;
|
||||||
|
font: inherit;
|
||||||
|
vertical-align: baseline;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* HTML5 display-role reset for older browsers */
|
||||||
|
article, aside, details, figcaption, figure,
|
||||||
|
footer, header, hgroup, menu, nav, section {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
ol, ul {
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
border-collapse: collapse;
|
||||||
|
border-spacing: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
Theme Styles
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
body {
|
||||||
|
box-sizing: border-box;
|
||||||
|
color:#373737;
|
||||||
|
background: #212121;
|
||||||
|
font-size: 16px;
|
||||||
|
font-family: 'Myriad Pro', Calibri, Helvetica, Arial, sans-serif;
|
||||||
|
line-height: 1.5;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1, h2, h3, h4, h5, h6 {
|
||||||
|
margin: 10px 0;
|
||||||
|
font-weight: 700;
|
||||||
|
color:#222222;
|
||||||
|
font-family: 'Lucida Grande', 'Calibri', Helvetica, Arial, sans-serif;
|
||||||
|
letter-spacing: -1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 36px;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
padding-bottom: 10px;
|
||||||
|
font-size: 32px;
|
||||||
|
background: url('../images/bg_hr.png') repeat-x bottom;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
font-size: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h4 {
|
||||||
|
font-size: 21px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h5 {
|
||||||
|
font-size: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h6 {
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin: 10px 0 15px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer p {
|
||||||
|
color: #f2f2f2;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
text-decoration: none;
|
||||||
|
color: #007edf;
|
||||||
|
text-shadow: none;
|
||||||
|
|
||||||
|
transition: color 0.5s ease;
|
||||||
|
transition: text-shadow 0.5s ease;
|
||||||
|
-webkit-transition: color 0.5s ease;
|
||||||
|
-webkit-transition: text-shadow 0.5s ease;
|
||||||
|
-moz-transition: color 0.5s ease;
|
||||||
|
-moz-transition: text-shadow 0.5s ease;
|
||||||
|
-o-transition: color 0.5s ease;
|
||||||
|
-o-transition: text-shadow 0.5s ease;
|
||||||
|
-ms-transition: color 0.5s ease;
|
||||||
|
-ms-transition: text-shadow 0.5s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
a:hover, a:focus {text-decoration: underline;}
|
||||||
|
|
||||||
|
footer a {
|
||||||
|
color: #F2F2F2;
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
em {
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
strong {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
img {
|
||||||
|
position: relative;
|
||||||
|
margin: 0 auto;
|
||||||
|
max-width: 739px;
|
||||||
|
padding: 5px;
|
||||||
|
margin: 10px 0 10px 0;
|
||||||
|
border: 1px solid #ebebeb;
|
||||||
|
|
||||||
|
box-shadow: 0 0 5px #ebebeb;
|
||||||
|
-webkit-box-shadow: 0 0 5px #ebebeb;
|
||||||
|
-moz-box-shadow: 0 0 5px #ebebeb;
|
||||||
|
-o-box-shadow: 0 0 5px #ebebeb;
|
||||||
|
-ms-box-shadow: 0 0 5px #ebebeb;
|
||||||
|
}
|
||||||
|
|
||||||
|
p img {
|
||||||
|
display: inline;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
vertical-align: middle;
|
||||||
|
text-align: center;
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre, code {
|
||||||
|
width: 100%;
|
||||||
|
color: #222;
|
||||||
|
background-color: #fff;
|
||||||
|
|
||||||
|
font-family: Monaco, "Bitstream Vera Sans Mono", "Lucida Console", Terminal, monospace;
|
||||||
|
font-size: 14px;
|
||||||
|
|
||||||
|
border-radius: 2px;
|
||||||
|
-moz-border-radius: 2px;
|
||||||
|
-webkit-border-radius: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
width: 100%;
|
||||||
|
padding: 10px;
|
||||||
|
box-shadow: 0 0 10px rgba(0,0,0,.1);
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
padding: 3px;
|
||||||
|
margin: 0 3px;
|
||||||
|
box-shadow: 0 0 10px rgba(0,0,0,.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
pre code {
|
||||||
|
display: block;
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
blockquote {
|
||||||
|
color: #666;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
padding: 0 0 0 20px;
|
||||||
|
border-left: 3px solid #bbb;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ul, ol, dl {
|
||||||
|
margin-bottom: 15px
|
||||||
|
}
|
||||||
|
|
||||||
|
ul {
|
||||||
|
list-style: inside;
|
||||||
|
padding-left: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
ol {
|
||||||
|
list-style: decimal inside;
|
||||||
|
padding-left: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
dl dt {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
dl dd {
|
||||||
|
padding-left: 20px;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
dl p {
|
||||||
|
padding-left: 20px;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr {
|
||||||
|
height: 1px;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
border: none;
|
||||||
|
background: url('../images/bg_hr.png') repeat-x center;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
border: 1px solid #373737;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
th {
|
||||||
|
font-family: 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
||||||
|
padding: 10px;
|
||||||
|
background: #373737;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
td {
|
||||||
|
padding: 10px;
|
||||||
|
border: 1px solid #373737;
|
||||||
|
}
|
||||||
|
|
||||||
|
form {
|
||||||
|
background: #f2f2f2;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
Full-Width Styles
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
.outer {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.inner {
|
||||||
|
position: relative;
|
||||||
|
max-width: 640px;
|
||||||
|
padding: 20px 10px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
#forkme_banner {
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
top:0;
|
||||||
|
right: 10px;
|
||||||
|
z-index: 10;
|
||||||
|
padding: 10px 50px 10px 10px;
|
||||||
|
color: #fff;
|
||||||
|
background: url('../images/blacktocat.png') #0090ff no-repeat 95% 50%;
|
||||||
|
font-weight: 700;
|
||||||
|
box-shadow: 0 0 10px rgba(0,0,0,.5);
|
||||||
|
border-bottom-left-radius: 2px;
|
||||||
|
border-bottom-right-radius: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#header_wrap {
|
||||||
|
background: #212121;
|
||||||
|
background: -moz-linear-gradient(top, #373737, #212121);
|
||||||
|
background: -webkit-linear-gradient(top, #373737, #212121);
|
||||||
|
background: -ms-linear-gradient(top, #373737, #212121);
|
||||||
|
background: -o-linear-gradient(top, #373737, #212121);
|
||||||
|
background: linear-gradient(top, #373737, #212121);
|
||||||
|
}
|
||||||
|
|
||||||
|
#header_wrap .inner {
|
||||||
|
padding: 50px 10px 30px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#project_title {
|
||||||
|
margin: 0;
|
||||||
|
color: #fff;
|
||||||
|
font-size: 42px;
|
||||||
|
font-weight: 700;
|
||||||
|
text-shadow: #111 0px 0px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#project_tagline {
|
||||||
|
color: #fff;
|
||||||
|
font-size: 24px;
|
||||||
|
font-weight: 300;
|
||||||
|
background: none;
|
||||||
|
text-shadow: #111 0px 0px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#downloads {
|
||||||
|
position: absolute;
|
||||||
|
width: 210px;
|
||||||
|
z-index: 10;
|
||||||
|
bottom: -40px;
|
||||||
|
right: 0;
|
||||||
|
height: 70px;
|
||||||
|
background: url('../images/icon_download.png') no-repeat 0% 90%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.zip_download_link {
|
||||||
|
display: block;
|
||||||
|
float: right;
|
||||||
|
width: 90px;
|
||||||
|
height:70px;
|
||||||
|
text-indent: -5000px;
|
||||||
|
overflow: hidden;
|
||||||
|
background: url(../images/sprite_download.png) no-repeat bottom left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tar_download_link {
|
||||||
|
display: block;
|
||||||
|
float: right;
|
||||||
|
width: 90px;
|
||||||
|
height:70px;
|
||||||
|
text-indent: -5000px;
|
||||||
|
overflow: hidden;
|
||||||
|
background: url(../images/sprite_download.png) no-repeat bottom right;
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.zip_download_link:hover {
|
||||||
|
background: url(../images/sprite_download.png) no-repeat top left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tar_download_link:hover {
|
||||||
|
background: url(../images/sprite_download.png) no-repeat top right;
|
||||||
|
}
|
||||||
|
|
||||||
|
#main_content_wrap {
|
||||||
|
background: #f2f2f2;
|
||||||
|
border-top: 1px solid #111;
|
||||||
|
border-bottom: 1px solid #111;
|
||||||
|
}
|
||||||
|
|
||||||
|
#main_content {
|
||||||
|
padding-top: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#footer_wrap {
|
||||||
|
background: #212121;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
Small Device Styles
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
@media screen and (max-width: 480px) {
|
||||||
|
body {
|
||||||
|
font-size:14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#downloads {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.inner {
|
||||||
|
min-width: 320px;
|
||||||
|
max-width: 480px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#project_title {
|
||||||
|
font-size: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 28px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-size: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
font-size: 21px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h4 {
|
||||||
|
font-size: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h5 {
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h6 {
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
code, pre {
|
||||||
|
min-width: 320px;
|
||||||
|
max-width: 480px;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -5,7 +5,7 @@ source = {
|
|||||||
}
|
}
|
||||||
description = {
|
description = {
|
||||||
summary = "A feature-rich command-line argument parser",
|
summary = "A feature-rich command-line argument parser",
|
||||||
detailed = "argparse allows you to define positional arguments, options, flags and default values. Provides automatically generated usage, error and help messages. Supports subcommands and generates a hint when a command or an option is mistyped. ",
|
detailed = "argparse supports positional arguments, options, flags, optional arguments, subcommands and more. argparse automatically generates usage, help and error messages. ",
|
||||||
homepage = "https://github.com/mpeterv/argparse",
|
homepage = "https://github.com/mpeterv/argparse",
|
||||||
license = "MIT/X11"
|
license = "MIT/X11"
|
||||||
}
|
}
|
||||||
@@ -17,5 +17,6 @@ build = {
|
|||||||
type = "builtin",
|
type = "builtin",
|
||||||
modules = {
|
modules = {
|
||||||
argparse = "src/argparse.lua"
|
argparse = "src/argparse.lua"
|
||||||
}
|
},
|
||||||
|
copy_directories = {"doc", "spec"}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user