Added guestfish 'echo' command.
[libguestfs.git] / fish / fish.c
index c8e9506..fcafb5c 100644 (file)
@@ -100,13 +100,14 @@ usage (void)
           "  -n|--no-sync         Don't autosync\n"
           "  -r|--ro              Mount read-only\n"
           "  -v|--verbose         Verbose messages\n"
+          "  -V|--version         Display version and exit\n"
           "For more information,  see the manpage guestfish(1).\n");
 }
 
 int
 main (int argc, char *argv[])
 {
-  static const char *options = "a:h::m:nrv?";
+  static const char *options = "a:h::m:nrv?V";
   static struct option long_options[] = {
     { "add", 1, 0, 'a' },
     { "cmd-help", 2, 0, 'h' },
@@ -115,6 +116,7 @@ main (int argc, char *argv[])
     { "no-sync", 0, 0, 'n' },
     { "ro", 0, 0, 'r' },
     { "verbose", 0, 0, 'v' },
+    { "version", 0, 0, 'V' },
     { 0, 0, 0, 0 }
   };
   struct mp *mps = NULL;
@@ -200,6 +202,10 @@ main (int argc, char *argv[])
       guestfs_set_verbose (g, verbose);
       break;
 
+    case 'V':
+      printf ("guestfish %s\n", PACKAGE_VERSION);
+      exit (0);
+
     case '?':
       usage ();
       exit (0);
@@ -348,6 +354,11 @@ script (int prompt)
     while (*buf && isspace (*buf))
       buf++;
 
+    if (!*buf) continue;
+
+    /* If the next character is '#' then this is a comment. */
+    if (*buf == '#') continue;
+
     /* Get the command (cannot be quoted). */
     len = strcspn (buf, " \t");
 
@@ -512,6 +523,8 @@ issue_command (const char *cmd, char *argv[])
   else if (strcasecmp (cmd, "alloc") == 0 ||
           strcasecmp (cmd, "allocate") == 0)
     return do_alloc (cmd, argc, argv);
+  else if (strcasecmp (cmd, "echo") == 0)
+    return do_echo (cmd, argc, argv);
   else if (strcasecmp (cmd, "edit") == 0 ||
           strcasecmp (cmd, "vi") == 0 ||
           strcasecmp (cmd, "emacs") == 0)
@@ -532,6 +545,8 @@ list_builtin_commands (void)
   printf ("%-20s %s\n",
          "alloc", "allocate an image");
   printf ("%-20s %s\n",
+         "echo", "display a line of text");
+  printf ("%-20s %s\n",
          "edit", "edit a file in the image");
 
   /* actions are printed after this (see list_commands) */
@@ -559,6 +574,11 @@ display_builtin_command (const char *cmd)
            "    <nn>M or <nn>MB  number of megabytes\n"
            "    <nn>G or <nn>GB  number of gigabytes\n"
            "    <nn>sects        number of 512 byte sectors\n");
+  else if (strcasecmp (cmd, "echo") == 0)
+    printf ("echo - display a line of text\n"
+           "     echo [<params> ...]\n"
+           "\n"
+           "    This echos the parameters to the terminal.\n");
   else if (strcasecmp (cmd, "edit") == 0 ||
           strcasecmp (cmd, "vi") == 0 ||
           strcasecmp (cmd, "emacs") == 0)