X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=libs%2Flpk%2Fluasrc%2Flpk%2Futil.lua;h=50b33e105cf1b86dc4642b0a64c660e7535407c6;hp=d398094833aff8ca38ac5419d131d55f5121b69b;hb=1f3700085c59ea3b3ed162277948771d41a57ccc;hpb=db4447af91e06cbe875fc656a65756751a1549e5 diff --git a/libs/lpk/luasrc/lpk/util.lua b/libs/lpk/luasrc/lpk/util.lua index d39809483..50b33e105 100644 --- a/libs/lpk/luasrc/lpk/util.lua +++ b/libs/lpk/luasrc/lpk/util.lua @@ -1,37 +1,39 @@ module("luci.lpk.util", package.seeall) function getopt( arg, options ) + options = options or "" local tab = {} local args = {} for k, v in ipairs(arg) do - if v:sub(1, 2) == "--" then - local x = v:find( "=", 1, true ) - if x then - tab[ v:sub( 3, x-1 ) ] = v:sub( x+1 ) - else - tab[ v:sub( 3 ) ] = true - end - elseif v:sub( 1, 1 ) == "-" then - local y = 2 - local l = #v - local jopt - while ( y <= l ) do - jopt = v:sub( y, y ) - if options:find( jopt, 1, true ) then - if y < l then - tab[ jopt ] = v:sub( y+1 ) - y = l + if v:sub(1, 2) == "--" then + local x = v:find( "=", 1, true ) + if x then + tab[ v:sub( 3, x-1 ) ] = v:sub( x+1 ) + else + tab[ v:sub( 3 ) ] = true + end + elseif v:sub( 1, 1 ) == "-" then + local y = 2 + local l = #v + local jopt + while ( y <= l ) do + jopt = v:sub( y, y ) + if options:find( jopt, 1, true ) then + if y < l then + tab[ jopt ] = v:sub( y+1 ) + y = l + else + tab[ jopt ] = arg[ k + 1 ] + arg[ k + 1 ] = "" + end else - tab[ jopt ] = arg[ k + 1 ] + tab[ jopt ] = true end - else - tab[ jopt ] = true + y = y + 1 end - y = y + 1 - end - else - table.insert(args, v) - end - end - return tab, args + elseif #v > 0 then + table.insert(args, v) + end + end + return tab, args end \ No newline at end of file