autocreate usage
This commit is contained in:
parent
c192b962e5
commit
65d07c4f96
17
dunst.c
17
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);
|
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);
|
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;
|
char *cur_section = NULL;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -1535,9 +1535,6 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
cmdline_load(argc, 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)) {
|
if (cmdline_get_bool("-v/-version", False) || cmdline_get_bool("--version", False)) {
|
||||||
print_version();
|
print_version();
|
||||||
@ -1550,6 +1547,11 @@ int main(int argc, char *argv[])
|
|||||||
cmdline_config_path = NULL;
|
cmdline_config_path = NULL;
|
||||||
#endif
|
#endif
|
||||||
load_options(cmdline_config_path);
|
load_options(cmdline_config_path);
|
||||||
|
|
||||||
|
if (cmdline_get_bool("-h/-help", False) || cmdline_get_bool("--help", False)) {
|
||||||
|
usage(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
dc = initdc();
|
dc = initdc();
|
||||||
|
|
||||||
init_shortcut(&close_ks);
|
init_shortcut(&close_ks);
|
||||||
@ -1602,9 +1604,10 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
void usage(int exit_status)
|
void usage(int exit_status)
|
||||||
{
|
{
|
||||||
fputs
|
fputs("usage:\n", stderr);
|
||||||
("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",
|
char *us = cmdline_create_usage();
|
||||||
stderr);
|
fputs(us, stderr);
|
||||||
|
fputs("\n", stderr);
|
||||||
exit(exit_status);
|
exit(exit_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
37
options.c
37
options.c
@ -1,4 +1,6 @@
|
|||||||
/* copyright 2012 Sascha Kruse and contributors (see LICENSE for licensing information) */
|
/* copyright 2012 Sascha Kruse and contributors (see LICENSE for licensing information) */
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -35,6 +37,9 @@ static char *clean_value(char *value);
|
|||||||
static int cmdline_argc;
|
static int cmdline_argc;
|
||||||
static char **cmdline_argv;
|
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);
|
static int cmdline_find_option(char *key);
|
||||||
|
|
||||||
section_t *new_section(char *name)
|
section_t *new_section(char *name)
|
||||||
@ -304,6 +309,7 @@ int cmdline_find_option(char *key)
|
|||||||
|
|
||||||
char *cmdline_get_string(char *key, char *def)
|
char *cmdline_get_string(char *key, char *def)
|
||||||
{
|
{
|
||||||
|
cmdline_usage_append(key, "string");
|
||||||
int idx = cmdline_find_option(key);
|
int idx = cmdline_find_option(key);
|
||||||
if (idx < 0) {
|
if (idx < 0) {
|
||||||
return def;
|
return def;
|
||||||
@ -320,6 +326,7 @@ char *cmdline_get_string(char *key, char *def)
|
|||||||
|
|
||||||
int cmdline_get_int(char *key, int def)
|
int cmdline_get_int(char *key, int def)
|
||||||
{
|
{
|
||||||
|
cmdline_usage_append(key, "double");
|
||||||
char *str = cmdline_get_string(key, NULL);
|
char *str = cmdline_get_string(key, NULL);
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return def;
|
return def;
|
||||||
@ -329,6 +336,7 @@ int cmdline_get_int(char *key, int def)
|
|||||||
|
|
||||||
double cmdline_get_double(char *key, double def)
|
double cmdline_get_double(char *key, double def)
|
||||||
{
|
{
|
||||||
|
cmdline_usage_append(key, "double");
|
||||||
char *str = cmdline_get_string(key, NULL);
|
char *str = cmdline_get_string(key, NULL);
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return def;
|
return def;
|
||||||
@ -338,6 +346,7 @@ double cmdline_get_double(char *key, double def)
|
|||||||
|
|
||||||
int cmdline_get_bool(char *key, int def)
|
int cmdline_get_bool(char *key, int def)
|
||||||
{
|
{
|
||||||
|
cmdline_usage_append(key, "");
|
||||||
int idx = cmdline_find_option(key);
|
int idx = cmdline_find_option(key);
|
||||||
if (idx > 0)
|
if (idx > 0)
|
||||||
return true;
|
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);
|
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: */
|
/* vim: set ts=8 sw=8 tw=0: */
|
||||||
|
@ -17,6 +17,7 @@ char *cmdline_get_string(char *key, char *def);
|
|||||||
int cmdline_get_int(char *key, int def);
|
int cmdline_get_int(char *key, int def);
|
||||||
double cmdline_get_double(char *key, double def);
|
double cmdline_get_double(char *key, double def);
|
||||||
int cmdline_get_bool(char *key, int 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);
|
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);
|
int option_get_int(char *ini_section, char *ini_key, char *cmdline_key, int def);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user