lnvis

nanovg lightning network visualizer
git clone git://jb55.com/lnvis
Log | Files | Refs | README | LICENSE

options.c (1206B)


      1 
      2 #include "options.h"
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 #include "commander/commander.h"
      6 
      7 static void opt_channels(command_t *self) {
      8 	struct options *options = self->data;
      9 	options->channels = self->arg;
     10 };
     11 
     12 static void opt_nodes(command_t *self) {
     13 	struct options *options = self->data;
     14 	options->nodes = self->arg;
     15 };
     16 
     17 static void opt_filter(command_t *self) {
     18 	struct options *options = self->data;
     19 	options->filter = self->arg;
     20 };
     21 
     22 static void fail(int code, const char *msg)
     23 {
     24 	fprintf(stderr, "%s\n", msg);
     25 	exit(code);
     26 }
     27 
     28 void parse_options(int argc, const char *argv[], struct options *options)
     29 {
     30 	command_t cmd;
     31 	options->channels = NULL;
     32 	options->nodes = NULL;
     33 	options->filter = NULL;
     34 
     35 	cmd.data = (void*)options;
     36 
     37 	command_init(&cmd, argv[0], "0.1");
     38 	cmd.usage = "--channels channels.json --nodes nodes.json [options]";
     39 
     40 	command_option(&cmd, "-c", "--channels <path>", "channels json", opt_channels);
     41 	command_option(&cmd, "-n", "--nodes <path>", "nodes json", opt_nodes);
     42 	command_option(&cmd, "-f", "--filter <nodeid>", "nodeid to filter on", opt_filter);
     43 
     44 	command_parse(&cmd, argc, (char **)argv);
     45 
     46 	if (options->channels == NULL || options->nodes == NULL)
     47 		command_help(&cmd);
     48 }