[Libguestfs] [PATCH 12/13] fish: edit: add verbose parameter

Pino Toscano ptoscano at redhat.com
Thu Aug 28 13:21:56 UTC 2014


---
 edit/edit.c      |  4 ++--
 fish/edit.c      |  2 +-
 fish/file-edit.c | 10 ++++++++--
 fish/file-edit.h |  5 +++--
 4 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/edit/edit.c b/edit/edit.c
index 70ee129..f1c3b91 100644
--- a/edit/edit.c
+++ b/edit/edit.c
@@ -332,7 +332,7 @@ edit (const char *filename, const char *root)
   }
 
   if (perl_expr != NULL) {
-    r = edit_file_perl (g, filename, perl_expr, backup_extension);
+    r = edit_file_perl (g, filename, perl_expr, backup_extension, verbose);
   } else {
     const char *editor;
 
@@ -340,7 +340,7 @@ edit (const char *filename, const char *root)
     if (editor == NULL)
       editor = "vi";
 
-    r = edit_file_editor (g, filename, editor, backup_extension);
+    r = edit_file_editor (g, filename, editor, backup_extension, verbose);
   }
 
   switch (r) {
diff --git a/fish/edit.c b/fish/edit.c
index f43ef3b..0f41a88 100644
--- a/fish/edit.c
+++ b/fish/edit.c
@@ -58,7 +58,7 @@ run_edit (const char *cmd, size_t argc, char *argv[])
   if (remotefilename == NULL)
     return -1;
 
-  r = edit_file_editor (g, remotefilename, editor, NULL);
+  r = edit_file_editor (g, remotefilename, editor, NULL, 0 /* not verbose */);
 
   return r == -1 ? -1 : 0;
 }
diff --git a/fish/file-edit.c b/fish/file-edit.c
index fa68626..ff36ac2 100644
--- a/fish/file-edit.c
+++ b/fish/file-edit.c
@@ -41,7 +41,7 @@ static char *generate_backup_name (const char *filename,
 
 int
 edit_file_editor (guestfs_h *g, const char *filename, const char *editor,
-                  const char *backup_extension)
+                  const char *backup_extension, int verbose)
 {
   CLEANUP_FREE char *tmpdir = guestfs_get_tmpdir (g);
   CLEANUP_UNLINK_FREE char *tmpfilename = NULL;
@@ -105,6 +105,9 @@ edit_file_editor (guestfs_h *g, const char *filename, const char *editor,
     return -1;
   }
 
+  if (verbose)
+    fprintf (stderr, "%s\n", cmd);
+
   r = system (cmd);
   if (r == -1 || WEXITSTATUS (r) != 0) {
     perror (cmd);
@@ -161,7 +164,7 @@ edit_file_editor (guestfs_h *g, const char *filename, const char *editor,
 
 int
 edit_file_perl (guestfs_h *g, const char *filename, const char *perl_expr,
-                const char *backup_extension)
+                const char *backup_extension, int verbose)
 {
   CLEANUP_FREE char *tmpdir = guestfs_get_tmpdir (g);
   CLEANUP_UNLINK_FREE char *tmpfilename = NULL;
@@ -223,6 +226,9 @@ edit_file_perl (guestfs_h *g, const char *filename, const char *perl_expr,
     return -1;
   }
 
+  if (verbose)
+    fprintf (stderr, "%s\n", cmd);
+
   r = system (cmd);
   if (r == -1 || WEXITSTATUS (r) != 0)
     return -1;
diff --git a/fish/file-edit.h b/fish/file-edit.h
index 98fc453..3f8b95e 100644
--- a/fish/file-edit.h
+++ b/fish/file-edit.h
@@ -30,7 +30,8 @@
  * the file (e.g. the user closed the editor without saving).
  */
 extern int edit_file_editor (guestfs_h *g, const char *filename,
-                             const char *editor, const char *backup_extension);
+                             const char *editor, const char *backup_extension,
+                             int verbose);
 
 /**
  * Edit 'filename' running the specified 'perl_expr' using Perl.
@@ -41,6 +42,6 @@ extern int edit_file_editor (guestfs_h *g, const char *filename,
  */
 extern int edit_file_perl (guestfs_h *g, const char *filename,
                            const char *perl_expr,
-                           const char *backup_extension);
+                           const char *backup_extension, int verbose);
 
 #endif
-- 
1.9.3




More information about the Libguestfs mailing list