[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH] sparsify: Make the interface between cmdline.ml and sparsify.ml explicit.



We could go a bit further here and push the cmdline struct
into Copying.run and In_place.run.
---
 sparsify/Makefile.am |  5 ++++-
 sparsify/cmdline.ml  | 23 +++++++++++++++++++----
 sparsify/cmdline.mli | 36 ++++++++++++++++++++++++++++++++++++
 sparsify/sparsify.ml | 13 +++++++------
 4 files changed, 66 insertions(+), 11 deletions(-)
 create mode 100644 sparsify/cmdline.mli

diff --git a/sparsify/Makefile.am b/sparsify/Makefile.am
index 33f418b..d99f311 100644
--- a/sparsify/Makefile.am
+++ b/sparsify/Makefile.am
@@ -18,13 +18,16 @@
 include $(top_srcdir)/subdir-rules.mk
 
 EXTRA_DIST = \
-	$(SOURCES_ML) $(SOURCES_C) \
+	$(SOURCES_MLI) $(SOURCES_ML) $(SOURCES_C) \
 	virt-sparsify.pod \
 	test-virt-sparsify.sh \
 	test-virt-sparsify-in-place.sh
 
 CLEANFILES = *~ *.annot *.cmi *.cmo *.cmx *.cmxa *.o virt-sparsify
 
+SOURCES_MLI = \
+	cmdline.mli
+
 SOURCES_ML = \
 	utils.ml \
 	cmdline.ml \
diff --git a/sparsify/cmdline.ml b/sparsify/cmdline.ml
index 868456f..8f2b721 100644
--- a/sparsify/cmdline.ml
+++ b/sparsify/cmdline.ml
@@ -25,9 +25,18 @@ open Common_utils
 
 open Utils
 
-type mode_t =
-| Mode_copying of string * check_t * bool * string option * string option *
-    string option
+type cmdline = {
+  indisk : string;
+  format : string option;
+  ignores : string list;
+  machine_readable : bool;
+  zeroes : string list;
+  mode : mode_t;
+}
+
+and mode_t =
+| Mode_copying of
+    string * check_t * bool * string option * string option * string option
 | Mode_in_place
 and check_t = [`Ignore|`Continue|`Warn|`Fail]
 
@@ -175,4 +184,10 @@ read the man page virt-sparsify(1).
     else
       Mode_in_place in
 
-  indisk, format, ignores, machine_readable, zeroes, mode
+  { indisk = indisk;
+    format = format;
+    ignores = ignores;
+    machine_readable = machine_readable;
+    zeroes = zeroes;
+    mode = mode;
+  }
diff --git a/sparsify/cmdline.mli b/sparsify/cmdline.mli
new file mode 100644
index 0000000..706ecc9
--- /dev/null
+++ b/sparsify/cmdline.mli
@@ -0,0 +1,36 @@
+(* virt-sparsify
+ * Copyright (C) 2011-2015 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+(** Command line argument parsing. *)
+
+type cmdline = {
+  indisk : string;
+  format : string option;
+  ignores : string list;
+  machine_readable : bool;
+  zeroes : string list;
+  mode : mode_t;
+}
+
+and mode_t =
+| Mode_copying of
+    string * check_t * bool * string option * string option * string option
+| Mode_in_place
+and check_t = [`Ignore|`Continue|`Warn|`Fail]
+
+val parse_cmdline : unit -> cmdline
diff --git a/sparsify/sparsify.ml b/sparsify/sparsify.ml
index 30e3020..b40dbf4 100644
--- a/sparsify/sparsify.ml
+++ b/sparsify/sparsify.ml
@@ -30,15 +30,16 @@ module G = Guestfs
 let () = Random.self_init ()
 
 let rec main () =
-  let indisk, format, ignores, machine_readable, zeroes, mode =
-    parse_cmdline () in
+  let cmdline = parse_cmdline () in
 
-  (match mode with
+  (match cmdline.mode with
   | Mode_copying (outdisk, check_tmpdir, compress, convert, option, tmp) ->
-    Copying.run indisk outdisk check_tmpdir compress convert
-      format ignores machine_readable option tmp zeroes
+    Copying.run cmdline.indisk outdisk check_tmpdir compress convert
+                cmdline.format cmdline.ignores cmdline.machine_readable
+                option tmp cmdline.zeroes
   | Mode_in_place ->
-    In_place.run indisk format ignores machine_readable zeroes
+    In_place.run cmdline.indisk cmdline.format cmdline.ignores
+                 cmdline.machine_readable cmdline.zeroes
   )
 
 let () = run_main_and_handle_errors main
-- 
2.5.0


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]