smbtorture: Enhance shell "help" command.
authorJames Peach <jpeach@samba.org>
Mon, 22 Mar 2010 05:04:37 +0000 (22:04 -0700)
committerJames Peach <jpeach@apple.com>
Mon, 21 Jun 2010 15:58:10 +0000 (08:58 -0700)
Sort the command list alphabetically. Let the help command print
usage info for other commands.

source4/torture/shell.c

index a0f9d7d3a3e9ff27ff993cbc3f0a05011b8f5e83..888097de7fa4657110ba6410bd8200e63588427f 100644 (file)
@@ -58,13 +58,14 @@ struct shell_command
 static const struct shell_command commands[] =
 {
     {
-       shell_help, "help", NULL,
-       "print this help message"
+       shell_auth, "auth",
+       "[[username | principal | domain | realm | password] STRING]",
+       "set authentication parameters"
     },
 
     {
-       shell_quit, "quit", NULL,
-       "exit smbtorture"
+       shell_help, "help", NULL,
+       "print this help message"
     },
 
     {
@@ -73,8 +74,8 @@ static const struct shell_command commands[] =
     },
 
     {
-       shell_set, "set", "[NAME VALUE]",
-       "print or set test configuration parameters"
+       shell_quit, "quit", NULL,
+       "exit smbtorture"
     },
 
     {
@@ -83,10 +84,10 @@ static const struct shell_command commands[] =
     },
 
     {
-       shell_auth, "auth",
-       "[[username | principal | domain | realm | password] STRING]",
-       "set authentication parameters"
+       shell_set, "set", "[NAME VALUE]",
+       "print or set test configuration parameters"
     }
+
 };
 
 void torture_shell(struct torture_context *tctx)
@@ -147,10 +148,19 @@ static void shell_help(const struct shell_command * command,
 {
     int i;
 
-    fprintf(stdout, "Available commands:\n");
-    for (i = 0; i < ARRAY_SIZE(commands); i++) {
-           fprintf(stdout, "\t%s - %s\n",
-                   commands[i].name, commands[i].help);
+    if (argc == 1) {
+           for (i = 0; i < ARRAY_SIZE(commands); i++) {
+                   if (match_command(argv[0], &commands[i])) {
+                           shell_usage(&commands[i]);
+                           return;
+                   }
+           }
+    } else {
+           fprintf(stdout, "Available commands:\n");
+           for (i = 0; i < ARRAY_SIZE(commands); i++) {
+                   fprintf(stdout, "\t%s - %s\n",
+                           commands[i].name, commands[i].help);
+           }
     }
 }