Mercurial > prosody-hg
comparison util/argparse.lua @ 12477:cc84682b8429 0.12
util.argparse: Revise 553c6204fe5b with a different approach
The second return value is (not insensibly) assumed to be an error. Instead of
returning a value there in the success case, copy the positional arguments
into the existing opts table.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Mon, 25 Apr 2022 15:24:56 +0100 |
| parents | 553c6204fe5b |
| children | 766152afc1c9 |
comparison
equal
deleted
inserted
replaced
| 12475:553c6204fe5b | 12477:cc84682b8429 |
|---|---|
| 3 local value_params = config and config.value_params or {}; | 3 local value_params = config and config.value_params or {}; |
| 4 | 4 |
| 5 local parsed_opts = {}; | 5 local parsed_opts = {}; |
| 6 | 6 |
| 7 if #arg == 0 then | 7 if #arg == 0 then |
| 8 return parsed_opts, arg; | 8 return parsed_opts; |
| 9 end | 9 end |
| 10 while true do | 10 while true do |
| 11 local raw_param = arg[1]; | 11 local raw_param = arg[1]; |
| 12 if not raw_param then | 12 if not raw_param then |
| 13 break; | 13 break; |
| 45 end | 45 end |
| 46 end | 46 end |
| 47 end | 47 end |
| 48 parsed_opts[param_k] = param_v; | 48 parsed_opts[param_k] = param_v; |
| 49 end | 49 end |
| 50 return parsed_opts, arg; | 50 for i = 1, #arg do |
| 51 parsed_opts[i] = arg[i]; | |
| 52 end | |
| 53 return parsed_opts; | |
| 51 end | 54 end |
| 52 | 55 |
| 53 return { | 56 return { |
| 54 parse = parse; | 57 parse = parse; |
| 55 } | 58 } |
