From 36d660e07a597da01c4d16c14bb8ba81a0973f80 Mon Sep 17 00:00:00 2001 From: Nathaniel Graham Date: Wed, 5 Apr 2017 17:01:43 -0600 Subject: [PATCH] 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 --- opal/util/cmd_line.c | 34 +++++++++++++++++++++++++++++++++- opal/util/cmd_line.h | 1 + 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/opal/util/cmd_line.c b/opal/util/cmd_line.c index 5fece780a4..a6cd171ad5 100644 --- a/opal/util/cmd_line.c +++ b/opal/util/cmd_line.c @@ -143,6 +143,7 @@ static int set_dest(cmd_line_option_t *option, char *sval); static void fill(const cmd_line_option_t *a, char result[3][BUFSIZ]); static int qsort_callback(const void *a, const void *b); static opal_cmd_line_otype_t get_help_otype(opal_cmd_line_t *cmd); +static char *build_parsable(cmd_line_option_t *option); /* @@ -570,7 +571,12 @@ char *opal_cmd_line_get_usage_msg(opal_cmd_line_t *cmd) for (j = 0; j < opal_list_get_size(&cmd->lcl_options); ++j) { option = sorted[j]; - if(otype == OPAL_CMD_LINE_OTYPE_NULL || option->clo_otype == otype) { + if(otype == OPAL_CMD_LINE_OTYPE_PARSABLE) { + ret = build_parsable(option); + opal_argv_append(&argc, &argv, ret); + free(ret); + ret = NULL; + } else if(otype == OPAL_CMD_LINE_OTYPE_NULL || option->clo_otype == otype) { if (NULL != option->clo_description) { bool filled = false; @@ -1375,7 +1381,33 @@ static opal_cmd_line_otype_t get_help_otype(opal_cmd_line_t *cmd) otype = OPAL_CMD_LINE_OTYPE_DVM; } else if (0 == strcmp(arg, "general")) { otype = OPAL_CMD_LINE_OTYPE_GENERAL; + } else if (0 == strcmp(arg, "parsable")) { + otype = OPAL_CMD_LINE_OTYPE_PARSABLE; } return otype; } + +/* + * Helper function to build a parsable string for the help + * output. + */ +static char *build_parsable(cmd_line_option_t *option) { + char *line; + int length; + + length = snprintf(NULL, 0, "%c:%s:%s:%d:%s\n", option->clo_short_name, option->clo_single_dash_name, + option->clo_long_name, option->clo_num_params, option->clo_description); + + line = (char *)malloc(length * sizeof(char)); + + if('\0' == option->clo_short_name) { + snprintf(line, length, "0:%s:%s:%d:%s\n", option->clo_single_dash_name, option->clo_long_name, + option->clo_num_params, option->clo_description); + } else { + snprintf(line, length, "%c:%s:%s:%d:%s\n", option->clo_short_name, option->clo_single_dash_name, + option->clo_long_name, option->clo_num_params, option->clo_description); + } + + return line; +} diff --git a/opal/util/cmd_line.h b/opal/util/cmd_line.h index 18814d91d2..9088063b90 100644 --- a/opal/util/cmd_line.h +++ b/opal/util/cmd_line.h @@ -193,6 +193,7 @@ BEGIN_C_DECLS OPAL_CMD_LINE_OTYPE_LAUNCH, OPAL_CMD_LINE_OTYPE_DVM, OPAL_CMD_LINE_OTYPE_UNSUPPORTED, + OPAL_CMD_LINE_OTYPE_PARSABLE, OPAL_CMD_LINE_OTYPE_NULL }; /**