cmd: Tidy up -help output
authorSimon Wilkinson <sxw@your-file-system.com>
Tue, 19 Apr 2011 18:59:13 +0000 (19:59 +0100)
committerDerrick Brashear <shadow@dementia.org>
Wed, 27 Apr 2011 19:08:53 +0000 (12:08 -0700)
Tidy up the output that comes from cmd's -help option by wrapping
at 78 characters, and picking the breaks sensibly. This changes:

Usage: ./vos move -id <volume name or ID> -fromserver <machine name on source> -
frompartition <partition name on source> -toserver <machine name on destination>
 -topartition <partition name on destination> [-live] [-cell <cell name>] [-noau
th] [-localauth] [-verbose] [-encrypt] [-noresolve] [-help]

to...

Usage: ./vos move -id <volume name or ID>
         -fromserver <machine name on source>
         -frompartition <partition name on source>
         -toserver <machine name on destination>
         -topartition <partition name on destination> [-live]
         [-cell <cell name>] [-noauth] [-localauth] [-verbose]
         [-encrypt] [-noresolve] [-help]

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

src/bu_utils/Makefile.in
src/bu_utils/NTMakefile
src/butc/Makefile.in
src/cmd/cmd.c
src/venus/test/Makefile.in
src/vlserver/NTMakefile
tests/cmd/command-t.c

index cdfc90e..4330472 100644 (file)
@@ -22,7 +22,7 @@ FMSLIBS=${TOP_LIBDIR}/libcmd.a \
        ${TOP_LIBDIR}/util.a
 
 fms: fms.o
-       $(AFS_LDRULE) fms.o ${FMSLIBS}
+       $(AFS_LDRULE) fms.o ${FMSLIBS} $(LIB_roken)
 
 fms.o:  fms.c AFS_component_version_number.o
 
index 520ed05..e4b3526 100644 (file)
@@ -22,7 +22,8 @@ EXELIBS =\
        $(DESTDIR)\lib\afs\afscmd.lib \
        $(DESTDIR)\lib\afs\afsusd.lib \
        $(DESTDIR)\lib\afs\afsutil.lib \
-       $(DESTDIR)\lib\afs\afsprocmgmt.lib
+       $(DESTDIR)\lib\afs\afsprocmgmt.lib \
+       $(DESTDIR)\lib\afsroken.lib
        
 
 $(EXEFILE): $(EXEOBJS) $(EXELIBS)
index 5c93ed5..04f6a4f 100644 (file)
@@ -86,7 +86,7 @@ read_tape: read_tape.c
        $(CC) $(AFS_CPPFLAGS) $(AFS_CFLAGS) $(AFS_LDFLAGS) \
                -o read_tape ${srcdir}/read_tape.c \
                ${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/libusd.a \
-               ${TOP_LIBDIR}/util.a
+               ${TOP_LIBDIR}/util.a $(LIB_roken)
 
 # Errors
 CFLAGS_tcudbprocs.o=@CFLAGS_NOERROR@
index 76061f6..204508d 100644 (file)
@@ -160,23 +160,20 @@ FindSyntax(char *aname, int *aambig)
 }
 
 /* print the help for a single parameter */
-static void
-PrintParmHelp(struct cmd_parmdesc *aparm)
+static char *
+ParmHelpString(struct cmd_parmdesc *aparm)
 {
+    char *str;
     if (aparm->type == CMD_FLAG) {
-#ifdef notdef
-       /* doc people don't like seeing this information */
-       if (aparm->help)
-           printf(" (%s)", aparm->help);
-#endif
-    } else if (aparm->help) {
-       printf(" <%s>", aparm->help);
-       if (aparm->type == CMD_LIST)
-           printf("+");
-    } else if (aparm->type == CMD_SINGLE)
-       printf(" <arg>");
-    else if (aparm->type == CMD_LIST)
-       printf(" <arg>+");
+       return strdup("");
+    } else {
+       asprintf(&str, " %s<%s>%s%s",
+                aparm->type == CMD_SINGLE_OR_FLAG?"[":"",
+                aparm->help?aparm->help:"arg",
+                aparm->type == CMD_LIST?"+":"",
+                aparm->type == CMD_SINGLE_OR_FLAG?"]":"");
+       return str;
+    }
 }
 
 extern char *AFSVersion;
@@ -193,30 +190,48 @@ PrintSyntax(struct cmd_syndesc *as)
 {
     int i;
     struct cmd_parmdesc *tp;
+    char *str;
+    size_t len;
+    size_t xtralen;
 
     /* now print usage, from syntax table */
     if (noOpcodes)
-       printf("Usage: %s", as->a0name);
+       asprintf(&str, "Usage: %s", as->a0name);
     else {
        if (!strcmp(as->name, initcmd_opcode))
-           printf("Usage: %s[%s]", NName(as->a0name, " "), as->name);
+           asprintf(&str, "Usage: %s[%s]", NName(as->a0name, " "), as->name);
        else
-           printf("Usage: %s%s", NName(as->a0name, " "), as->name);
+           asprintf(&str, "Usage: %s%s", NName(as->a0name, " "), as->name);
     }
 
+    len = strlen(str);
+    printf("%s", str);
+    free(str);
+
     for (i = 0; i < CMD_MAXPARMS; i++) {
        tp = &as->parms[i];
        if (tp->type == 0)
            continue;           /* seeked over slot */
        if (tp->flags & CMD_HIDE)
            continue;           /* skip hidden options */
-       printf(" ");
-       if (tp->flags & CMD_OPTIONAL)
-           printf("[");
-       printf("%s", tp->name);
-       PrintParmHelp(tp);
-       if (tp->flags & CMD_OPTIONAL)
-           printf("]");
+       /* 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) +
+                 ((tp->flags & CMD_OPTIONAL)? 2: 0);
+
+       if (len + xtralen > 78) {
+           printf("\n        ");
+           len = 8;
+       }
+
+       printf(" %s%s%s%s",
+              tp->flags & CMD_OPTIONAL?"[":"",
+              tp->name,
+              str,
+              tp->flags & CMD_OPTIONAL?"]":"");
+       free(str);
+       len+=xtralen;
     }
     printf("\n");
 }
index 78d6192..38a0bec 100644 (file)
@@ -18,7 +18,7 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
 INCDIRS= -I${TOP_OBJDIR}/src/config -I${TOP_INCDIR} -I..
 LDIRS= -L${TOP_LIBDIR} -L..
 LIBS= -lsys -lubik -lvldb -lauth -lrxkad -lafshcrypto_lwp \
-      -lafscom_err -lcmd -lrx -llwp -lafsutil
+      -lafscom_err -lcmd -lrx -llwp -lafsutil $(LIB_roken)
 
 all test:  fulltest owntest idtest getinitparams
 
index 70e7687..e809a13 100644 (file)
@@ -140,7 +140,8 @@ VLDB_CHECK_LIBS =\
        $(DESTDIR)\lib\afs\afsutil.lib  \
        $(DESTDIR)\lib\afs\afsreg.lib \
        $(DESTDIR)\lib\afs\afseventlog.lib \
-       $(DESTDIR)\lib\afs\afscmd.lib
+       $(DESTDIR)\lib\afs\afscmd.lib \
+       $(DESTDIR)\lib\afsroken.lib
 
 $(OUT)\vldb_check.exe: $(OUT)\vldb_check.obj $(VLDB_CHECK_LIBS)
        $(EXECONLINK)
@@ -152,7 +153,8 @@ $(OUT)\vldb_check.exe: $(OUT)\vldb_check.obj $(VLDB_CHECK_LIBS)
 # build local vlclient
 VLCLIENT_LIBS = \
        $(DESTDIR)\lib\afs\afscmd.lib \
-       $(DESTDIR)\lib\afs\afspioctl.lib
+       $(DESTDIR)\lib\afs\afspioctl.lib \
+       $(DESTDIR)\lib\afsroken.lib
 
 $(OUT)\vlclient.exe: $(OUT)\vlclient.obj  $(LIBFILE) $(VLSERVER_EXECLIBS) $(VLCLIENT_LIBS)
        $(EXECONLINK) dnsapi.lib mpr.lib iphlpapi.lib shell32.lib
index aec9c8a..835147e 100644 (file)
@@ -59,7 +59,7 @@ main(int argc, char **argv)
     int retval;
     char *retstring;
 
-    plan(70);
+    plan(73);
 
     initialize_CMD_error_table();
 
@@ -261,6 +261,14 @@ main(int argc, char **argv)
     cmd_FreeOptions(&retopts);
     cmd_FreeArgv(tv);
 
+    /* Check that we can produce help output */
+    code = cmd_ParseLine("-help", tv, &tc, 100);
+    is_int(0, code, "cmd_ParseLine succeeds");
+    code = cmd_Parse(tc, tv, &retopts);
+    is_int(CMD_USAGE, code, "cmd_Parse returns usage error with help output");
+    ok(retopts == NULL, " ... and options is empty");
+    cmd_FreeArgv(tv);
+
     return 0;
 }