77 *-------------------------------------------------------------------------
88 */
99
10+ #include <assert.h>
1011#include "pg_probackup.h"
1112
13+ static void help_nocmd (void );
1214static void help_init (void );
1315static void help_backup (void );
1416static void help_restore (void );
@@ -24,50 +26,52 @@ static void help_del_instance(void);
2426static void help_archive_push (void );
2527static void help_archive_get (void );
2628static void help_checkdb (void );
29+ static void help_help (void );
2730
2831void
29- help_command ( char * command )
32+ help_print_version ( void )
3033{
31- if (strcmp (command , "init" ) == 0 )
32- help_init ();
33- else if (strcmp (command , "backup" ) == 0 )
34- help_backup ();
35- else if (strcmp (command , "restore" ) == 0 )
36- help_restore ();
37- else if (strcmp (command , "validate" ) == 0 )
38- help_validate ();
39- else if (strcmp (command , "show" ) == 0 )
40- help_show ();
41- else if (strcmp (command , "delete" ) == 0 )
42- help_delete ();
43- else if (strcmp (command , "merge" ) == 0 )
44- help_merge ();
45- else if (strcmp (command , "set-backup" ) == 0 )
46- help_set_backup ();
47- else if (strcmp (command , "set-config" ) == 0 )
48- help_set_config ();
49- else if (strcmp (command , "show-config" ) == 0 )
50- help_show_config ();
51- else if (strcmp (command , "add-instance" ) == 0 )
52- help_add_instance ();
53- else if (strcmp (command , "del-instance" ) == 0 )
54- help_del_instance ();
55- else if (strcmp (command , "archive-push" ) == 0 )
56- help_archive_push ();
57- else if (strcmp (command , "archive-get" ) == 0 )
58- help_archive_get ();
59- else if (strcmp (command , "checkdb" ) == 0 )
60- help_checkdb ();
61- else if (strcmp (command , "--help" ) == 0
62- || strcmp (command , "help" ) == 0
63- || strcmp (command , "-?" ) == 0
64- || strcmp (command , "--version" ) == 0
65- || strcmp (command , "version" ) == 0
66- || strcmp (command , "-V" ) == 0 )
67- printf (_ ("No help page for \"%s\" command. Try pg_probackup help\n" ), command );
68- else
69- printf (_ ("Unknown command \"%s\". Try pg_probackup help\n" ), command );
70- exit (0 );
34+ #ifdef PGPRO_VERSION
35+ fprintf (stdout , "%s %s (Postgres Pro %s %s)\n" ,
36+ PROGRAM_NAME , PROGRAM_VERSION ,
37+ PGPRO_VERSION , PGPRO_EDITION );
38+ #else
39+ fprintf (stdout , "%s %s (PostgreSQL %s)\n" ,
40+ PROGRAM_NAME , PROGRAM_VERSION , PG_VERSION );
41+ #endif
42+ }
43+
44+ void
45+ help_command (ProbackupSubcmd const subcmd )
46+ {
47+ typedef void (* help_function_ptr )(void );
48+ /* Order is important, keep it in sync with utils/configuration.h:enum ProbackupSubcmd declaration */
49+ static help_function_ptr const help_functions [] =
50+ {
51+ & help_nocmd ,
52+ & help_init ,
53+ & help_add_instance ,
54+ & help_del_instance ,
55+ & help_archive_push ,
56+ & help_archive_get ,
57+ & help_backup ,
58+ & help_restore ,
59+ & help_validate ,
60+ & help_delete ,
61+ & help_merge ,
62+ & help_show ,
63+ & help_set_config ,
64+ & help_set_backup ,
65+ & help_show_config ,
66+ & help_checkdb ,
67+ & help_nocmd , // SSH_CMD
68+ & help_nocmd , // AGENT_CMD
69+ & help_help ,
70+ & help_help , // VERSION_CMD
71+ };
72+
73+ Assert ((int )subcmd < sizeof (help_functions ) / sizeof (help_functions [0 ]));
74+ help_functions [(int )subcmd ]();
7175}
7276
7377void
@@ -247,7 +251,12 @@ help_pg_probackup(void)
247251 if (PROGRAM_EMAIL )
248252 printf ("Report bugs to <%s>.\n" , PROGRAM_EMAIL );
249253 }
250- exit (0 );
254+ }
255+
256+ static void
257+ help_nocmd (void )
258+ {
259+ printf (_ ("Unknown command. Try pg_probackup help\n" ));
251260}
252261
253262static void
@@ -971,3 +980,9 @@ help_archive_get(void)
971980 printf (_ (" --ssh-options=ssh_options additional ssh options (default: none)\n" ));
972981 printf (_ (" (example: --ssh-options='-c cipher_spec -F configfile')\n\n" ));
973982}
983+
984+ static void
985+ help_help (void )
986+ {
987+ printf (_ ("No help page required for \"help\" and \"version\" commands. Just try it!\n" ));
988+ }
0 commit comments