@@ -24,6 +24,7 @@ main(int argc, char *argv[])
2424{"host" ,required_argument ,NULL ,'h' },
2525{"port" ,required_argument ,NULL ,'p' },
2626{"username" ,required_argument ,NULL ,'U' },
27+ {"role" ,required_argument ,NULL ,'g' },
2728{"no-password" ,no_argument ,NULL ,'w' },
2829{"password" ,no_argument ,NULL ,'W' },
2930{"echo" ,no_argument ,NULL ,'e' },
@@ -57,6 +58,7 @@ main(int argc, char *argv[])
5758char * host = NULL ;
5859char * port = NULL ;
5960char * username = NULL ;
61+ SimpleStringList roles = {NULL ,NULL };
6062enum trivalue prompt_password = TRI_DEFAULT ;
6163bool echo = false;
6264bool interactive = false;
@@ -83,7 +85,7 @@ main(int argc, char *argv[])
8385
8486handle_help_version_opts (argc ,argv ,"createuser" ,help );
8587
86- while ((c = getopt_long (argc ,argv ,"h:p:U:wWedDsSaArRiIlLc:PEN" ,
88+ while ((c = getopt_long (argc ,argv ,"h:p:U:g: wWedDsSaArRiIlLc:PEN" ,
8789long_options ,& optindex ))!= -1 )
8890{
8991switch (c )
@@ -97,6 +99,9 @@ main(int argc, char *argv[])
9799case 'U' :
98100username = pg_strdup (optarg );
99101break ;
102+ case 'g' :
103+ simple_string_list_append (& roles ,optarg );
104+ break ;
100105case 'w' :
101106prompt_password = TRI_NO ;
102107break ;
@@ -302,6 +307,19 @@ main(int argc, char *argv[])
302307appendPQExpBufferStr (& sql ," NOREPLICATION" );
303308if (conn_limit != NULL )
304309appendPQExpBuffer (& sql ," CONNECTION LIMIT %s" ,conn_limit );
310+ if (roles .head != NULL )
311+ {
312+ SimpleStringListCell * cell ;
313+ appendPQExpBufferStr (& sql ," IN ROLE " );
314+
315+ for (cell = roles .head ;cell ;cell = cell -> next )
316+ {
317+ if (cell -> next )
318+ appendPQExpBuffer (& sql ,"%s," ,fmtId (cell -> val ));
319+ else
320+ appendPQExpBuffer (& sql ,"%s" ,fmtId (cell -> val ));
321+ }
322+ }
305323appendPQExpBufferStr (& sql ,";\n" );
306324
307325if (echo )
@@ -334,6 +352,7 @@ help(const char *progname)
334352printf (_ (" -D, --no-createdb role cannot create databases (default)\n" ));
335353printf (_ (" -e, --echo show the commands being sent to the server\n" ));
336354printf (_ (" -E, --encrypted encrypt stored password\n" ));
355+ printf (_ (" -g, --role=ROLE new role will be a member of this role\n" ));
337356printf (_ (" -i, --inherit role inherits privileges of roles it is a\n"
338357" member of (default)\n" ));
339358printf (_ (" -I, --no-inherit role does not inherit privileges\n" ));