cmd: Include aliases in help output
authorSimon Wilkinson <sxw@your-file-system.com>
Sun, 24 Apr 2011 19:28:02 +0000 (15:28 -0400)
committerDerrick Brashear <shadow@dementia.org>
Sun, 22 May 2011 14:02:33 +0000 (07:02 -0700)
Include any command aliases in the output from the -help option

Change-Id: Ifb2ac96d9ba6fc64bffff69bac9480a6b7e8568e
Reviewed-on: http://gerrit.openafs.org/4651
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>

src/cmd/cmd.c

index 0389188..3b97102 100644 (file)
@@ -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);