mpeterv 4320f40844 Update travis config
Bump setup scripts, use luacheck.
2015-06-09 21:57:02 +03:00
2014-08-25 14:20:57 +04:00
2015-03-13 14:44:13 +03:00
2015-06-09 21:57:02 +03:00
2015-06-09 21:57:02 +03:00
2015-06-09 21:57:02 +03:00
2015-06-09 21:57:02 +03:00
2015-01-15 16:25:00 +03:00
2014-11-06 16:25:26 +03:00

argparse

Build Status

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:

-- 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)
$ lua script.lua foo
input: foo
output: a.out
include: {}
$ lua script.lua foo -I/usr/local/include -I/src -o bar
input: foo
output: bar
include: {/usr/local/include, /src}
$ lua script.lua foo bar
Usage: script.lua [-o <output>] [-I <include>] [-h] <input>

Error: too many arguments
$ 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.
$ lua script.lua foo --outptu=bar
Usage: script.lua [-o <output>] [-I <include>] [-h] <input>

Error: unknown option '--outptu'
Did you mean '--output'?

Contents

Installation

Using luarocks

Installing argparse using luarocks is simple.

$ luarocks install argparse

Without luarocks

Download src/argparse.lua file and put it into the directory for Lua libraries or your working directory.

Tutorial

The tutorial is available online and in the doc directory. If argparse was installed using luarocks 2.1.2 or later, it can be viewed using luarocks doc argparse command.

Testing

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 spec command from the argparse folder.

License

argparse is licensed under the same terms as Lua itself(MIT license).

Description
Feature-rich command line parser for Lua
Readme MIT 774 KiB
Languages
Lua 94.7%
Python 5.3%