[netcf-devel] [PATCH 2/3] ncftool: Have 'ncftool --help' print command list

Cole Robinson crobinso at redhat.com
Sun Jan 31 00:59:53 UTC 2010


Signed-off-by: Cole Robinson <crobinso at redhat.com>
---
 src/ncftool.c |   25 ++++++++++++++++---------
 1 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/ncftool.c b/src/ncftool.c
index 28f97ca..66c590c 100644
--- a/src/ncftool.c
+++ b/src/ncftool.c
@@ -412,15 +412,21 @@ static const struct command_def cmd_undefine_def = {
     .help = "remove the configuration of an interface"
 };
 
+static void print_all_cmds(FILE *stream) {
+    fprintf(stream, "Commands:\n\n");
+    for (int i=0; commands[i]->name != NULL; i++) {
+        const struct command_def *def = commands[i];
+        fprintf(stream, "    %-10s - %s\n", def->name, def->synopsis);
+    }
+
+    fprintf(stream,
+            "\nType 'help <command>' for more information on a command\n\n");
+}
+
 static int cmd_help(const struct command *cmd) {
     const char *name = param_value(cmd, "command");
     if (name == NULL) {
-        printf("Commands:\n\n");
-        for (int i=0; commands[i]->name != NULL; i++) {
-            const struct command_def *def = commands[i];
-            printf("    %-10s - %s\n", def->name, def->synopsis);
-        }
-        printf("\nType 'help <command>' for more information on a command\n\n");
+        print_all_cmds(stdout);
     } else {
         const struct command_def *def = lookup_cmd_def(name);
         const struct command_opt_def *odef = NULL;
@@ -653,10 +659,11 @@ static void readline_init(void) {
 __attribute__((noreturn))
 static void usage(void) {
     fprintf(stderr, "Usage: %s [OPTIONS]\n", progname);
-    fprintf(stderr, "Interactive shell for netcf\n\n");
-    fprintf(stderr, "Type 'help' at the prompt to get a list of commands\n");
+    fprintf(stderr, "Interactive shell for netcf\n");
     fprintf(stderr, "\nOptions:\n\n");
-    fprintf(stderr, "  -r, --root ROOT    use ROOT as the root of the filesystem\n");
+    fprintf(stderr,
+            "  -r, --root ROOT    use ROOT as the root of the filesystem\n\n");
+    print_all_cmds(stderr);
 
     exit(EXIT_FAILURE);
 }
-- 
1.6.5.2



More information about the netcf-devel mailing list