At 2014-09-24 09:25:12 -0400, t...@sss.pgh.pa.us wrote:
>
> What's so hard about [ -D ] before the datadir argument?

I'm sorry to have given you the impression that I objected to it because
it was hard. Since I proposed the same thing a few lines after what you
quoted, I guess I have to agree it's not hard.

I think it's pointless, because if you're going to look at the usage
message to begin with, why not do what it already says? But I don't
care enough to argue about it any further.

Patches attached.

-- Abhijit

P.S. Trivia: I can't find any other options in Postgres where the
argument is mandatory but the option is optional.
>From 69d7386ab59ca9df74af5abe5a5c3cf5a93e64bb Mon Sep 17 00:00:00 2001
From: Abhijit Menon-Sen <a...@2ndquadrant.com>
Date: Wed, 24 Sep 2014 16:26:00 +0530
Subject: Make pg_controldata ignore a -D before DataDir

---
 src/bin/pg_controldata/pg_controldata.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index f815024..4386283 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -33,7 +33,7 @@ usage(const char *progname)
 {
 	printf(_("%s displays control information of a PostgreSQL database cluster.\n\n"), progname);
 	printf(_("Usage:\n"));
-	printf(_("  %s [OPTION] [DATADIR]\n"), progname);
+	printf(_("  %s [OPTION] [[-D] DATADIR]\n"), progname);
 	printf(_("\nOptions:\n"));
 	printf(_("  -V, --version  output version information, then exit\n"));
 	printf(_("  -?, --help     show this help, then exit\n"));
@@ -120,7 +120,11 @@ main(int argc, char *argv[])
 	}
 
 	if (argc > 1)
+	{
 		DataDir = argv[1];
+		if (strcmp(DataDir, "-D") == 0 && argc > 2)
+			DataDir = argv[2];
+	}
 	else
 		DataDir = getenv("PGDATA");
 	if (DataDir == NULL)
-- 
1.9.1

>From 388b5009281184051398657449e649ec9585a242 Mon Sep 17 00:00:00 2001
From: Abhijit Menon-Sen <a...@2ndquadrant.com>
Date: Wed, 24 Sep 2014 16:48:36 +0530
Subject: Make pg_resetxlog also accept -D datadir

---
 src/bin/pg_resetxlog/pg_resetxlog.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/bin/pg_resetxlog/pg_resetxlog.c b/src/bin/pg_resetxlog/pg_resetxlog.c
index 302d005..8ff5df0 100644
--- a/src/bin/pg_resetxlog/pg_resetxlog.c
+++ b/src/bin/pg_resetxlog/pg_resetxlog.c
@@ -89,7 +89,7 @@ main(int argc, char *argv[])
 	MultiXactId set_oldestmxid = 0;
 	char	   *endptr;
 	char	   *endptr2;
-	char	   *DataDir;
+	char	   *DataDir = NULL;
 	int			fd;
 
 	set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_resetxlog"));
@@ -111,10 +111,14 @@ main(int argc, char *argv[])
 	}
 
 
-	while ((c = getopt(argc, argv, "fl:m:no:O:x:e:")) != -1)
+	while ((c = getopt(argc, argv, "D:fl:m:no:O:x:e:")) != -1)
 	{
 		switch (c)
 		{
+			case 'D':
+				DataDir = optarg;
+				break;
+
 			case 'f':
 				force = true;
 				break;
@@ -233,7 +237,7 @@ main(int argc, char *argv[])
 		}
 	}
 
-	if (optind == argc)
+	if (DataDir == NULL && optind == argc)
 	{
 		fprintf(stderr, _("%s: no data directory specified\n"), progname);
 		fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
@@ -257,7 +261,8 @@ main(int argc, char *argv[])
 	}
 #endif
 
-	DataDir = argv[optind];
+	if (DataDir == NULL)
+		DataDir = argv[optind];
 
 	if (chdir(DataDir) < 0)
 	{
@@ -1077,7 +1082,7 @@ static void
 usage(void)
 {
 	printf(_("%s resets the PostgreSQL transaction log.\n\n"), progname);
-	printf(_("Usage:\n  %s [OPTION]... DATADIR\n\n"), progname);
+	printf(_("Usage:\n  %s [OPTION]... [-D] DATADIR\n\n"), progname);
 	printf(_("Options:\n"));
 	printf(_("  -e XIDEPOCH      set next transaction ID epoch\n"));
 	printf(_("  -f               force update to be done\n"));
-- 
1.9.1

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to