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
@@ -127,7 +131,7 @@ help_pg_probackup(void)
127131 printf (_ (" [--error-log-filename=error-log-filename]\n" ));
128132 printf (_ (" [--log-directory=log-directory]\n" ));
129133 printf (_ (" [--log-rotation-size=log-rotation-size]\n" ));
130- printf (_ (" [--log-rotation-age=log-rotation-age]\n" ));
134+ printf (_ (" [--log-rotation-age=log-rotation-age] [--no-color] \n" ));
131135 printf (_ (" [--delete-expired] [--delete-wal] [--merge-expired]\n" ));
132136 printf (_ (" [--retention-redundancy=retention-redundancy]\n" ));
133137 printf (_ (" [--retention-window=retention-window]\n" ));
@@ -188,7 +192,7 @@ help_pg_probackup(void)
188192 printf (_ ("\n %s show -B backup-path\n" ), PROGRAM_NAME );
189193 printf (_ (" [--instance=instance_name [-i backup-id]]\n" ));
190194 printf (_ (" [--format=format] [--archive]\n" ));
191- printf (_ (" [--help]\n" ));
195+ printf (_ (" [--no-color] [-- help]\n" ));
192196
193197 printf (_ ("\n %s delete -B backup-path --instance=instance_name\n" ), PROGRAM_NAME );
194198 printf (_ (" [-j num-threads] [--progress]\n" ));
@@ -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
@@ -273,7 +282,7 @@ help_backup(void)
273282 printf (_ (" [--error-log-filename=error-log-filename]\n" ));
274283 printf (_ (" [--log-directory=log-directory]\n" ));
275284 printf (_ (" [--log-rotation-size=log-rotation-size]\n" ));
276- printf (_ (" [--log-rotation-age=log-rotation-age]\n" ));
285+ printf (_ (" [--log-rotation-age=log-rotation-age] [--no-color] \n" ));
277286 printf (_ (" [--delete-expired] [--delete-wal] [--merge-expired]\n" ));
278287 printf (_ (" [--retention-redundancy=retention-redundancy]\n" ));
279288 printf (_ (" [--retention-window=retention-window]\n" ));
@@ -329,6 +338,7 @@ help_backup(void)
329338 printf (_ (" --log-rotation-age=log-rotation-age\n" ));
330339 printf (_ (" rotate logfile if its age exceeds this value; 0 disables; (default: 0)\n" ));
331340 printf (_ (" available units: 'ms', 's', 'min', 'h', 'd' (default: min)\n" ));
341+ printf (_ (" --no-color disable the coloring of error and warning console messages\n" ));
332342
333343 printf (_ ("\n Retention options:\n" ));
334344 printf (_ (" --delete-expired delete backups expired according to current\n" ));
@@ -489,6 +499,7 @@ help_restore(void)
489499 printf (_ (" --log-rotation-age=log-rotation-age\n" ));
490500 printf (_ (" rotate logfile if its age exceeds this value; 0 disables; (default: 0)\n" ));
491501 printf (_ (" available units: 'ms', 's', 'min', 'h', 'd' (default: min)\n" ));
502+ printf (_ (" --no-color disable the coloring of error and warning console messages\n" ));
492503
493504 printf (_ ("\n Remote options:\n" ));
494505 printf (_ (" --remote-proto=protocol remote protocol to use\n" ));
@@ -554,7 +565,8 @@ help_validate(void)
554565 printf (_ (" available units: 'kB', 'MB', 'GB', 'TB' (default: kB)\n" ));
555566 printf (_ (" --log-rotation-age=log-rotation-age\n" ));
556567 printf (_ (" rotate logfile if its age exceeds this value; 0 disables; (default: 0)\n" ));
557- printf (_ (" available units: 'ms', 's', 'min', 'h', 'd' (default: min)\n\n" ));
568+ printf (_ (" available units: 'ms', 's', 'min', 'h', 'd' (default: min)\n" ));
569+ printf (_ (" --no-color disable the coloring of error and warning console messages\n\n" ));
558570}
559571
560572static void
@@ -599,6 +611,7 @@ help_checkdb(void)
599611 printf (_ (" --log-rotation-age=log-rotation-age\n" ));
600612 printf (_ (" rotate logfile if its age exceeds this value; 0 disables; (default: 0)\n" ));
601613 printf (_ (" available units: 'ms', 's', 'min', 'h', 'd' (default: min)\n" ));
614+ printf (_ (" --no-color disable the coloring of error and warning console messages\n" ));
602615
603616 printf (_ ("\n Connection options:\n" ));
604617 printf (_ (" -U, --pguser=USERNAME user name to connect as (default: current local user)\n" ));
@@ -620,7 +633,8 @@ help_show(void)
620633 printf (_ (" --instance=instance_name show info about specific instance\n" ));
621634 printf (_ (" -i, --backup-id=backup-id show info about specific backups\n" ));
622635 printf (_ (" --archive show WAL archive information\n" ));
623- printf (_ (" --format=format show format=PLAIN|JSON\n\n" ));
636+ printf (_ (" --format=format show format=PLAIN|JSON\n" ));
637+ printf (_ (" --no-color disable the coloring for plain format\n\n" ));
624638}
625639
626640static void
@@ -673,7 +687,8 @@ help_delete(void)
673687 printf (_ (" available units: 'kB', 'MB', 'GB', 'TB' (default: kB)\n" ));
674688 printf (_ (" --log-rotation-age=log-rotation-age\n" ));
675689 printf (_ (" rotate logfile if its age exceeds this value; 0 disables; (default: 0)\n" ));
676- printf (_ (" available units: 'ms', 's', 'min', 'h', 'd' (default: min)\n\n" ));
690+ printf (_ (" available units: 'ms', 's', 'min', 'h', 'd' (default: min)\n" ));
691+ printf (_ (" --no-color disable the coloring of error and warning console messages\n\n" ));
677692}
678693
679694static void
@@ -715,7 +730,8 @@ help_merge(void)
715730 printf (_ (" available units: 'kB', 'MB', 'GB', 'TB' (default: kB)\n" ));
716731 printf (_ (" --log-rotation-age=log-rotation-age\n" ));
717732 printf (_ (" rotate logfile if its age exceeds this value; 0 disables; (default: 0)\n" ));
718- printf (_ (" available units: 'ms', 's', 'min', 'h', 'd' (default: min)\n\n" ));
733+ printf (_ (" available units: 'ms', 's', 'min', 'h', 'd' (default: min)\n" ));
734+ printf (_ (" --no-color disable the coloring of error and warning console messages\n\n" ));
719735}
720736
721737static void
@@ -964,3 +980,9 @@ help_archive_get(void)
964980 printf (_ (" --ssh-options=ssh_options additional ssh options (default: none)\n" ));
965981 printf (_ (" (example: --ssh-options='-c cipher_spec -F configfile')\n\n" ));
966982}
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