Giter Site home page Giter Site logo

argparse's Introduction

argparse

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.

Contents

Example

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 [-o <output>] [-I <include>] [-h] <input>

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

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

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

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

License

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

argparse's People

Contributors

alloyed avatar jsbackus avatar mpeterv avatar stepelu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.