Allow printing the entire configuration (or parts of it) using, e.g. "pihole-FTL --config debug". Before, --config could only print exact config key matches
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
c672120123
commit
6623700e8d
|
@ -258,7 +258,9 @@ void parse_args(int argc, char* argv[])
|
|||
readFTLconf(&config, false);
|
||||
log_ctrl(false, true);
|
||||
clear_debug_flags(); // No debug printing wanted
|
||||
if(argc == 3)
|
||||
if(argc == 2)
|
||||
exit(get_config_from_CLI(NULL, false));
|
||||
else if(argc == 3)
|
||||
exit(get_config_from_CLI(argv[2], false));
|
||||
else if(argc == 4 && strcmp(argv[2], "-q") == 0)
|
||||
exit(get_config_from_CLI(argv[3], true));
|
||||
|
@ -266,7 +268,7 @@ void parse_args(int argc, char* argv[])
|
|||
exit(set_config_from_CLI(argv[2], argv[3]));
|
||||
else
|
||||
{
|
||||
printf("Usage: %s --config <config item key> [<value>]\n", argv[0]);
|
||||
printf("Usage: %s --config [<config item key>] [<value>]\n", argv[0]);
|
||||
printf("Example: %s --config dns.blockESNI true\n", argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
|
|
@ -443,7 +443,8 @@ int get_config_from_CLI(const char *key, const bool quiet)
|
|||
// Get pointer to memory location of this conf_item
|
||||
struct conf_item *item = get_conf_item(&config, i);
|
||||
|
||||
if(strcmp(item->k, key) != 0)
|
||||
// Check if item.k starts with key
|
||||
if(key != NULL && strncmp(item->k, key, strlen(key)) != 0)
|
||||
continue;
|
||||
|
||||
// Skip write-only options
|
||||
|
@ -452,11 +453,21 @@ int get_config_from_CLI(const char *key, const bool quiet)
|
|||
|
||||
// This is the config option we are looking for
|
||||
conf_item = item;
|
||||
break;
|
||||
|
||||
// Print key if this is not an exact match
|
||||
if(key == NULL || strcmp(item->k, key) != 0)
|
||||
printf("%s = ", item->k);
|
||||
|
||||
// Print value
|
||||
if(conf_item-> f & FLAG_WRITE_ONLY)
|
||||
puts("<write-only property>");
|
||||
else
|
||||
writeTOMLvalue(stdout, -1, conf_item->t, &conf_item->v);
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
// Check if we found the config option
|
||||
if(conf_item == NULL)
|
||||
if(key != NULL && conf_item == NULL)
|
||||
{
|
||||
log_err("Unknown config option: %s", key);
|
||||
return 2;
|
||||
|
@ -467,12 +478,5 @@ int get_config_from_CLI(const char *key, const bool quiet)
|
|||
if(quiet && conf_item->t == CONF_BOOL)
|
||||
return conf_item->v.b ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
|
||||
// Print value
|
||||
if(conf_item-> f & FLAG_WRITE_ONLY)
|
||||
puts("<write-only property>");
|
||||
else
|
||||
writeTOMLvalue(stdout, -1, conf_item->t, &conf_item->v);
|
||||
putchar('\n');
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue