2013-09-20 03:21:12 +08:00
|
|
|
|
|
|
|
-- The getopt-functionality is loaded from pm3/getopt.lua
|
|
|
|
-- Have a look there for further details
|
|
|
|
getopt = require('getopt')
|
|
|
|
|
|
|
|
usage = "script run parameters.lua -a 1 -blala -c -de"
|
|
|
|
author = "Martin Holst Swende"
|
|
|
|
desc =[[
|
2019-03-09 17:34:43 +08:00
|
|
|
This is an example script to demonstrate handle parameters in scripts.
|
2013-09-20 03:21:12 +08:00
|
|
|
For more info, check the comments in the code
|
|
|
|
]]
|
|
|
|
|
|
|
|
local function main(args)
|
|
|
|
|
2019-03-09 17:34:43 +08:00
|
|
|
print(desc)
|
|
|
|
print("These parameters were passed")
|
|
|
|
--[[
|
|
|
|
When passing parameters,
|
|
|
|
x: means that a value should follow x
|
|
|
|
y means that 'y' is a flag, either on or off
|
|
|
|
So, the string a:b:def means that we support up to
|
|
|
|
5 parameters; two with values and three flags. The following
|
|
|
|
should be valid:
|
|
|
|
|
|
|
|
script run parameters.lua -a 1 -blala -c -de
|
|
|
|
|
|
|
|
Notice two things:
|
|
|
|
1. 'blala' works just like 'b lala', both set 'b' to 'lala'
|
|
|
|
2. Flags can be put together, '-de' is the same as '-d -e'
|
|
|
|
3. The format -b=lala is *not* supported
|
|
|
|
4. The format b lala (without -) is *not* supported
|
|
|
|
--]]
|
|
|
|
|
|
|
|
for o, a in getopt.getopt(args, 'a:b:ced') do
|
|
|
|
print(o, a)
|
|
|
|
end
|
2013-09-20 03:21:12 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--[[
|
2019-03-09 17:34:43 +08:00
|
|
|
In the future, we may implement so that scripts are invoked directly
|
2013-09-20 03:21:12 +08:00
|
|
|
into a 'main' function, instead of being executed blindly. For future
|
2019-03-09 17:34:43 +08:00
|
|
|
compatibility, I have done so, but I invoke my main from here.
|
2013-09-20 03:21:12 +08:00
|
|
|
--]]
|
2019-03-12 07:12:26 +08:00
|
|
|
main(args)
|