17 local value_params = { config = true }; |
17 local value_params = { config = true }; |
18 |
18 |
19 function startup.parse_args() |
19 function startup.parse_args() |
20 local parsed_opts = {}; |
20 local parsed_opts = {}; |
21 |
21 |
22 if #arg > 0 and arg[1] ~= "--config" then |
22 if #arg == 0 then |
23 while true do |
23 return; |
24 local raw_param = arg[1]; |
24 end |
25 if not raw_param then |
25 while true do |
26 break; |
26 local raw_param = arg[1]; |
27 end |
27 if not raw_param then |
28 |
28 break; |
29 local prefix = raw_param:match("^%-%-?"); |
29 end |
30 if not prefix then |
30 |
31 break; |
31 local prefix = raw_param:match("^%-%-?"); |
32 elseif prefix == "--" and raw_param == "--" then |
32 if not prefix then |
33 table.remove(arg, 1); |
33 break; |
34 break; |
34 elseif prefix == "--" and raw_param == "--" then |
35 end |
35 table.remove(arg, 1); |
36 local param = table.remove(arg, 1):sub(#prefix+1); |
36 break; |
37 if #param == 1 then |
37 end |
38 param = short_params[param]; |
38 local param = table.remove(arg, 1):sub(#prefix+1); |
39 end |
39 if #param == 1 then |
40 |
40 param = short_params[param]; |
41 if not param then |
41 end |
42 print("Unknown command-line option: "..tostring(param)); |
42 |
43 print("Perhaps you meant to use prosodyctl instead?"); |
43 if not param then |
|
44 print("Unknown command-line option: "..tostring(param)); |
|
45 print("Perhaps you meant to use prosodyctl instead?"); |
|
46 os.exit(1); |
|
47 end |
|
48 |
|
49 local param_k, param_v; |
|
50 if value_params[param] then |
|
51 param_k, param_v = param, table.remove(arg, 1); |
|
52 if not param_v then |
|
53 print("Expected a value to follow command-line option: "..raw_param); |
44 os.exit(1); |
54 os.exit(1); |
45 end |
55 end |
46 |
56 else |
47 local param_k, param_v; |
57 param_k, param_v = param:match("^([^=]+)=(.+)$"); |
48 if value_params[param] then |
58 if not param_k then |
49 param_k, param_v = param, table.remove(arg, 1); |
59 if param:match("^no%-") then |
50 if not param_v then |
60 param_k, param_v = param:sub(4), false; |
51 print("Expected a value to follow command-line option: "..raw_param); |
61 else |
52 os.exit(1); |
62 param_k, param_v = param, true; |
53 end |
63 end |
54 else |
64 end |
55 param_k, param_v = param:match("^([^=]+)=(.+)$"); |
65 end |
56 if not param_k then |
66 parsed_opts[param_k] = param_v; |
57 if param:match("^no%-") then |
67 print("ARG", param_k, param_v); |
58 param_k, param_v = param:sub(4), false; |
|
59 else |
|
60 param_k, param_v = param, true; |
|
61 end |
|
62 end |
|
63 end |
|
64 parsed_opts[param_k] = param_v; |
|
65 end |
|
66 end |
68 end |
67 prosody.opts = parsed_opts; |
69 prosody.opts = parsed_opts; |
68 end |
70 end |
69 |
71 |
70 function startup.read_config() |
72 function startup.read_config() |