Fix language selection broken after po file merges
[project/luci.git] / libs / lpk / luasrc / lpk / util.lua
1 module("luci.lpk.util", package.seeall)
2
3 function getopt( arg, options )
4 options = options or ""
5 local tab = {}
6 local args = {}
7 for k, v in ipairs(arg) do
8 if v:sub(1, 2) == "--" then
9 local x = v:find( "=", 1, true )
10 if x then
11 tab[ v:sub( 3, x-1 ) ] = v:sub( x+1 )
12 else
13 tab[ v:sub( 3 ) ] = true
14 end
15 elseif v:sub( 1, 1 ) == "-" then
16 local y = 2
17 local l = #v
18 local jopt
19 while ( y <= l ) do
20 jopt = v:sub( y, y )
21 if options:find( jopt, 1, true ) then
22 if y < l then
23 tab[ jopt ] = v:sub( y+1 )
24 y = l
25 else
26 tab[ jopt ] = arg[ k + 1 ]
27 arg[ k + 1 ] = ""
28 end
29 else
30 tab[ jopt ] = true
31 end
32 y = y + 1
33 end
34 elseif #v > 0 then
35 table.insert(args, v)
36 end
37 end
38 return tab, args
39 end
40
41 function splash()
42 require("luci.lpk")
43 luci.util.perror(string.format("%s v%s\n%s",
44 luci.lpk.__appname__, luci.lpk.__version__, luci.lpk.__cpyrght__))
45 luci.util.perror([[
46
47 Usage:
48 lpk [options] <command> [arguments]
49 lpk [options] install|remove pkg1 [pkg2] [...] [pkgn]
50
51 Commands:
52 install - Install packages
53 remove - Remove packages
54 purge - Remove packages and their configuration files
55
56 Options:
57 --force-depends - Ignore unresolvable dependencies
58 ]])
59 end