proxmark3/client/luascripts/parameters.lua

77 lines
2.1 KiB
Lua
Raw Normal View History

-- The getopt-functionality is loaded from pm3/getopt.lua
-- Have a look there for further details
2020-04-05 18:49:25 +08:00
local getopt = require('getopt')
local ansicolors = require('ansicolors')
2019-04-29 03:29:47 +08:00
copyright = ''
usage = 'script run parameters.lua -a 1 -blala -c -de'
author = 'Martin Holst Swende'
2020-04-05 18:49:25 +08:00
version = 'v1.0.2'
2019-04-29 03:29:47 +08:00
desc = [[
2019-03-09 17:34:43 +08:00
This is an example script to demonstrate handle parameters in scripts.
For more info, check the comments in the code
]]
2019-04-29 03:29:47 +08:00
example = [[
2020-04-05 18:49:25 +08:00
1. script run parameters -a mytestparam_input -c
2019-04-29 03:29:47 +08:00
]]
usage = [[
2020-04-05 18:49:25 +08:00
script run parameters [-h] [-a <txt>] [-b <txt>] [-c] [-d] [-e]
2019-04-29 03:29:47 +08:00
]]
2020-04-05 18:49:25 +08:00
arguments = [[
-h This help
-a <txt> text
-b <txt> text
-c test param w/o input
-d test param w/o input
-e test param w/o input
]]
2019-04-29 03:29:47 +08:00
---
-- Usage help
local function help()
print(copyright)
print(author)
print(version)
print(desc)
2020-04-05 18:49:25 +08:00
print(ansicolors.cyan..'Usage'..ansicolors.reset)
2019-04-29 03:29:47 +08:00
print(usage)
2020-04-05 18:49:25 +08:00
print(ansicolors.cyan..'Arguments'..ansicolors.reset)
print(arguments)
print(ansicolors.cyan..'Example usage'..ansicolors.reset)
print(example)
2019-04-29 03:29:47 +08:00
end
local function main(args)
2019-04-29 03:29:47 +08:00
print('These parameters were passed')
2019-03-09 17:34:43 +08:00
--[[
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
--]]
2019-04-29 03:29:47 +08:00
for o, a in getopt.getopt(args, 'ha:b:ced') do
if o == 'h' then return help() end
2019-03-09 17:34:43 +08:00
print(o, a)
end
end
--[[
2019-03-09 17:34:43 +08:00
In the future, we may implement so that scripts are invoked directly
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.
--]]
2019-03-12 07:12:26 +08:00
main(args)