Comparison

util/argparse.lua @ 10936:d770435f0f84

util.argparse: Move exiting and error to util.startup It's not so nice to have a library that exits the entire application from under you, so this and the error reporting belongs in util.startup. The argparse code was originally in util.startup but moved out in 1196f1e8d178 but the error handling should have stayed.
author Kim Alvefur <zash@zash.se>
date Wed, 17 Jun 2020 19:32:12 +0200
parent 10651:1196f1e8d178
child 11846:6425dfa3de45
comparison
equal deleted inserted replaced
10935:2d57c49bfa12 10936:d770435f0f84
24 if #param == 1 and short_params then 24 if #param == 1 and short_params then
25 param = short_params[param]; 25 param = short_params[param];
26 end 26 end
27 27
28 if not param then 28 if not param then
29 print("Unknown command-line option: "..tostring(param)); 29 return nil, "param-not-found", param;
30 print("Perhaps you meant to use prosodyctl instead?");
31 os.exit(1);
32 end 30 end
33 31
34 local param_k, param_v; 32 local param_k, param_v;
35 if value_params[param] then 33 if value_params[param] then
36 param_k, param_v = param, table.remove(arg, 1); 34 param_k, param_v = param, table.remove(arg, 1);
37 if not param_v then 35 if not param_v then
38 print("Expected a value to follow command-line option: "..raw_param); 36 return nil, "missing-value", raw_param;
39 os.exit(1);
40 end 37 end
41 else 38 else
42 param_k, param_v = param:match("^([^=]+)=(.+)$"); 39 param_k, param_v = param:match("^([^=]+)=(.+)$");
43 if not param_k then 40 if not param_k then
44 if param:match("^no%-") then 41 if param:match("^no%-") then