Comparison

util/startup.lua @ 10600:08f2fe5ac30f 0.11

util.startup: Fix logic to make --config work again
author Matthew Wild <mwild1@gmail.com>
date Sun, 19 Jan 2020 15:39:13 +0000
parent 10597:25a3c8134b0a
child 10601:d8b51833926b
child 10602:f23add0df461
comparison
equal deleted inserted replaced
10598:5cf481bee678 10600:08f2fe5ac30f
16 local value_params = { config = true }; 16 local value_params = { config = true };
17 17
18 function startup.parse_args() 18 function startup.parse_args()
19 local parsed_opts = {}; 19 local parsed_opts = {};
20 20
21 if #arg > 0 and arg[1] ~= "--config" then 21 if #arg == 0 then
22 while true do 22 return;
23 local raw_param = arg[1]; 23 end
24 if not raw_param then 24 while true do
25 break; 25 local raw_param = arg[1];
26 end 26 if not raw_param then
27 27 break;
28 local prefix = raw_param:match("^%-%-?"); 28 end
29 if not prefix then 29
30 break; 30 local prefix = raw_param:match("^%-%-?");
31 elseif prefix == "--" and raw_param == "--" then 31 if not prefix then
32 table.remove(arg, 1); 32 break;
33 break; 33 elseif prefix == "--" and raw_param == "--" then
34 end 34 table.remove(arg, 1);
35 local param = table.remove(arg, 1):sub(#prefix+1); 35 break;
36 if #param == 1 then 36 end
37 param = short_params[param]; 37 local param = table.remove(arg, 1):sub(#prefix+1);
38 end 38 if #param == 1 then
39 39 param = short_params[param];
40 if not param then 40 end
41 print("Unknown command-line option: "..tostring(param)); 41
42 print("Perhaps you meant to use prosodyctl instead?"); 42 if not param then
43 print("Unknown command-line option: "..tostring(param));
44 print("Perhaps you meant to use prosodyctl instead?");
45 os.exit(1);
46 end
47
48 local param_k, param_v;
49 if value_params[param] then
50 param_k, param_v = param, table.remove(arg, 1);
51 if not param_v then
52 print("Expected a value to follow command-line option: "..raw_param);
43 os.exit(1); 53 os.exit(1);
44 end 54 end
45 55 else
46 local param_k, param_v; 56 param_k, param_v = param:match("^([^=]+)=(.+)$");
47 if value_params[param] then 57 if not param_k then
48 param_k, param_v = param, table.remove(arg, 1); 58 if param:match("^no%-") then
49 if not param_v then 59 param_k, param_v = param:sub(4), false;
50 print("Expected a value to follow command-line option: "..raw_param); 60 else
51 os.exit(1); 61 param_k, param_v = param, true;
52 end 62 end
53 else 63 end
54 param_k, param_v = param:match("^([^=]+)=(.+)$"); 64 end
55 if not param_k then 65 parsed_opts[param_k] = param_v;
56 if param:match("^no%-") then 66 print("ARG", param_k, param_v);
57 param_k, param_v = param:sub(4), false;
58 else
59 param_k, param_v = param, true;
60 end
61 end
62 end
63 parsed_opts[param_k] = param_v;
64 end
65 end 67 end
66 prosody.opts = parsed_opts; 68 prosody.opts = parsed_opts;
67 end 69 end
68 70
69 function startup.read_config() 71 function startup.read_config()