From 4efc8fb9ced2f0485cf09d637b2e5813f0d5a6f3 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Wed, 16 Aug 2017 13:24:14 +0900 Subject: [PATCH] Add placeholder functions for "repmgr $command --help" There are now too many options to sensibly fit into general --help output; we'll add separate output for each repmgr command, e.g. "repmgr node --help". --- repmgr-action-bdr.c | 9 ++++ repmgr-action-bdr.h | 2 + repmgr-action-cluster.c | 9 ++++ repmgr-action-cluster.h | 1 + repmgr-action-node.c | 13 +++-- repmgr-action-node.h | 2 +- repmgr-action-primary.c | 10 ++++ repmgr-action-primary.h | 1 + repmgr-action-standby.c | 9 ++++ repmgr-action-standby.h | 2 + repmgr-client-global.h | 1 + repmgr-client.c | 105 +++++++++++++++++++++++++++++----------- 12 files changed, 131 insertions(+), 33 deletions(-) diff --git a/repmgr-action-bdr.c b/repmgr-action-bdr.c index a318542f..77164b8b 100644 --- a/repmgr-action-bdr.c +++ b/repmgr-action-bdr.c @@ -414,3 +414,12 @@ do_bdr_unregister(void) return; } + + +void +do_bdr_help(void) +{ + print_help_header(); + + +} diff --git a/repmgr-action-bdr.h b/repmgr-action-bdr.h index e8c91135..83119df1 100644 --- a/repmgr-action-bdr.h +++ b/repmgr-action-bdr.h @@ -9,5 +9,7 @@ extern void do_bdr_register(void); extern void do_bdr_unregister(void); +extern void do_bdr_help(void); + #endif /* _REPMGR_ACTION_BDR_H_ */ diff --git a/repmgr-action-cluster.c b/repmgr-action-cluster.c index dbe6691a..9991716b 100644 --- a/repmgr-action-cluster.c +++ b/repmgr-action-cluster.c @@ -1083,3 +1083,12 @@ cube_set_node_status(t_node_status_cube **cube, int n, int execute_node_id, int } } } + + +void +do_cluster_help(void) +{ + print_help_header(); + + +} diff --git a/repmgr-action-cluster.h b/repmgr-action-cluster.h index 90934182..8aa2f467 100644 --- a/repmgr-action-cluster.h +++ b/repmgr-action-cluster.h @@ -35,5 +35,6 @@ extern void do_cluster_event(void); extern void do_cluster_crosscheck(void); extern void do_cluster_matrix(void); +extern void do_cluster_help(void); #endif diff --git a/repmgr-action-node.c b/repmgr-action-node.c index 0e8f802f..27be99d1 100644 --- a/repmgr-action-node.c +++ b/repmgr-action-node.c @@ -1249,11 +1249,7 @@ do_node_check_downstream(PGconn *conn, OutputMode mode, CheckStatusList *list_ou return status; } -// --action=... -// --check -// --list -> list what would be executed for each action, filter to --action -// --checkpoint must be run as superuser - check connection void do_node_service(void) { @@ -1967,3 +1963,12 @@ copy_file(const char *src_file, const char *dest_file) return true; } + + +void +do_node_help(void) +{ + print_help_header(); + + +} diff --git a/repmgr-action-node.h b/repmgr-action-node.h index 2cb874d1..067cc998 100644 --- a/repmgr-action-node.h +++ b/repmgr-action-node.h @@ -13,6 +13,6 @@ extern void do_node_check(void); extern void do_node_rejoin(void); extern void do_node_service(void); - +extern void do_node_help(void); #endif /* _REPMGR_ACTION_NODE_H_ */ diff --git a/repmgr-action-primary.c b/repmgr-action-primary.c index e5482380..01b2ddbe 100644 --- a/repmgr-action-primary.c +++ b/repmgr-action-primary.c @@ -489,3 +489,13 @@ do_primary_unregister(void) PQfinish(primary_conn); return; } + + + +void +do_primary_help(void) +{ + print_help_header(); + + +} diff --git a/repmgr-action-primary.h b/repmgr-action-primary.h index badc9973..d043afe9 100644 --- a/repmgr-action-primary.h +++ b/repmgr-action-primary.h @@ -9,4 +9,5 @@ extern void do_primary_register(void); extern void do_primary_unregister(void); +extern void do_primary_help(void); #endif diff --git a/repmgr-action-standby.c b/repmgr-action-standby.c index dcaadaa2..1e440468 100644 --- a/repmgr-action-standby.c +++ b/repmgr-action-standby.c @@ -4065,3 +4065,12 @@ parse_node_check_replication_lag(const char *node_check_output, int *seconds, in return status; } + + +void +do_standby_help(void) +{ + print_help_header(); + + +} diff --git a/repmgr-action-standby.h b/repmgr-action-standby.h index 5344738f..3c04dd7c 100644 --- a/repmgr-action-standby.h +++ b/repmgr-action-standby.h @@ -13,6 +13,8 @@ extern void do_standby_promote(void); extern void do_standby_follow(void); extern void do_standby_switchover(void); +extern void do_standby_help(void); + extern bool do_standby_follow_internal(PGconn *primary_conn, t_node_info *primary_node_record, PQExpBufferData *output); diff --git a/repmgr-client-global.h b/repmgr-client-global.h index bcb51b8f..8c8957f3 100644 --- a/repmgr-client-global.h +++ b/repmgr-client-global.h @@ -197,6 +197,7 @@ extern void get_superuser_connection(PGconn **conn, PGconn **superuser_conn, PGc extern bool remote_command(const char *host, const char *user, const char *command, PQExpBufferData *outputbuf); extern void make_remote_repmgr_path(PQExpBufferData *outputbuf, t_node_info *remote_node_record); +extern void print_help_header(void); /* server control functions */ extern void get_server_action(t_server_action action, char *script, char *data_dir); diff --git a/repmgr-client.c b/repmgr-client.c index b536f25f..98fb16de 100644 --- a/repmgr-client.c +++ b/repmgr-client.c @@ -84,12 +84,14 @@ main(int argc, char **argv) int optindex; int c; - char *repmgr_node_type = NULL; + char *repmgr_command = NULL; char *repmgr_action = NULL; - bool valid_repmgr_node_type_found = true; + bool valid_repmgr_command_found = true; int action = NO_ACTION; char *dummy_action = ""; + bool help_option = false; + set_progname(argv[0]); /* @@ -173,8 +175,10 @@ main(int argc, char **argv) * these are the only ones which can be executed as root user */ case OPT_HELP: /* --help */ - do_help(); - exit(SUCCESS); + help_option = true; + break; + //do_help(); + //exit(SUCCESS); case '?': /* Actual help option given */ if (strcmp(argv[optind - 1], "-?") == 0) @@ -646,7 +650,7 @@ main(int argc, char **argv) * We check this here to give the root user a chance to execute --help/--version * options. */ - if (geteuid() == 0) + if (geteuid() == 0 && help_option == false) { fprintf(stderr, _("%s: cannot be run as root\n" @@ -679,7 +683,7 @@ main(int argc, char **argv) */ if (optind < argc) { - repmgr_node_type = argv[optind++]; + repmgr_command = argv[optind++]; } if (optind < argc) @@ -691,11 +695,17 @@ main(int argc, char **argv) repmgr_action = dummy_action; } - if (repmgr_node_type != NULL) + if (repmgr_command != NULL) { #ifndef BDR_ONLY - if (strcasecmp(repmgr_node_type, "PRIMARY") == 0 || strcasecmp(repmgr_node_type, "MASTER") == 0 ) + if (strcasecmp(repmgr_command, "PRIMARY") == 0 || strcasecmp(repmgr_command, "MASTER") == 0 ) { + if (help_option == true) + { + do_primary_help(); + exit(SUCCESS); + } + if (strcasecmp(repmgr_action, "REGISTER") == 0) action = PRIMARY_REGISTER; else if (strcasecmp(repmgr_action, "UNREGISTER") == 0) @@ -706,8 +716,14 @@ main(int argc, char **argv) action = NODE_STATUS; } - else if (strcasecmp(repmgr_node_type, "STANDBY") == 0) + else if (strcasecmp(repmgr_command, "STANDBY") == 0) { + if (help_option == true) + { + do_standby_help(); + exit(SUCCESS); + } + if (strcasecmp(repmgr_action, "CLONE") == 0) action = STANDBY_CLONE; else if (strcasecmp(repmgr_action, "REGISTER") == 0) @@ -725,11 +741,17 @@ main(int argc, char **argv) else if (strcasecmp(repmgr_action, "STATUS") == 0) action = NODE_STATUS; } - else if (strcasecmp(repmgr_node_type, "BDR") == 0) + else if (strcasecmp(repmgr_command, "BDR") == 0) #else - if (strcasecmp(repmgr_node_type, "BDR") == 0) + if (strcasecmp(repmgr_command, "BDR") == 0) #endif { + if (help_option == true) + { + do_bdr_help(); + exit(SUCCESS); + } + if (strcasecmp(repmgr_action, "REGISTER") == 0) action = BDR_REGISTER; else if (strcasecmp(repmgr_action, "UNREGISTER") == 0) @@ -740,8 +762,14 @@ main(int argc, char **argv) action = NODE_STATUS; } - else if (strcasecmp(repmgr_node_type, "NODE") == 0) + else if (strcasecmp(repmgr_command, "NODE") == 0) { + if (help_option == true) + { + do_node_help(); + exit(SUCCESS); + } + if (strcasecmp(repmgr_action, "CHECK") == 0) action = NODE_CHECK; else if (strcasecmp(repmgr_action, "STATUS") == 0) @@ -752,8 +780,13 @@ main(int argc, char **argv) action = NODE_SERVICE; } - else if (strcasecmp(repmgr_node_type, "CLUSTER") == 0) + else if (strcasecmp(repmgr_command, "CLUSTER") == 0) { + if (help_option == true) + { + do_cluster_help(); + exit(SUCCESS); + } if (strcasecmp(repmgr_action, "SHOW") == 0) action = CLUSTER_SHOW; @@ -769,37 +802,43 @@ main(int argc, char **argv) } else { - valid_repmgr_node_type_found = false; + valid_repmgr_command_found = false; } } + if (help_option == true) + { + do_help(); + exit(SUCCESS); + } + if (action == NO_ACTION) { PQExpBufferData command_error; initPQExpBuffer(&command_error); - if (repmgr_node_type == NULL) + if (repmgr_command == NULL) { appendPQExpBuffer(&command_error, _("no repmgr command provided")); } - else if (valid_repmgr_node_type_found == false && repmgr_action[0] == '\0') + else if (valid_repmgr_command_found == false && repmgr_action[0] == '\0') { appendPQExpBuffer(&command_error, - _("unknown repmgr node type '%s'"), - repmgr_node_type); + _("unknown repmgr command '%s'"), + repmgr_command); } else if (repmgr_action[0] == '\0') { appendPQExpBuffer(&command_error, - _("no action provided for node type '%s'"), - repmgr_node_type); + _("no action provided for command '%s'"), + repmgr_command); } else { appendPQExpBuffer(&command_error, _("unknown repmgr action '%s %s'"), - repmgr_node_type, + repmgr_command, repmgr_action); } @@ -1565,8 +1604,8 @@ print_error_list(ItemList *error_list, int log_level) } -static void -do_help(void) +void +print_help_header(void) { printf(_("%s: replication management tool for PostgreSQL\n"), progname()); puts(""); @@ -1579,15 +1618,25 @@ do_help(void) printf(_(" **************************************************\n")); puts(""); } +} + +static void +do_help(void) +{ + print_help_header(); printf(_("Usage:\n")); #ifndef BDR_ONLY - printf(_(" %s [OPTIONS] primary {register|unregister}\n"), progname()); - printf(_(" %s [OPTIONS] standby {register|unregister|clone|promote|follow}\n"), progname()); + printf(_(" %s [OPTIONS] primary {register|unregister}\n"), progname()); + printf(_(" %s [OPTIONS] standby {register|unregister|clone|promote|follow}\n"), progname()); #endif - printf(_(" %s [OPTIONS] bdr {register|unregister}\n"), progname()); - printf(_(" %s [OPTIONS] node status\n"), progname()); - printf(_(" %s [OPTIONS] cluster {show|event|matrix|crosscheck}\n"), progname()); + printf(_(" %s [OPTIONS] bdr {register|unregister}\n"), progname()); + printf(_(" %s [OPTIONS] node status\n"), progname()); + printf(_(" %s [OPTIONS] cluster {show|event|matrix|crosscheck}\n"), progname()); + + puts(""); + + printf(_(" Execute \"%s {primary|standby|bdr|node|cluster} --help\" to see command-specific options\n"), progname()); puts("");