+struct option_def options[] = {
+ // opt description arg name default value
+ {'c', "Load alternate configuration file", "config_file", CONFIG_DIR "/" CONFIG_FILENAME},
+ {'D', "Disable fork into background", NULL, NULL},
+ {'h', "Display help message", NULL, NULL},
+ {'P', "File to save a pid while running", "FILE", NULL},
+ {'p', "Port to listen. Can be from 1 to 65535.", "port_number", "19999"},
+ {'s', "Path to access host /proc and /sys when running in a container.", "PATH", NULL},
+ {'t', "The frequency in seconds, for data collection. \
+ Same as 'update every' config file option.", "seconds", "1"},
+ {'l', "The number of entries the netdata daemon will keep in memory \
+ for each chart dimension. Same as 'history config file option.", "lines_to_save", NULL},
+ {'u', "System username to run as.", "username", "netdata"},
+ {'v', "Version of the program", NULL, NULL},
+ {'W', "vendor options.", "stacksize=<size>|unittest|debug_flag", NULL},
+};
+
+void help(int exitcode) {
+ FILE *stream;
+ if(exitcode == 0)
+ stream = stdout;
+ else
+ stream = stderr;
+
+ int num_opts = sizeof(options) / sizeof(struct option_def);
+ int i;
+ int max_len_arg = 0;
+
+ // Compute maximum argument length
+ for( i = 0; i < num_opts; i++ ) {
+ if(options[i].arg_name) {
+ int len_arg = strlen(options[i].arg_name);
+ if(len_arg > max_len_arg) max_len_arg = len_arg;
+ }
+ }
+
+ fprintf(stream, "SYNOPSIS: netdata [options]\n");
+ fprintf(stream, "\n");
+ fprintf(stream, "Options:\n");
+
+ // Output options description.
+ for( i = 0; i < num_opts; i++ ) {
+ fprintf(stream, " -%c %-*s %s", options[i].val, max_len_arg, options[i].arg_name ? options[i].arg_name : "", options[i].description);
+ if(options[i].default_value) {
+ fprintf(stream, " Default: %s\n", options[i].default_value);
+ } else {
+ fprintf(stream, "\n");
+ }
+ }
+
+ fflush(stream);
+ exit(exitcode);
+}
+