@@ -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[])
5758 char * host = NULL ;
5859 char * port = NULL ;
5960 char * username = NULL ;
61+ SimpleStringList roles = {NULL , NULL };
6062 enum trivalue prompt_password = TRI_DEFAULT ;
6163 bool echo = false;
6264 bool interactive = false;
@@ -83,7 +85,7 @@ main(int argc, char *argv[])
8385
8486 handle_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" ,
8789 long_options , & optindex )) != -1 )
8890 {
8991 switch (c )
@@ -97,6 +99,9 @@ main(int argc, char *argv[])
9799 case 'U' :
98100 username = pg_strdup (optarg );
99101 break ;
102+ case 'g' :
103+ simple_string_list_append (& roles , optarg );
104+ break ;
100105 case 'w' :
101106 prompt_password = TRI_NO ;
102107 break ;
@@ -302,6 +307,19 @@ main(int argc, char *argv[])
302307 appendPQExpBufferStr (& sql , " NOREPLICATION" );
303308 if (conn_limit != NULL )
304309 appendPQExpBuffer (& 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+ }
305323 appendPQExpBufferStr (& sql , ";\n" );
306324
307325 if (echo )
@@ -334,6 +352,7 @@ help(const char *progname)
334352 printf (_ (" -D, --no-createdb role cannot create databases (default)\n" ));
335353 printf (_ (" -e, --echo show the commands being sent to the server\n" ));
336354 printf (_ (" -E, --encrypted encrypt stored password\n" ));
355+ printf (_ (" -g, --role=ROLE new role will be a member of this role\n" ));
337356 printf (_ (" -i, --inherit role inherits privileges of roles it is a\n"
338357 " member of (default)\n" ));
339358 printf (_ (" -I, --no-inherit role does not inherit privileges\n" ));
0 commit comments