@@ -143,6 +143,7 @@ static int set_dest(cmd_line_option_t *option, char *sval);
143
143
static void fill (const cmd_line_option_t * a , char result [3 ][BUFSIZ ]);
144
144
static int qsort_callback (const void * a , const void * b );
145
145
static opal_cmd_line_otype_t get_help_otype (opal_cmd_line_t * cmd );
146
+ static char * build_parsable (cmd_line_option_t * option );
146
147
147
148
148
149
/*
@@ -570,7 +571,12 @@ char *opal_cmd_line_get_usage_msg(opal_cmd_line_t *cmd)
570
571
571
572
for (j = 0 ; j < opal_list_get_size (& cmd -> lcl_options ); ++ j ) {
572
573
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 ) {
574
580
if (NULL != option -> clo_description ) {
575
581
bool filled = false;
576
582
@@ -1375,7 +1381,33 @@ static opal_cmd_line_otype_t get_help_otype(opal_cmd_line_t *cmd)
1375
1381
otype = OPAL_CMD_LINE_OTYPE_DVM ;
1376
1382
} else if (0 == strcmp (arg , "general" )) {
1377
1383
otype = OPAL_CMD_LINE_OTYPE_GENERAL ;
1384
+ } else if (0 == strcmp (arg , "parsable" )) {
1385
+ otype = OPAL_CMD_LINE_OTYPE_PARSABLE ;
1378
1386
}
1379
1387
1380
1388
return otype ;
1381
1389
}
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