diff --git a/dunst.c b/dunst.c index 50c62f8..c89874f 100644 --- a/dunst.c +++ b/dunst.c @@ -1469,7 +1469,7 @@ void load_options(char *cmdline_config_path) close_all_ks.str = option_get_string("shortcuts", "close_all", "-all_key", close_all_ks.str); history_ks.str = option_get_string("shortcuts", "history", "-history_key", history_ks.str); - print_notifications = cmdline_get_bool("print", False); + print_notifications = cmdline_get_bool("-print", False); char *cur_section = NULL; for (;;) { @@ -1535,9 +1535,6 @@ int main(int argc, char *argv[]) cmdline_load(argc, argv); - if (cmdline_get_bool("-h/-help", False) || cmdline_get_bool("--help", False)) { - usage(EXIT_SUCCESS); - } if (cmdline_get_bool("-v/-version", False) || cmdline_get_bool("--version", False)) { print_version(); @@ -1550,6 +1547,11 @@ int main(int argc, char *argv[]) cmdline_config_path = NULL; #endif load_options(cmdline_config_path); + + if (cmdline_get_bool("-h/-help", False) || cmdline_get_bool("--help", False)) { + usage(EXIT_SUCCESS); + } + dc = initdc(); init_shortcut(&close_ks); @@ -1602,9 +1604,10 @@ int main(int argc, char *argv[]) void usage(int exit_status) { - fputs - ("usage: dunst [-h/--help] [-v] [-geometry geom] [-lh height] [-fn font] [-format fmt]\n[-nb color] [-nf color] [-lb color] [-lf color] [-cb color] [ -cf color]\n[-to secs] [-lto secs] [-cto secs] [-nto secs] [-key key] [-history_key key] [-all_key key] [-mon n] [-follow none/mouse/keyboard] [-config dunstrc]\n", - stderr); + fputs("usage:\n", stderr); + char *us = cmdline_create_usage(); + fputs(us, stderr); + fputs("\n", stderr); exit(exit_status); } diff --git a/options.c b/options.c index f94a47b..1325a1f 100644 --- a/options.c +++ b/options.c @@ -1,4 +1,6 @@ /* copyright 2012 Sascha Kruse and contributors (see LICENSE for licensing information) */ +#define _GNU_SOURCE + #include #include #include @@ -35,6 +37,9 @@ static char *clean_value(char *value); static int cmdline_argc; static char **cmdline_argv; +static char *usage_str = NULL; +static void cmdline_usage_append(char *key, char *type); + static int cmdline_find_option(char *key); section_t *new_section(char *name) @@ -304,6 +309,7 @@ int cmdline_find_option(char *key) char *cmdline_get_string(char *key, char *def) { + cmdline_usage_append(key, "string"); int idx = cmdline_find_option(key); if (idx < 0) { return def; @@ -320,6 +326,7 @@ char *cmdline_get_string(char *key, char *def) int cmdline_get_int(char *key, int def) { + cmdline_usage_append(key, "double"); char *str = cmdline_get_string(key, NULL); if (str == NULL) return def; @@ -329,6 +336,7 @@ int cmdline_get_int(char *key, int def) double cmdline_get_double(char *key, double def) { + cmdline_usage_append(key, "double"); char *str = cmdline_get_string(key, NULL); if (str == NULL) return def; @@ -338,6 +346,7 @@ double cmdline_get_double(char *key, double def) int cmdline_get_bool(char *key, int def) { + cmdline_usage_append(key, ""); int idx = cmdline_find_option(key); if (idx > 0) return true; @@ -413,4 +422,32 @@ int option_get_bool(char *ini_section, char *ini_key, char *cmdline_key, int def return ini_get_bool(ini_section, ini_key, def); } +void cmdline_usage_append(char *key, char *type) +{ + static int add_linebreak = 2; + + + if (!usage_str) { + asprintf(&usage_str, "[%s %s]", key, type); + return; + } + + char *tmp; + add_linebreak--; + if (add_linebreak == 0) { + asprintf(&tmp, "%s[%s %s]\n", usage_str, key, type); + add_linebreak = 3; + } else { + asprintf(&tmp, "%s[%s %s] ", usage_str, key, type); + } + + free(usage_str); + usage_str = tmp; + +} + +char *cmdline_create_usage(void) +{ + return strdup(usage_str); +} /* vim: set ts=8 sw=8 tw=0: */ diff --git a/options.h b/options.h index 6337744..76a04ba 100644 --- a/options.h +++ b/options.h @@ -17,6 +17,7 @@ char *cmdline_get_string(char *key, char *def); int cmdline_get_int(char *key, int def); double cmdline_get_double(char *key, double def); int cmdline_get_bool(char *key, int def); +char *cmdline_create_usage(void); char *option_get_string(char *ini_section, char *ini_key, char *cmdline_key, char *def); int option_get_int(char *ini_section, char *ini_key, char *cmdline_key, int def);