@@ -143,6 +143,7 @@ static int set_dest(cmd_line_option_t *option, char *sval);
143143static void fill (const cmd_line_option_t * a , char result [3 ][BUFSIZ ]);
144144static int qsort_callback (const void * a , const void * b );
145145static opal_cmd_line_otype_t get_help_otype (opal_cmd_line_t * cmd );
146+ static char * build_parsable (cmd_line_option_t * option );
146147
147148
148149/*
@@ -570,7 +571,12 @@ char *opal_cmd_line_get_usage_msg(opal_cmd_line_t *cmd)
570571
571572 for (j = 0 ; j < opal_list_get_size (& cmd -> lcl_options ); ++ j ) {
572573 option = sorted [j ];
573- if (otype == OPAL_CMD_LINE_OTYPE_NULL || option -> clo_otype == otype ) {
574+ if (otype == OPAL_CMD_LINE_OTYPE_PARSABLE ) {
575+ ret = build_parsable (option );
576+ opal_argv_append (& argc , & argv , ret );
577+ free (ret );
578+ ret = NULL ;
579+ } else if (otype == OPAL_CMD_LINE_OTYPE_NULL || option -> clo_otype == otype ) {
574580 if (NULL != option -> clo_description ) {
575581 bool filled = false;
576582
@@ -1375,7 +1381,33 @@ static opal_cmd_line_otype_t get_help_otype(opal_cmd_line_t *cmd)
13751381 otype = OPAL_CMD_LINE_OTYPE_DVM ;
13761382 } else if (0 == strcmp (arg , "general" )) {
13771383 otype = OPAL_CMD_LINE_OTYPE_GENERAL ;
1384+ } else if (0 == strcmp (arg , "parsable" )) {
1385+ otype = OPAL_CMD_LINE_OTYPE_PARSABLE ;
13781386 }
13791387
13801388 return otype ;
13811389}
1390+
1391+ /*
1392+ * Helper function to build a parsable string for the help
1393+ * output.
1394+ */
1395+ static char * build_parsable (cmd_line_option_t * option ) {
1396+ char * line ;
1397+ int length ;
1398+
1399+ length = snprintf (NULL , 0 , "%c:%s:%s:%d:%s\n" , option -> clo_short_name , option -> clo_single_dash_name ,
1400+ option -> clo_long_name , option -> clo_num_params , option -> clo_description );
1401+
1402+ line = (char * )malloc (length * sizeof (char ));
1403+
1404+ if ('\0' == option -> clo_short_name ) {
1405+ snprintf (line , length , "0:%s:%s:%d:%s\n" , option -> clo_single_dash_name , option -> clo_long_name ,
1406+ option -> clo_num_params , option -> clo_description );
1407+ } else {
1408+ snprintf (line , length , "%c:%s:%s:%d:%s\n" , option -> clo_short_name , option -> clo_single_dash_name ,
1409+ option -> clo_long_name , option -> clo_num_params , option -> clo_description );
1410+ }
1411+
1412+ return line ;
1413+ }
0 commit comments