forked from lunarmodules/lua_cliargs
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.lua
More file actions
Latest commit
28 lines (23 loc) · 862 Bytes
/
Copy pathtest.lua
File metadata and controls
28 lines (23 loc) · 862 Bytes
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
localcli=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")
localargs=cli:parse_args()
ifnotargsthen
-- something wrong happened and an error was printed
return
end
-- argument parsing was successful, arguments can be found in `args`
fork,iteminpairs(args) doprint(k.." => " ..tostring(item)) end
-- checking for flags: is -v or --version set?
ifargs["v"] then
returnprint("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()