aboutsummaryrefslogtreecommitdiff
path: root/src/fe_utils/option_utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fe_utils/option_utils.c')
-rw-r--r--src/fe_utils/option_utils.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/fe_utils/option_utils.c b/src/fe_utils/option_utils.c
new file mode 100644
index 00000000000..e19a495dba7
--- /dev/null
+++ b/src/fe_utils/option_utils.c
@@ -0,0 +1,38 @@
+/*-------------------------------------------------------------------------
+ *
+ * Command line option processing facilities for frontend code
+ *
+ * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/fe_utils/option_utils.c
+ *
+ *-------------------------------------------------------------------------
+ */
+
+#include "postgres_fe.h"
+
+#include "fe_utils/option_utils.h"
+
+/*
+ * Provide strictly harmonized handling of --help and --version
+ * options.
+ */
+void
+handle_help_version_opts(int argc, char *argv[],
+ const char *fixed_progname, help_handler hlp)
+{
+ if (argc > 1)
+ {
+ if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
+ {
+ hlp(get_progname(argv[0]));
+ exit(0);
+ }
+ if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
+ {
+ printf("%s (PostgreSQL) " PG_VERSION "\n", fixed_progname);
+ exit(0);
+ }
+ }
+}