// Define command line option
-#define SET_VERBOSE 1
+#define SET_VERBOSE 'v'
#define SET_BACKGROUND 2
#define SET_FORGROUND 3
+#define SET_QUIET 'q'
#define SET_TCP_PORT 5
#define SET_ROOT_DIR 6
#define SET_APITIMEOUT 14
#define SET_CNTXTIMEOUT 15
-#define DISPLAY_VERSION 16
-#define DISPLAY_HELP 17
+#define DISPLAY_VERSION 'V'
+#define DISPLAY_HELP 'h'
#define SET_MODE 18
#define SET_READYFD 19
#define SET_TRACEREQ 27
+#define SET_NO_HTTPD 28
+
+#define SET_EXEC 'e'
+
+#define SHORTOPTS "vqhVe"
+
// Command line structure hold cli --command + help text
typedef struct {
int val; // command number within application
static AFB_options cliOptions[] = {
/* *INDENT-OFF* */
{SET_VERBOSE, 0, "verbose", "Verbose Mode, repeat to increase verbosity"},
+ {SET_QUIET, 0, "quiet", "Quiet Mode, repeat to decrease verbosity"},
{SET_FORGROUND, 0, "foreground", "Get all in foreground mode"},
{SET_BACKGROUND, 0, "daemon", "Get all in background mode"},
{SET_SESSION_DIR, 1, "sessiondir", "Sessions file path [default rootdir/sessions]"},
- {SET_LDPATH, 1, "ldpaths", "Load bindingss from dir1:dir2:... [default = " BINDING_INSTALL_DIR "]"},
+ {SET_LDPATH, 1, "ldpaths", "Load bindings from dir1:dir2:... [default = " BINDING_INSTALL_DIR "]"},
{SET_AUTH_TOKEN, 1, "token", "Initial Secret [default=no-session, --token= for session without authentication]"},
{DISPLAY_VERSION, 0, "version", "Display version and copyright"},
{SET_TRACEREQ, 1, "tracereq", "Log the requests: no, common, extra, all"},
+ {SET_NO_HTTPD, 0, "no-httpd", "Forbids HTTP service"},
+ {SET_EXEC, 0, "exec", "Execute the remaining arguments"},
+
{0, 0, NULL, NULL}
/* *INDENT-ON* */
};
" Copyright (C) 2015, 2016, 2017 \"IoT.bzh\" [fulup -at- iot.bzh]\n");
fprintf(file, " AFB comes with ABSOLUTELY NO WARRANTY.\n");
fprintf(file, " Licence Apache 2\n\n");
- exit(0);
}
/*----------------------------------------------------------
// ------------------ Process Command Line -----------------------
- // if no argument print help and return
- if (argc < 2) {
- printHelp(stderr, programName);
- exit(1);
- }
// build GNU getopt info from cliOptions
nbcmd = sizeof(cliOptions) / sizeof(AFB_options);
gnuOptions = malloc(sizeof(*gnuOptions) * (unsigned)nbcmd);
}
// get all options from command line
- while ((optc = getopt_long(argc, argv, "", gnuOptions, &optionIndex)) != EOF) {
+ while ((optc = getopt_long(argc, argv, SHORTOPTS, gnuOptions, &optionIndex)) != EOF) {
switch (optc) {
case SET_VERBOSE:
verbosity++;
break;
+ case SET_QUIET:
+ verbosity--;
+ break;
+
case SET_TCP_PORT:
config->httpdPort = argvalintdec(optionIndex, 1024, 32767);
break;
config->tracereq = argvalenum(optionIndex, tracereq_desc);
break;
+ case SET_NO_HTTPD:
+ noarg(optionIndex);
+ config->noHttpd = 1;
+ break;
+
+ case SET_EXEC:
+ config->exec = &argv[optind];
+ optind = argc;
+ break;
+
case DISPLAY_VERSION:
noarg(optionIndex);
printVersion(stdout);
- break;
+ exit(0);
case DISPLAY_HELP:
printHelp(stdout, programName);
}
}
+void afb_config_dump(struct afb_config *config)
+{
+ struct afb_config_list *l;
+ struct enumdesc *e;
+ char **v;
+
+#define NN(x) (x)?:""
+#define P(...) fprintf(stderr, __VA_ARGS__)
+#define PF(x) P("-- %15s: ", #x)
+#define PE P("\n")
+#define S(x) PF(x);P("%s",NN(config->x));PE;
+#define D(x) PF(x);P("%d",config->x);PE;
+#define H(x) PF(x);P("%x",config->x);PE;
+#define B(x) PF(x);P("%s",config->x?"yes":"no");PE;
+#define L(x) PF(x);l=config->x;if(l){P("%s\n",NN(l->value));for(l=l->next;l;l=l->next)P("-- %15s %s\n","",NN(l->value));}else PE;
+#define E(x,d) for(e=d;e->name&&e->value!=config->x;e++);if(e->name){PF(x);P("%s",e->name);PE;}else{D(x);}
+#define V(x) P("-- %15s:", #x);for(v=config->x;v&&*v;v++)P(" %s",*v); PE;
+
+ P("---BEGIN-OF-CONFIG---\n");
+ S(console)
+ S(rootdir)
+ S(roothttp)
+ S(rootbase)
+ S(rootapi)
+ S(sessiondir)
+ S(token)
+
+ L(aliases)
+ L(dbus_clients)
+ L(dbus_servers)
+ L(ws_clients)
+ L(ws_servers)
+ L(so_bindings)
+ L(ldpaths)
+
+ V(exec)
+
+ D(httpdPort)
+ B(background)
+ D(readyfd)
+ D(cacheTimeout)
+ D(apiTimeout)
+ D(cntxTimeout)
+ D(nbSessionMax)
+ E(mode,mode_desc)
+ E(tracereq,tracereq_desc)
+ B(noHttpd)
+ P("---END-OF-CONFIG---\n");
+
+#undef V
+#undef E
+#undef L
+#undef B
+#undef H
+#undef D
+#undef S
+#undef PE
+#undef PF
+#undef P
+#undef NN
+}
+
struct afb_config *afb_config_parse_arguments(int argc, char **argv)
{
struct afb_config *result;
parse_arguments(argc, argv, result);
config_set_default(result);
+ if (verbosity >= 3)
+ afb_config_dump(result);
return result;
}
+