Skip to content

Commit 36d660e

Browse files
author
Nathaniel Graham
committed
Add parsable option to help arguments
This commit adds a "parsable" option to the help arguments, which prints out a machine readable list of all the mpirun options. Fixes #3279 Signed-off-by: Nathaniel Graham <[email protected]>
1 parent 7063f30 commit 36d660e

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

opal/util/cmd_line.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ static int set_dest(cmd_line_option_t *option, char *sval);
143143
static void fill(const cmd_line_option_t *a, char result[3][BUFSIZ]);
144144
static int qsort_callback(const void *a, const void *b);
145145
static 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+
}

opal/util/cmd_line.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ BEGIN_C_DECLS
193193
OPAL_CMD_LINE_OTYPE_LAUNCH,
194194
OPAL_CMD_LINE_OTYPE_DVM,
195195
OPAL_CMD_LINE_OTYPE_UNSUPPORTED,
196+
OPAL_CMD_LINE_OTYPE_PARSABLE,
196197
OPAL_CMD_LINE_OTYPE_NULL
197198
};
198199
/**

0 commit comments

Comments
 (0)