Suppress configuration file warnings if --terse is set

This commit is contained in:
Ian Barwick
2017-04-26 10:50:43 +09:00
parent 1b785d9a20
commit 2ed5393209
3 changed files with 13 additions and 10 deletions

View File

@@ -22,7 +22,7 @@ static void tablespace_list_append(t_configuration_options *options, const char
static char *trim(char *s); static char *trim(char *s);
static void exit_with_errors(ItemList *config_errors, ItemList *config_warnings); static void exit_with_errors(ItemList *config_errors, ItemList *config_warnings, bool terse);
void void
@@ -38,7 +38,7 @@ progname(void)
} }
bool bool
load_config(const char *config_file, bool verbose, t_configuration_options *options, char *argv0) load_config(const char *config_file, bool verbose, bool terse, t_configuration_options *options, char *argv0)
{ {
struct stat stat_config; struct stat stat_config;
@@ -156,12 +156,12 @@ load_config(const char *config_file, bool verbose, t_configuration_options *opti
} }
} }
return parse_config(options); return parse_config(options, terse);
} }
bool bool
parse_config(t_configuration_options *options) parse_config(t_configuration_options *options, bool terse)
{ {
/* Collate configuration file errors here for friendlier reporting */ /* Collate configuration file errors here for friendlier reporting */
static ItemList config_errors = { NULL, NULL }; static ItemList config_errors = { NULL, NULL };
@@ -172,10 +172,10 @@ parse_config(t_configuration_options *options)
/* errors found - exit after printing details, and any warnings */ /* errors found - exit after printing details, and any warnings */
if (config_errors.head != NULL) if (config_errors.head != NULL)
{ {
exit_with_errors(&config_errors, &config_warnings); exit_with_errors(&config_errors, &config_warnings, terse);
} }
if (config_warnings.head != NULL) if (terse == false && config_warnings.head != NULL)
{ {
ItemListCell *cell; ItemListCell *cell;
@@ -633,10 +633,11 @@ reload_config(t_configuration_options *orig_options)
/* TODO: don't emit warnings if --terse and no errors */ /* TODO: don't emit warnings if --terse and no errors */
static void static void
exit_with_errors(ItemList *config_errors, ItemList *config_warnings) exit_with_errors(ItemList *config_errors, ItemList *config_warnings, bool terse)
{ {
ItemListCell *cell; ItemListCell *cell;
log_error(_("following errors were found in the configuration file:")); log_error(_("following errors were found in the configuration file:"));
for (cell = config_errors->head; cell; cell = cell->next) for (cell = config_errors->head; cell; cell = cell->next)
@@ -644,7 +645,7 @@ exit_with_errors(ItemList *config_errors, ItemList *config_warnings)
fprintf(stderr, " %s\n", cell->string); fprintf(stderr, " %s\n", cell->string);
} }
if (config_warnings->head != NULL) if (terse == false && config_warnings->head != NULL)
{ {
puts(""); puts("");
log_warning(_("the following problems were also found in the configuration file:")); log_warning(_("the following problems were also found in the configuration file:"));
@@ -653,6 +654,7 @@ exit_with_errors(ItemList *config_errors, ItemList *config_warnings)
fprintf(stderr, " %s\n", cell->string); fprintf(stderr, " %s\n", cell->string);
} }
} }
exit(ERR_BAD_CONFIG); exit(ERR_BAD_CONFIG);
} }

View File

@@ -129,8 +129,8 @@ typedef struct
void set_progname(const char *argv0); void set_progname(const char *argv0);
const char *progname(void); const char *progname(void);
bool load_config(const char *config_file, bool verbose, t_configuration_options *options, char *argv0); bool load_config(const char *config_file, bool verbose, bool terse, t_configuration_options *options, char *argv0);
bool parse_config(t_configuration_options *options); bool parse_config(t_configuration_options *options, bool terse);
bool reload_config(t_configuration_options *orig_options); bool reload_config(t_configuration_options *orig_options);

View File

@@ -325,6 +325,7 @@ main(int argc, char **argv)
*/ */
config_file_parsed = load_config(runtime_options.config_file, config_file_parsed = load_config(runtime_options.config_file,
runtime_options.verbose, runtime_options.verbose,
runtime_options.terse,
&config_file_options, &config_file_options,
argv[0]); argv[0]);