Software /
code /
prosody
Comparison
util/argparse.lua @ 12475:553c6204fe5b 0.12
util.argparse: Return final 'arg' table with positional arguments for convenience
This is the same as the input table (which is mutated during processing), but
if that table was created on the fly, such as by packing `...` it's convenient
if it also gets returned from the parse function.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 25 Apr 2022 15:09:41 +0100 |
parent | 11846:6425dfa3de45 |
child | 12477:cc84682b8429 |
comparison
equal
deleted
inserted
replaced
12474:8fac32810144 | 12475:553c6204fe5b |
---|---|
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; | 8 return parsed_opts, arg; |
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; | 50 return parsed_opts, arg; |
51 end | 51 end |
52 | 52 |
53 return { | 53 return { |
54 parse = parse; | 54 parse = parse; |
55 } | 55 } |