On Sun, May 21, 2023 at 07:44:49AM -0700, Nathan Bossart wrote:
> On Sun, May 21, 2023 at 08:00:15AM +0200, Peter Eisentraut wrote:
>> Maybe
>> 
>> createuser --with-members
>> 
>> and
>> 
>> createuser --member-of
>> 
>> would be clearer.
> 
> Those seem like reasonable choices to me.  I suspect we'll want to keep
> --role around for backward compatibility.

I've attached a draft patch for this.  I also changed --admin to
--with-admin.

-- 
Nathan Bossart
Amazon Web Services: https://aws.amazon.com
diff --git a/doc/src/sgml/ref/createuser.sgml b/doc/src/sgml/ref/createuser.sgml
index 58ed111642..062509deb8 100644
--- a/doc/src/sgml/ref/createuser.sgml
+++ b/doc/src/sgml/ref/createuser.sgml
@@ -82,7 +82,7 @@ PostgreSQL documentation
 
      <varlistentry>
       <term><option>-a <replaceable class="parameter">role</replaceable></option></term>
-      <term><option>--admin=<replaceable class="parameter">role</replaceable></option></term>
+      <term><option>--with-admin=<replaceable class="parameter">role</replaceable></option></term>
       <listitem>
        <para>
         Indicates an existing role that will be automatically added as a member of the new
@@ -149,7 +149,7 @@ PostgreSQL documentation
 
      <varlistentry>
       <term><option>-g <replaceable class="parameter">role</replaceable></option></term>
-      <term><option>--role=<replaceable class="parameter">role</replaceable></option></term>
+      <term><option>--member-of=<replaceable class="parameter">role</replaceable></option></term>
       <listitem>
        <para>
         Indicates the new role should be automatically added as a member
@@ -222,7 +222,7 @@ PostgreSQL documentation
 
      <varlistentry>
       <term><option>-m <replaceable class="parameter">role</replaceable></option></term>
-      <term><option>--member=<replaceable class="parameter">role</replaceable></option></term>
+      <term><option>--with-member=<replaceable class="parameter">role</replaceable></option></term>
       <listitem>
        <para>
         Indicates the specified existing role should be automatically
diff --git a/src/bin/scripts/createuser.c b/src/bin/scripts/createuser.c
index 0c7f454be5..77cb0bb8e1 100644
--- a/src/bin/scripts/createuser.c
+++ b/src/bin/scripts/createuser.c
@@ -28,7 +28,7 @@ int
 main(int argc, char *argv[])
 {
 	static struct option long_options[] = {
-		{"admin", required_argument, NULL, 'a'},
+		{"with-admin", required_argument, NULL, 'a'},
 		{"connection-limit", required_argument, NULL, 'c'},
 		{"createdb", no_argument, NULL, 'd'},
 		{"no-createdb", no_argument, NULL, 'D'},
@@ -40,7 +40,7 @@ main(int argc, char *argv[])
 		{"no-inherit", no_argument, NULL, 'I'},
 		{"login", no_argument, NULL, 'l'},
 		{"no-login", no_argument, NULL, 'L'},
-		{"member", required_argument, NULL, 'm'},
+		{"with-member", required_argument, NULL, 'm'},
 		{"port", required_argument, NULL, 'p'},
 		{"pwprompt", no_argument, NULL, 'P'},
 		{"createrole", no_argument, NULL, 'r'},
@@ -56,6 +56,7 @@ main(int argc, char *argv[])
 		{"interactive", no_argument, NULL, 3},
 		{"bypassrls", no_argument, NULL, 4},
 		{"no-bypassrls", no_argument, NULL, 5},
+		{"member-of", required_argument, NULL, 6},
 		{NULL, 0, NULL, 0}
 	};
 
@@ -123,6 +124,7 @@ main(int argc, char *argv[])
 			case 'E':
 				/* no-op, accepted for backward compatibility */
 				break;
+			case 6:
 			case 'g':
 				simple_string_list_append(&roles, optarg);
 				break;
@@ -414,19 +416,19 @@ help(const char *progname)
 	printf(_("Usage:\n"));
 	printf(_("  %s [OPTION]... [ROLENAME]\n"), progname);
 	printf(_("\nOptions:\n"));
-	printf(_("  -a, --admin=ROLE          this role will be a member of new role with admin\n"
+	printf(_("  -a, --with-admin=ROLE     this role will be a member of new role with admin\n"
 			 "                            option\n"));
 	printf(_("  -c, --connection-limit=N  connection limit for role (default: no limit)\n"));
 	printf(_("  -d, --createdb            role can create new databases\n"));
 	printf(_("  -D, --no-createdb         role cannot create databases (default)\n"));
 	printf(_("  -e, --echo                show the commands being sent to the server\n"));
-	printf(_("  -g, --role=ROLE           new role will be a member of this role\n"));
+	printf(_("  -g, --member-of=ROLE      new role will be a member of this role\n"));
 	printf(_("  -i, --inherit             role inherits privileges of roles it is a\n"
 			 "                            member of (default)\n"));
 	printf(_("  -I, --no-inherit          role does not inherit privileges\n"));
 	printf(_("  -l, --login               role can login (default)\n"));
 	printf(_("  -L, --no-login            role cannot login\n"));
-	printf(_("  -m, --member=ROLE         this role will be a member of new role\n"));
+	printf(_("  -m, --with-member=ROLE    this role will be a member of new role\n"));
 	printf(_("  -P, --pwprompt            assign a password to new role\n"));
 	printf(_("  -r, --createrole          role can create new roles\n"));
 	printf(_("  -R, --no-createrole       role cannot create roles (default)\n"));
diff --git a/src/bin/scripts/t/040_createuser.pl b/src/bin/scripts/t/040_createuser.pl
index da99d0ccb9..7530a9f007 100644
--- a/src/bin/scripts/t/040_createuser.pl
+++ b/src/bin/scripts/t/040_createuser.pl
@@ -64,4 +64,21 @@ $node->issues_sql_like(
 $node->command_fails([ 'createuser', 'regress_user1' ],
 	'fails if role already exists');
 
+$node->issues_sql_like(
+	[ 'createuser', 'regress_user9', '--with-admin', 'regress_user1' ],
+	qr/statement: CREATE ROLE regress_user9 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN NOREPLICATION NOBYPASSRLS ADMIN regress_user1;/,
+	'--with-admin');
+$node->issues_sql_like(
+	[ 'createuser', 'regress_user10', '--with-member', 'regress_user1' ],
+	qr/statement: CREATE ROLE regress_user10 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN NOREPLICATION NOBYPASSRLS ROLE regress_user1;/,
+	'--with-member');
+$node->issues_sql_like(
+	[ 'createuser', 'regress_user11', '--role', 'regress_user1' ],
+	qr/statement: CREATE ROLE regress_user11 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN NOREPLICATION NOBYPASSRLS IN ROLE regress_user1;/,
+	'--role (for backward compatibility)');
+$node->issues_sql_like(
+	[ 'createuser', 'regress_user12', '--member-of', 'regress_user1' ],
+	qr/statement: CREATE ROLE regress_user12 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN NOREPLICATION NOBYPASSRLS IN ROLE regress_user1;/,
+	'--member-of');
+
 done_testing();

Reply via email to