• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

mpeterv/argparse: Feature-rich command line parser for Lua

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

mpeterv/argparse

开源软件地址(OpenSource Url):

https://github.com/mpeterv/argparse

开源编程语言(OpenSource Language):

Lua 93.4%

开源软件介绍(OpenSource 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).




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap