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

Function gather_cmdline_args

common/configdir.c:240–296  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

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