Skip to content

Commit

Permalink
Merge pull request #684 from grondo/issue#655
Browse files Browse the repository at this point in the history
flux-help: allow command help search pattern to be extended
  • Loading branch information
garlick committed May 26, 2016
2 parents 1aab48d + 9216063 commit 20f1f2d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
13 changes: 12 additions & 1 deletion src/cmd/cmdhelp.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ zhash_t *get_command_list_hash (const char *pattern)
return (zh);
}

void emit_command_help (const char *pattern, FILE *fp)
static void emit_command_help_from_pattern (const char *pattern, FILE *fp)
{
zhash_t *zh = NULL;
zlist_t *keys = NULL;
Expand All @@ -262,6 +262,17 @@ void emit_command_help (const char *pattern, FILE *fp)
return;
}

void emit_command_help (const char *plist, FILE *fp)
{
int i, count;
sds *p;
if (!(p = sdssplitlen (plist, strlen (plist), ":", 1, &count)))
return;
for (i = 0; i < count; i++)
emit_command_help_from_pattern (p[i], fp);
sdsfreesplitres (p, count);
}

/*
* vi: ts=4 sw=4 expandtab
*/
21 changes: 15 additions & 6 deletions src/cmd/flux.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,23 @@ static struct optparse_option opts[] = {
OPTPARSE_TABLE_END
};

static const char *default_cmdhelp_pattern (optparse_t *p)
{
int *flags = optparse_get_data (p, "conf_flags");
return flux_conf_get ("cmdhelp_pattern", *flags);
}

void usage (optparse_t *p)
{
const char *help_pattern = getenv ("FLUX_CMDHELP_PATTERN");
if (!help_pattern) {
int *flags = optparse_get_data (p, "conf_flags");
help_pattern = flux_conf_get ("cmdhelp_pattern", *flags);
}
assert (help_pattern != NULL);
char *help_pattern;
const char *val = getenv ("FLUX_CMDHELP_PATTERN");
const char *def = default_cmdhelp_pattern (p);

if (asprintf (&help_pattern, "%s%s%s",
def ? def : "",
val ? ":" : "",
val ? val : "") < 0)
err_exit ("faled to get command help list!");

optparse_print_usage (p);
fprintf (stderr, "\n");
Expand Down
5 changes: 3 additions & 2 deletions t/t0001-basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ test_expect_success 'flux-help command list can be extended' '
cat <<-EOF > help.d/test.json &&
[{ "category": "test", "command": "test", "description": "a test" }]
EOF
cat <<-EOF > help.expected &&
flux help 2>&1 | sed "0,/^$/d" >help.expected &&
cat <<-EOF >>help.expected &&
Common commands from flux-test:
test a test
EOF
Expand All @@ -121,7 +122,7 @@ test_expect_success 'flux-help command list can be extended' '
cat <<-EOF > help.d/test2.json &&
[{ "category": "test2", "command": "test2", "description": "a test two" }]
EOF
cat <<-EOF >> help.expected &&
cat <<-EOF >>help.expected &&
Common commands from flux-test2:
test2 a test two
Expand Down

0 comments on commit 20f1f2d

Please sign in to comment.