forked from lunarmodules/lua_cliargs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.lua
28 lines (23 loc) · 862 Bytes
/
test.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
local cli = require "cliargs"
cli:set_name("test.lua")
cli:add_argument("root", "path to where root scripts can be found")
cli:add_option("-o FILE", "path to the output file")
cli:add_option("-i, --input=FILE", "path to an input file", "input_path")
cli:add_flag("-v, --version", "prints the program's version and exits")
local args = cli:parse_args()
if not args then
-- something wrong happened and an error was printed
return
end
-- argument parsing was successful, arguments can be found in `args`
for k,item in pairs(args) do print(k .. " => " .. tostring(item)) end
-- checking for flags: is -v or --version set?
if args["v"] then
return print("test.lua: version 0.0.0")
end
-- overridden keys:
print("Input file: " .. args["input_path"])
-- default keys:
print("Output file: " .. args["o"])
-- force display of help listing:
-- cli:print_help()