From: Simon Wilkinson Date: Sun, 24 Apr 2011 19:28:02 +0000 (-0400) Subject: cmd: Include aliases in help output X-Git-Tag: openafs-devel-1_7_1~473 X-Git-Url: http://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=98a4a5498f39e242b4cd933694a4626e208f43c6 cmd: Include aliases in help output Include any command aliases in the output from the -help option Change-Id: Ifb2ac96d9ba6fc64bffff69bac9480a6b7e8568e Reviewed-on: http://gerrit.openafs.org/4651 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- diff --git a/src/cmd/cmd.c b/src/cmd/cmd.c index 0389188..3b97102 100644 --- a/src/cmd/cmd.c +++ b/src/cmd/cmd.c @@ -191,6 +191,7 @@ PrintSyntax(struct cmd_syndesc *as) int i; struct cmd_parmdesc *tp; char *str; + char *name; size_t len; size_t xtralen; @@ -214,10 +215,30 @@ PrintSyntax(struct cmd_syndesc *as) continue; /* seeked over slot */ if (tp->flags & CMD_HIDE) continue; /* skip hidden options */ + + /* The parameter name is the real name, plus any aliases */ + if (!tp->aliases) { + name = strdup(tp->name); + } else { + size_t namelen; + struct cmd_item *alias; + namelen = strlen(tp->name) + 1; + for (alias = tp->aliases; alias != NULL; alias = alias->next) + namelen+=strlen(alias->data) + 3; + + name = malloc(namelen); + strlcpy(name, tp->name, namelen); + + for (alias = tp->aliases; alias != NULL; alias = alias->next) { + strlcat(name, " | ", namelen); + strlcat(name, alias->data, namelen); + } + } + /* Work out if we can fit what we want to on this line, or if we need to * start a new one */ str = ParmHelpString(tp); - xtralen = 1 + strlen(tp->name) + strlen(str) + + xtralen = 1 + strlen(name) + strlen(str) + ((tp->flags & CMD_OPTIONAL)? 2: 0); if (len + xtralen > 78) { @@ -227,7 +248,7 @@ PrintSyntax(struct cmd_syndesc *as) printf(" %s%s%s%s", tp->flags & CMD_OPTIONAL?"[":"", - tp->name, + name, str, tp->flags & CMD_OPTIONAL?"]":""); free(str);