A Lua package for creating beautiful command line interfaces in a composable way.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
rockspec
src
tests
.gitignore
LICENSE.txt
README.md
test.sh

README.md

lua-click

一个用于快速创建命令行程序的Lua模块。该项目从python库click借鉴了不少灵感,项目名也沿用了"click"这一缩写(Command Line Interface Creation Kit)。

Dependencies

唯一的依赖就是:

  • lua >= 5.1

该模块已在lua-5.1.5, lua-5.2.4, lua-5.3.5下验证通过。

Quick start

一个简单的HelloWorld程序:

-- HelloWorld.lua

local function main(cmd, options, arguments)
    print(string.format("Hi, %s!", arguments["name"]))
    if options["speaker"]~=nil then
        print(string.format("%40s", "-- from " .. options["speaker"]))
    end
end

local cli = require("click")

local mainCommand = cli.FunctionCommand {
    desc = "Say hi to somebody.",
    options = {
        {"-s, --speaker", help="Specify the name of speaker."},
    },
    arguments = {
        {name="name", help="Your name."},
    },
    entry_func = main,
}

if cli.__name__()=="__main__" then
    cli.main(mainCommand, nil, arg)
end