👨💻 about me home CV/Resume News 🖊️ Contact Codeberg Github LinkedIn 🏆 Best of LuaX (tools) pub bang ypp panda lsvg ldc yreq Fizzbuzz Calculadoira TPG picfg Belenos (intro) dnsfilter 🔀 Git Repos
Made in Europe
Note
This fork of argparse is fully compatible with luarocks/argparse. It
provides minor cosmetic updates:
To update argparse from upstream:
git checkout master
git remote add luarocks https://github.com/luarocks/argparse
git fetch luarocks
git pull --rebase luarocks master
git push
git checkout LuaX
git pull --rebase origin masterArgparse 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, and can generate shell completion scripts.
Simple example:
-- script.lua
local argparse = require "argparse"
local parser = argparse("script", "An example.")
parser:argument("input", "Input file.")
parser:option("-o --output", "Output file.", "a.out")
parser:option("-I --include", "Include locations."):count("*")
local args = parser:parse()args contents depending on command line arguments:
$ lua script.lua foo{
input = "foo",
output = "a.out",
include = {}
}$ lua script.lua foo -I/usr/local/include -Isrc -o bar{
input = "foo",
output = "bar",
include = {"/usr/local/include", "src"}
}Error messages depending on command line arguments:
$ lua script.lua foo barUsage: script [-h] [-o <output>] [-I <include>] <input>
Error: too many arguments
$ lua script.lua --helpUsage: script [-h] [-o <output>] [-I <include>] <input>
An example.
Arguments:
input Input file.
Options:
-h, --help Show this help message and exit.
-o <output>, --output <output>
Output file. (default: a.out)
-I <include>, --include <include>
Include locations.
$ lua script.lua foo --outptu=barUsage: script [-h] [-o <output>] [-I <include>] <input>
Error: unknown option '--outptu'
Did you mean '--output'?
Installing argparse using LuaRocks is simple:
$ luarocks install argparseDownload src/argparse.lua file and put it into the
directory for Lua libraries or your working directory.
The tutorial is available online. If argparse has been
installed using LuaRocks 2.1.2 or later, it can be viewed using
luarocks doc argparse command.
Tutorial HTML files can be built using Sphinx:
sphinx-build docsrc doc, the files will be found inside
doc/.
argparse comes with a testing suite located in spec
directory. busted
is required for testing, it can be installed using LuaRocks. Run the
tests using busted command from the argparse folder.
argparse is licensed under the same terms as Lua itself (MIT license).
This site is powered by LuaX, bang, ypp, cdsoft.css and Pandoc.
Mirrors: cdelord.fr – christophe.delord.free.fr – cdsoft.codeberg.page