summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2014-12-19 13:27:12 +0000
committerDaniel Kolesa <d.kolesa@samsung.com>2014-12-19 13:27:12 +0000
commit70017eddb0b4104db75ec8bb4f4150f6cb4279d0 (patch)
tree80e45da8e07594d480b0bde99ffd234524dc8aff
parent74ff95c349af9717edbed1246d792a205056f276 (diff)
elua: handle getopt callback failures
-rw-r--r--src/scripts/elua/modules/getopt.lua23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/scripts/elua/modules/getopt.lua b/src/scripts/elua/modules/getopt.lua
index 0a73fa2e23..0db513da5a 100644
--- a/src/scripts/elua/modules/getopt.lua
+++ b/src/scripts/elua/modules/getopt.lua
@@ -7,7 +7,6 @@
7 - arguments that can only be specified once (for now you can check 7 - arguments that can only be specified once (for now you can check
8 that manually by going over array values of opts) 8 that manually by going over array values of opts)
9 - i18n support 9 - i18n support
10 - support for desc callback failures
11 10
12 Copyright (c) 2014 Daniel "q66" Kolesa <quaker66@gmail.com> 11 Copyright (c) 2014 Daniel "q66" Kolesa <quaker66@gmail.com>
13 12
@@ -40,7 +39,7 @@ local get_desc = function(opt, j, descs)
40 return v 39 return v
41 end 40 end
42 end 41 end
43 error("option " .. prefixes[j] .. opt .. " not recognized", 4) 42 error("option " .. prefixes[j] .. opt .. " not recognized", 0)
44end 43end
45 44
46local is_arg = function(opt, j, descs) 45local is_arg = function(opt, j, descs)
@@ -66,14 +65,14 @@ local parse_l = function(opts, opt, descs, args, parser)
66 if not optval then 65 if not optval then
67 if #args == 0 then 66 if #args == 0 then
68 if argr then 67 if argr then
69 error("option --" .. opt .. " requires an argument", 3) 68 error("option --" .. opt .. " requires an argument", 0)
70 end 69 end
71 elseif argr or not is_arg(args[1], 2, descs) then 70 elseif argr or not is_arg(args[1], 2, descs) then
72 optval = table.remove(args, 1) 71 optval = table.remove(args, 1)
73 end 72 end
74 end 73 end
75 elseif optval then 74 elseif optval then
76 error("option --" .. opt .. " cannot have an argument", 3) 75 error("option --" .. opt .. " cannot have an argument", 0)
77 end 76 end
78 local rets 77 local rets
79 if desc.callback then 78 if desc.callback then
@@ -111,7 +110,7 @@ local parse_s = function(opts, optstr, descs, args, parser)
111 optstr = nil 110 optstr = nil
112 if #args == 0 then 111 if #args == 0 then
113 if argr then 112 if argr then
114 error("option -" .. opt .. " requires an argument", 3) 113 error("option -" .. opt .. " requires an argument", 0)
115 end 114 end
116 elseif argr or not is_arg(args[1], 1, descs) then 115 elseif argr or not is_arg(args[1], 1, descs) then
117 optstr = table.remove(args, 1) 116 optstr = table.remove(args, 1)
@@ -437,7 +436,7 @@ end
437 <CATEGORYNAME>: 436 <CATEGORYNAME>:
438 -x, --long Description for no argument. 437 -x, --long Description for no argument.
439 -h[?<METAVAR>], --help=[?<METAVAR>] Description for optional argument. 438 -h[?<METAVAR>], --help=[?<METAVAR>] Description for optional argument.
440 -f<METAVAR>, --foo=<METAVAR> Description for mandatory argument. 439 -f[<METAVAR>], --foo=[<METAVAR>] Description for mandatory argument.
441 440
442 <ANOTHERCATEGORYNAME>: 441 <ANOTHERCATEGORYNAME>:
443 <MOREARGS> 442 <MOREARGS>
@@ -482,12 +481,20 @@ end
482 481
483-- A utility callback for geometry parsing (--foo=x:y:w:h). 482-- A utility callback for geometry parsing (--foo=x:y:w:h).
484M.geometry_parse_cb = function(desc, parser, v) 483M.geometry_parse_cb = function(desc, parser, v)
485 return v:match("^(%d+):(%d+):(%d+):(%d+)$") 484 local x, y, w, h = v:match("^(%d+):(%d+):(%d+):(%d+)$")
485 if not x then
486 error("bad geometry value: " .. v, 0)
487 end
488 return x, y, w, h
486end 489end
487 490
488-- A utility callback for size parsing (--foo=WxH). 491-- A utility callback for size parsing (--foo=WxH).
489M.size_parse_cb = function(desc, parser, v) 492M.size_parse_cb = function(desc, parser, v)
490 return v:match("^(%d+)x(%d+)$") 493 local w, h = v:match("^(%d+)x(%d+)$")
494 if not w then
495 error("bad size value: " .. v, 0)
496 end
497 return w, h
491end 498end
492 499
493-- A utility callback generator for help. Returns a utility callback when 500-- A utility callback generator for help. Returns a utility callback when