Skip to content
Feature-rich command line parser for Lua
Lua Python
Branch: master
Clone or download
Pull request Compare This branch is 68 commits ahead of mpeterv:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
docsrc Update docsrc/ for 0.7.0 release Aug 15, 2019
spec Bash completions: add support for nested commands Aug 12, 2019
src 0.7.0 release Aug 15, 2019
.gitignore Add doc/ to .gitignore Apr 12, 2018
.luacheckrc Update travis config Jun 9, 2015
.travis.yml Fix codecov call and badge Mar 17, 2018 0.7.0 release Aug 15, 2019
LICENSE Merge remote-tracking branch 'luarocks/refs/pull/2/head' Jul 26, 2019 0.7.0 release Aug 15, 2019
argparse-scm-2.rockspec 0.7.0 release Aug 15, 2019


Build Status Coverage 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, 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 bar
Usage: script [-h] [-o <output>] [-I <include>] <input>

Error: too many arguments
$ lua script.lua --help
Usage: script [-h] [-o <output>] [-I <include>] <input>

An example. 

   input                 Input file.

   -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=bar
Usage: script [-h] [-o <output>] [-I <include>] <input>

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


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.


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).

You can’t perform that action at this time.