TT#16518 ngcp-dlg(cnt|list)-clean: improve arg parse

* use lua-argparse to improve argument parsing

Change-Id: I25b1a216294f77849101e58eae8fe9daa8da67b7
changes/34/13334/1
Victor Seva 8 years ago
parent 751c1e7ef9
commit e6a3a1bdc6

@ -3,6 +3,16 @@
local NGCPDlg = require 'ngcp.dlgcnt'
local config = "/etc/kamailio/proxy/dlgcnt.lua.cfg"
local argparse = require "argparse"
local parser = argparse() {
name = "ngcp-dlgcnt-clean",
description = "helper to remove kamailio dialogs from redis db"
}
parser:argument("callid", "Call-Id to remove")
parser:flag("-c --config-db", "redis db defined at config")
parser:flag("-C --config-host", "redis server defined at config")
-- luacheck: globals dlg_config
sr = {}
sr.log = function (level, str)
@ -21,26 +31,16 @@ local function get_config()
end
end
local function usage()
print("ngcp-dlgcnt-clean callid")
end
if #arg ~= 1 then
io.stderr:write("wrong number of arguments\n");
usage()
os.exit(2)
end
if arg[1] == "-h" then usage(); os.exit(0); end
local args = parser:parse()
get_config()
local dlg = NGCPDlg:new()
if arg[1] == '-c' then
print(tostring(dlg.config.pair.db))
if args.config_db then
print(tostring(dlg_config.pair.db))
os.exit(0)
elseif arg[1] == '-C' then
elseif args.config_host then
print(tostring(dlg_config.pair.host))
os.exit(0)
end
@ -55,4 +55,4 @@ if dlg_config then
--print(string.format("dlg.config:%s", ut.tostring(dlg.config)))
end
dlg:del(arg[1])
dlg:del(args.callid)

@ -3,6 +3,14 @@
local NGCPDlgList = require 'ngcp.dlglist'
local config = "/etc/kamailio/proxy/dlgcnt.lua.cfg"
local argparse = require "argparse"
local parser = argparse() {
name = "ngcp-dlglist-clean",
description = "helper to remove kamailio queue dialogs from redis db"
}
parser:argument("callid", "Call-Id to remove")
-- luacheck: globals dlg_config
sr = {}
sr.log = function (level, str)
@ -21,17 +29,7 @@ local function get_config()
end
end
local function usage()
print("ngcp-dlglist-clean callid")
end
if #arg ~= 1 then
io.stderr:write("wrong number of arguments\n");
usage()
os.exit(2)
end
if arg[1] == "-h" then usage(); os.exit(0); end
local args = parser:parse()
get_config()
@ -46,4 +44,4 @@ if dlg_config then
--print(string.format("dlg.config:%s", ut.tostring(dlg.config)))
end
dlg:destroy(arg[1])
dlg:destroy(args.callid)

@ -10,7 +10,8 @@ ENV REFRESHED_AT 2016-12-2
# TODO - the release-trunk-jessie is too dynamic yet, though required for lua-unit backport
RUN echo "deb https://deb.sipwise.com/autobuild/ release-trunk-jessie main" >>/etc/apt/sources.list
RUN apt-get update && apt-get install --assume-yes lua5.1 lua-unit lua-lemock lua-logging python-xmlrunner
RUN apt-get update && apt-get install --assume-yes \
lua5.1 lua-unit lua-lemock lua-logging lua-argparse python-xmlrunner
RUN echo './t/testrunner' >>/root/.bash_history

Loading…
Cancel
Save