MCPcopy Create free account
hub / github.com/ElementsProject/lightning / gather_cmdline_args

Function gather_cmdline_args

common/configdir.c:233–289  ·  view source on GitHub ↗

Now all options are known, we can turn cmdline into configvars */

Source from the content-addressed store, hash-verified

231
232/* Now all options are known, we can turn cmdline into configvars */
233static struct configvar **gather_cmdline_args(const tal_t *ctx,
234 int *argc, char **argv,
235 bool remove_args)
236{
237 struct configvar **cvs = tal_arr(ctx, struct configvar *, 0);
238
239 assert(argv[*argc] == NULL);
240 for (size_t i = 1; argv[i];) {
241 struct opt_table *ot;
242 const char *configline, *arg, *optarg;
243 enum configvar_src src;
244 bool extra_arg;
245
246 /* End of options? */
247 if (streq(argv[i], "--"))
248 break;
249
250 if (!strstarts(argv[i], "-")) {
251 i++;
252 continue;
253 }
254
255 if (strstarts(argv[i], "--")) {
256 arg = argv[i] + 2;
257 ot = opt_find_long(arg, &optarg);
258 src = CONFIGVAR_CMDLINE;
259 } else {
260 /* FIXME: We don't handle multiple short
261 * options here! */
262 arg = argv[i] + 1;
263 ot = opt_find_short(arg[0]);
264 optarg = NULL;
265 src = CONFIGVAR_CMDLINE_SHORT;
266 }
267 if (ot) {
268 extra_arg = (ot->type & OPT_HASARG) && !optarg;
269 } else {
270 /* Unknown (yet!). Guess if next arg is for this! */
271 extra_arg = ((src == CONFIGVAR_CMDLINE_SHORT
272 || !strchr(arg, '='))
273 && argv[i+1]
274 && !strstarts(argv[i+1], "-"));
275 }
276 finished_arg(argc, argv, &i, remove_args);
277 /* We turn `--foo bar` into `--foo=bar` here */
278 if (extra_arg) {
279 configline = tal_fmt(tmpctx, "%s=%s", arg, argv[i]);
280 finished_arg(argc, argv, &i, remove_args);
281 } else {
282 configline = arg;
283 }
284 tal_arr_expand(&cvs, configvar_new(cvs, src,
285 NULL, 0, configline));
286 }
287 assert(argv[*argc] == NULL);
288 return cvs;
289}
290

Callers 1

initial_config_optsFunction · 0.85

Calls 4

opt_find_longFunction · 0.85
opt_find_shortFunction · 0.85
finished_argFunction · 0.85
configvar_newFunction · 0.85

Tested by

no test coverage detected