From 4c50f4c38d9a50fbf983c79dd208d1b1598fef8a Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Tue, 6 Apr 2010 23:54:08 +0100 Subject: [PATCH] fish: Print extended help when the user types an unknown command first. $ guestfish /tmp/disk.img /tmp/disk.img: unknown command Did you mean to open a disk image? guestfish -a disk.img For a list of commands: guestfish -h For complete documentation: man guestfish --- fish/fish.c | 19 +++++++++++++++++++ fish/fish.h | 2 ++ src/generator.ml | 2 ++ 3 files changed, 23 insertions(+) diff --git a/fish/fish.c b/fish/fish.c index 2022ee3..bd13a82 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -73,6 +73,7 @@ int echo_commands = 0; int remote_control_listen = 0; int remote_control = 0; int exit_on_error = 1; +int command_num = 0; int launch (guestfs_h *_g) @@ -790,6 +791,9 @@ issue_command (const char *cmd, char *argv[], const char *pipecmd) int pid = 0; int i, r; + /* This counts the commands issued, starting at 1. */ + command_num++; + if (echo_commands) { printf ("%s", cmd); for (i = 0; argv[i] != NULL; ++i) @@ -1073,6 +1077,21 @@ display_builtin_command (const char *cmd) cmd); } +/* This is printed when the user types in an unknown command for the + * first command issued. A common case is the user doing: + * guestfish disk.img + * expecting guestfish to open 'disk.img' (in fact, this tried to + * run a command 'disk.img'). + */ +void +extended_help_message (void) +{ + fprintf (stderr, + _("Did you mean to open a disk image? guestfish -a disk.img\n" + "For a list of commands: guestfish -h\n" + "For complete documentation: man guestfish\n")); +} + void free_strings (char **argv) { diff --git a/fish/fish.h b/fish/fish.h index c4b1a45..06b8de5 100644 --- a/fish/fish.h +++ b/fish/fish.h @@ -51,6 +51,7 @@ extern guestfs_h *g; extern int quit; extern int verbose; +extern int command_num; extern int issue_command (const char *cmd, char *argv[], const char *pipe); extern void pod2text (const char *name, const char *shortdesc, const char *body); extern void list_builtin_commands (void); @@ -64,6 +65,7 @@ extern int is_true (const char *str); extern char **parse_string_list (const char *str); extern int xwrite (int fd, const void *buf, size_t len); extern char *resolve_win_path (const char *path); +extern void extended_help_message (void); /* in cmds.c (auto-generated) */ extern void list_commands (void); diff --git a/src/generator.ml b/src/generator.ml index f206be1..416a66f 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -7403,6 +7403,8 @@ and generate_fish_cmds () = ) all_functions; pr " {\n"; pr " fprintf (stderr, _(\"%%s: unknown command\\n\"), cmd);\n"; + pr " if (command_num == 1)\n"; + pr " extended_help_message ();\n"; pr " return -1;\n"; pr " }\n"; pr " return 0;\n"; -- 1.8.3.1