From: Richard W.M. Jones Date: Sat, 11 Jul 2009 20:35:03 +0000 (+0100) Subject: Guestfish: implement -x option, echo commands before executing them. X-Git-Tag: 1.0.59~17 X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=commitdiff_plain;h=ad64aff8342198f11cf7d8ffff148a9cd5afe6ce Guestfish: implement -x option, echo commands before executing them. --- diff --git a/fish/fish.c b/fish/fish.c index 132b59e..a093395 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -68,6 +68,7 @@ guestfs_h *g; int read_only = 0; int quit = 0; int verbose = 0; +int echo_commands = 0; int launch (guestfs_h *_g) @@ -112,6 +113,7 @@ usage (void) " -n|--no-sync Don't autosync\n" " -r|--ro Mount read-only\n" " -v|--verbose Verbose messages\n" + " -x Echo each command before executing it\n" " -V|--version Display version and exit\n" "For more information, see the manpage guestfish(1).\n")); } @@ -119,7 +121,7 @@ usage (void) int main (int argc, char *argv[]) { - static const char *options = "a:Df:h::im:nrv?V"; + static const char *options = "a:Df:h::im:nrv?Vx"; static struct option long_options[] = { { "add", 1, 0, 'a' }, { "cmd-help", 2, 0, 'h' }, @@ -252,6 +254,10 @@ main (int argc, char *argv[]) printf ("guestfish %s\n", PACKAGE_VERSION); exit (0); + case 'x': + echo_commands = 1; + break; + case '?': usage (); exit (0); @@ -663,7 +669,14 @@ issue_command (const char *cmd, char *argv[], const char *pipecmd) int argc; int stdout_saved_fd = -1; int pid = 0; - int r; + int i, r; + + if (echo_commands) { + printf ("%s", cmd); + for (i = 0; argv[i] != NULL; ++i) + printf (" %s", argv[i]); + printf ("\n"); + } /* For | ... commands. Annoyingly we can't use popen(3) here. */ if (pipecmd) { diff --git a/guestfish.pod b/guestfish.pod index 442b333..e3ffe52 100644 --- a/guestfish.pod +++ b/guestfish.pod @@ -149,6 +149,10 @@ This changes the C<-m> option so that mounts are done read-only Enable very verbose messages. This is particularly useful if you find a bug. +=item B<-x> + +Echo each command before executing it. + =item B<-D> | B<--no-dest-paths> Don't tab-complete paths on the guest filesystem. It is useful to be