mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-24 07:36:30 +00:00
repmgr: improve handling of command line parameter errors
Previously providing a parameter which requires a value (e.g. -f/--config-file) would result in a misleading error like "Unknown option -f". Rather than suppress getopt's error messages, we'll rely on these to inform about missing required values or unknown options (as other PostgreSQL tools do), though we will still provide our own list of command line errors and warnings countered above and beyond getopt's sanity checks.
This commit is contained in:
5
HISTORY
5
HISTORY
@@ -1,5 +1,8 @@
|
|||||||
3.2.2 2016-
|
3.2.2 2016-12-
|
||||||
repmgr: always log to STDERR even if log facility defined (Ian)
|
repmgr: always log to STDERR even if log facility defined (Ian)
|
||||||
|
repmgr: add --log-to-file to log repmgr output to the defined
|
||||||
|
log facility (Ian)
|
||||||
|
repmgr: improve handling of command line parameter errors (Ian)
|
||||||
|
|
||||||
3.2.1 2016-10-24
|
3.2.1 2016-10-24
|
||||||
repmgr: require a valid repmgr cluster name unless -F/--force
|
repmgr: require a valid repmgr cluster name unless -F/--force
|
||||||
|
|||||||
32
repmgr.c
32
repmgr.c
@@ -333,9 +333,6 @@ main(int argc, char **argv)
|
|||||||
strncpy(runtime_options.dbname, runtime_options.username, MAXLEN);
|
strncpy(runtime_options.dbname, runtime_options.username, MAXLEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Prevent getopt_long() from printing an error message */
|
|
||||||
opterr = 0;
|
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, "?Vd:h:p:U:S:D:f:R:w:k:FWIvb:rcL:tm:C:l:", long_options,
|
while ((c = getopt_long(argc, argv, "?Vd:h:p:U:S:D:f:R:w:k:FWIvb:rcL:tm:C:l:", long_options,
|
||||||
&optindex)) != -1)
|
&optindex)) != -1)
|
||||||
{
|
{
|
||||||
@@ -347,17 +344,6 @@ main(int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
case '?':
|
|
||||||
/* Actual help option given */
|
|
||||||
if (strcmp(argv[optind - 1], "-?") == 0)
|
|
||||||
{
|
|
||||||
do_help();
|
|
||||||
exit(SUCCESS);
|
|
||||||
}
|
|
||||||
/* unknown option reported by getopt */
|
|
||||||
else
|
|
||||||
goto unknown_option;
|
|
||||||
break;
|
|
||||||
case OPT_HELP:
|
case OPT_HELP:
|
||||||
do_help();
|
do_help();
|
||||||
exit(SUCCESS);
|
exit(SUCCESS);
|
||||||
@@ -567,16 +553,14 @@ main(int argc, char **argv)
|
|||||||
case OPT_IGNORE_EXTERNAL_CONFIG_FILES:
|
case OPT_IGNORE_EXTERNAL_CONFIG_FILES:
|
||||||
item_list_append(&cli_warnings, _("--ignore-external-config-files is deprecated and has no effect; use --copy-external-config-file instead"));
|
item_list_append(&cli_warnings, _("--ignore-external-config-files is deprecated and has no effect; use --copy-external-config-file instead"));
|
||||||
break;
|
break;
|
||||||
|
case '?':
|
||||||
default:
|
/* Actual help option given */
|
||||||
unknown_option:
|
if (strcmp(argv[optind - 1], "-?") == 0)
|
||||||
{
|
{
|
||||||
PQExpBufferData unknown_option;
|
do_help();
|
||||||
initPQExpBuffer(&unknown_option);
|
exit(SUCCESS);
|
||||||
appendPQExpBuffer(&unknown_option, _("Unknown option '%s'"), argv[optind - 1]);
|
}
|
||||||
|
break;
|
||||||
item_list_append(&cli_errors, unknown_option.data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user