On Tue, Dec 10, 2013 at 12:20 AM, Robert Haas <robertmh...@gmail.com> wrote:
> On Sat, Dec 7, 2013 at 11:39 PM, Amit Kapila <amit.kapil...@gmail.com> wrote:
>> On Fri, Dec 6, 2013 at 10:31 AM, Peter Eisentraut <pete...@gmx.net> wrote:
>>>
>>> How about only one role name per -g option, but allowing the -g option
>>> to be repeated?
>>
>>    I think that might simplify the problem and patch, but do you think
>> it is okay to have inconsistency
>>    for usage of options between Create User statement and this utility?
>
> Yes.  In general, command-line utilities use a very different syntax
> for options-passing that SQL commands.  Trying to make them consistent
> feels unnecessary or perhaps even counterproductive.  And the proposed
> syntax is certainly a convention common to many other command-line
> utilities, so I think it's fine.

Okay, the new way for syntax suggested by Peter has simplified the problem.
Please find the updated patch and docs for multiple -g options.

If there are no objections, then I will mark this patch as Ready For Committer.

Christopher, please check once, if you have any comments/objections
for modifications.

With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com
diff --git a/doc/src/sgml/ref/createuser.sgml b/doc/src/sgml/ref/createuser.sgml
index 2f1ea2f..63d4c6c 100644
--- a/doc/src/sgml/ref/createuser.sgml
+++ b/doc/src/sgml/ref/createuser.sgml
@@ -131,6 +131,19 @@ PostgreSQL documentation
      </varlistentry>
 
      <varlistentry>
+      <term><option>-g <replaceable 
class="parameter">role</replaceable></></term>
+      <term><option>--role=<replaceable 
class="parameter">role</replaceable></></term>
+      <listitem>
+       <para>
+         Indicates role to which this role will be added immediately as a new
+         member. Multiple roles to which this role will be added as a member
+         can be specified by writing multiple
+         <option>-g</> switches.
+         </para>
+      </listitem>
+     </varlistentry>
+
+     <varlistentry>
       <term><option>-i</></term>
       <term><option>--inherit</></term>
       <listitem>
diff --git a/src/bin/scripts/createuser.c b/src/bin/scripts/createuser.c
index 83623ea..d98b420 100644
--- a/src/bin/scripts/createuser.c
+++ b/src/bin/scripts/createuser.c
@@ -24,6 +24,7 @@ main(int argc, char *argv[])
                {"host", required_argument, NULL, 'h'},
                {"port", required_argument, NULL, 'p'},
                {"username", required_argument, NULL, 'U'},
+               {"role", required_argument, NULL, 'g'},
                {"no-password", no_argument, NULL, 'w'},
                {"password", no_argument, NULL, 'W'},
                {"echo", no_argument, NULL, 'e'},
@@ -57,6 +58,7 @@ main(int argc, char *argv[])
        char       *host = NULL;
        char       *port = NULL;
        char       *username = NULL;
+       SimpleStringList roles = {NULL, NULL};
        enum trivalue prompt_password = TRI_DEFAULT;
        bool            echo = false;
        bool            interactive = false;
@@ -83,7 +85,7 @@ main(int argc, char *argv[])
 
        handle_help_version_opts(argc, argv, "createuser", help);
 
-       while ((c = getopt_long(argc, argv, "h:p:U:wWedDsSaArRiIlLc:PEN",
+       while ((c = getopt_long(argc, argv, "h:p:U:g:wWedDsSaArRiIlLc:PEN",
                                                        long_options, 
&optindex)) != -1)
        {
                switch (c)
@@ -97,6 +99,9 @@ main(int argc, char *argv[])
                        case 'U':
                                username = pg_strdup(optarg);
                                break;
+                       case 'g':
+                               simple_string_list_append(&roles, optarg);
+                               break;
                        case 'w':
                                prompt_password = TRI_NO;
                                break;
@@ -302,6 +307,19 @@ main(int argc, char *argv[])
                appendPQExpBufferStr(&sql, " NOREPLICATION");
        if (conn_limit != NULL)
                appendPQExpBuffer(&sql, " CONNECTION LIMIT %s", conn_limit);
+       if (roles.head != NULL)
+       {
+               SimpleStringListCell *cell;
+               appendPQExpBufferStr(&sql, " IN ROLE ");
+
+               for (cell = roles.head; cell; cell = cell->next)
+               {
+                       if (cell->next)
+                               appendPQExpBuffer(&sql, "%s,", 
fmtId(cell->val));
+                       else
+                               appendPQExpBuffer(&sql, "%s", fmtId(cell->val));
+               }
+       }
        appendPQExpBufferStr(&sql, ";\n");
 
        if (echo)
@@ -334,6 +352,7 @@ help(const char *progname)
        printf(_("  -D, --no-createdb         role cannot create databases 
(default)\n"));
        printf(_("  -e, --echo                show the commands being sent to 
the server\n"));
        printf(_("  -E, --encrypted           encrypt stored password\n"));
+       printf(_("  -g, --role=ROLE           role(s) to associate with this 
new 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"));
-- 
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