Skip to content

remove backup_subcmd global variable and useless command_name variable #291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 75 additions & 44 deletions src/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
*-------------------------------------------------------------------------
*/

#include <assert.h>
#include "pg_probackup.h"

static void help_nocmd(void);
static void help_internal(void);
static void help_init(void);
static void help_backup(void);
static void help_restore(void);
Expand All @@ -24,58 +27,61 @@ static void help_del_instance(void);
static void help_archive_push(void);
static void help_archive_get(void);
static void help_checkdb(void);
static void help_help(void);
static void help_version(void);

void
help_command(char *command)
help_print_version(void)
{
if (strcmp(command, "init") == 0)
help_init();
else if (strcmp(command, "backup") == 0)
help_backup();
else if (strcmp(command, "restore") == 0)
help_restore();
else if (strcmp(command, "validate") == 0)
help_validate();
else if (strcmp(command, "show") == 0)
help_show();
else if (strcmp(command, "delete") == 0)
help_delete();
else if (strcmp(command, "merge") == 0)
help_merge();
else if (strcmp(command, "set-backup") == 0)
help_set_backup();
else if (strcmp(command, "set-config") == 0)
help_set_config();
else if (strcmp(command, "show-config") == 0)
help_show_config();
else if (strcmp(command, "add-instance") == 0)
help_add_instance();
else if (strcmp(command, "del-instance") == 0)
help_del_instance();
else if (strcmp(command, "archive-push") == 0)
help_archive_push();
else if (strcmp(command, "archive-get") == 0)
help_archive_get();
else if (strcmp(command, "checkdb") == 0)
help_checkdb();
else if (strcmp(command, "--help") == 0
|| strcmp(command, "help") == 0
|| strcmp(command, "-?") == 0
|| strcmp(command, "--version") == 0
|| strcmp(command, "version") == 0
|| strcmp(command, "-V") == 0)
printf(_("No help page for \"%s\" command. Try pg_probackup help\n"), command);
else
printf(_("Unknown command \"%s\". Try pg_probackup help\n"), command);
exit(0);
#ifdef PGPRO_VERSION
fprintf(stdout, "%s %s (Postgres Pro %s %s)\n",
PROGRAM_NAME, PROGRAM_VERSION,
PGPRO_VERSION, PGPRO_EDITION);
#else
fprintf(stdout, "%s %s (PostgreSQL %s)\n",
PROGRAM_NAME, PROGRAM_VERSION, PG_VERSION);
#endif
}

void
help_command(ProbackupSubcmd const subcmd)
{
typedef void (* help_function_ptr)(void);
/* Order is important, keep it in sync with utils/configuration.h:enum ProbackupSubcmd declaration */
static help_function_ptr const help_functions[] =
{
&help_nocmd,
&help_init,
&help_add_instance,
&help_del_instance,
&help_archive_push,
&help_archive_get,
&help_backup,
&help_restore,
&help_validate,
&help_delete,
&help_merge,
&help_show,
&help_set_config,
&help_set_backup,
&help_show_config,
&help_checkdb,
&help_internal, // SSH_CMD
&help_internal, // AGENT_CMD
&help_help,
&help_version,
};

Assert((int)subcmd < sizeof(help_functions) / sizeof(help_functions[0]));
help_functions[(int)subcmd]();
}

void
help_pg_probackup(void)
{
printf(_("\n%s - utility to manage backup/recovery of PostgreSQL database.\n\n"), PROGRAM_NAME);
printf(_("\n%s - utility to manage backup/recovery of PostgreSQL database.\n"), PROGRAM_NAME);

printf(_(" %s help [COMMAND]\n"), PROGRAM_NAME);
printf(_("\n %s help [COMMAND]\n"), PROGRAM_NAME);

printf(_("\n %s version\n"), PROGRAM_NAME);

Expand Down Expand Up @@ -247,7 +253,18 @@ help_pg_probackup(void)
if (PROGRAM_EMAIL)
printf("Report bugs to <%s>.\n", PROGRAM_EMAIL);
}
exit(0);
}

static void
help_nocmd(void)
{
printf(_("\nUnknown command. Try pg_probackup help\n\n"));
}

static void
help_internal(void)
{
printf(_("\nThis command is intended for internal use\n\n"));
}

static void
Expand Down Expand Up @@ -971,3 +988,17 @@ help_archive_get(void)
printf(_(" --ssh-options=ssh_options additional ssh options (default: none)\n"));
printf(_(" (example: --ssh-options='-c cipher_spec -F configfile')\n\n"));
}

static void
help_help(void)
{
printf(_("\n%s help [command]\n"), PROGRAM_NAME);
printf(_("%s command --help\n\n"), PROGRAM_NAME);
}

static void
help_version(void)
{
printf(_("\n%s version\n"), PROGRAM_NAME);
printf(_("%s --version\n\n"), PROGRAM_NAME);
}
Loading