diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2015-04-12 12:59:54 +0000 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2015-08-25 08:05:42 +0200 |
commit | 3e19c78b725562186996f38daa34288650db0949 (patch) | |
tree | 8dda867e93c9c35cb796ad0b190fe0e7a0cf0ef8 /buildrepo.lua | |
parent | 62478e8dc18cac0ffc3d30917f057b1d1d75f9f0 (diff) | |
download | lua-aports-3e19c78b725562186996f38daa34288650db0949.tar.bz2 lua-aports-3e19c78b725562186996f38daa34288650db0949.tar.xz |
buildrepo: use external lua-optarg for parsing options
Diffstat (limited to 'buildrepo.lua')
-rwxr-xr-x | buildrepo.lua | 52 |
1 files changed, 6 insertions, 46 deletions
diff --git a/buildrepo.lua b/buildrepo.lua index 5c4b931..6170c24 100755 --- a/buildrepo.lua +++ b/buildrepo.lua @@ -3,6 +3,7 @@ local abuild = require("aports.abuild") local apkrepo = require("aports.apkrepo") local lfs = require("lfs") +local optarg = require("optarg") local pluginsdir = "/etc/buildrepo/plugins.d" @@ -26,44 +27,6 @@ local function info(formatstr, ...) io.stdout:flush() end -local function parse_opts(opthelp, raw_args) - local valid_opts = {} - local opts = {} - local args = {} - local moreopts = true - for optc, separator in opthelp:gmatch("%s+%-(%a)(%s+)") do - valid_opts[optc] = { hasarg = (separator == " ") } - end - - local i = 1 - while i <= #raw_args do - local a = raw_args[i] - i = i + 1 - if a == "--" then - moreopts = false - elseif moreopts and a:sub(1,1) == "-" then - for j = 2, #a do - local opt = a:sub(j,j) - if not valid_opts[opt] then - return nil, opt, "invalid option" - end - if valid_opts[opt].hasarg then - opts[opt] = raw_args[i] - i = i + 1 - else - opts[opt] = true - end - if not opts[opt] then - return nil, opt, "optarg required" - end - end - else - args[#args + 1] = a - end - end - return opts, args -end - local function skip_aport(aport) local dirattr = lfs.attributes(aport.dir.."/src/") local fileattr = lfs.attributes(aport.dir.."/APKBUILD") @@ -159,13 +122,14 @@ local opthelp = [[ ]] local function usage(exitcode) - io.stdout:write(("options:\n%s\n"):format(opthelp)) + io.stdout:write(( +"Usage: %s [-hknps] [-a DIR] [-d DIR] [-l DIR] [-r REPO] REPO...\n".. +"Options:\n%s\n"):format(_G.arg[0], opthelp)) os.exit(exitcode) end -opts, args, errmsg = parse_opts(opthelp, arg) -if opts == nil then - io.stderr:write(("%s: -%s\n"):format(errmsg, args)) +opts, args = optarg.from_opthelp(opthelp) +if opts == nil or #args == 0 then usage(1) end @@ -173,10 +137,6 @@ if opts.h then usage(0) end -if #args == 0 then - usage(1) -end - homedir = os.getenv("HOME") aportsdir = opts.a or ("%s/aports"):format(homedir) repodest = opts.d or abuild.repodest or ("%s/packages"):format(homedir) |