Move the make_dib_args helper function to Common_utils as
stringify_args, so it can be used also within Common_utils itself.
This is mostly code motion.
---
dib/dib.ml | 12 +-----------
mllib/common_utils.ml | 10 ++++++++++
mllib/common_utils.mli | 4 ++++
3 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/dib/dib.ml b/dib/dib.ml
index b988f14..a76eb5e 100644
--- a/dib/dib.ml
+++ b/dib/dib.ml
@@ -53,16 +53,6 @@ let read_dib_envvars () =
let vars = List.map (fun x -> x ^ "\n") vars in
String.concat "" vars
-let make_dib_args args =
- let args = Array.to_list args in
- let rec quote_args = function
- | [] -> ""
- | x :: xs -> " " ^ (quote x) ^ quote_args xs
- in
- match args with
- | [] -> ""
- | app :: xs -> app ^ quote_args xs
-
let write_script fn text =
let oc = open_out fn in
output_string oc text;
@@ -507,7 +497,7 @@ let main () =
printf " (none)\n";
printf "\n";
);
- let dib_args = make_dib_args Sys.argv in
+ let dib_args = stringify_args Sys.argv in
let dib_vars = read_dib_envvars () in
if debug >= 1 then (
printf "DIB args:\n%s\n" dib_args;
diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
index d1aa8d2..0332510 100644
--- a/mllib/common_utils.ml
+++ b/mllib/common_utils.ml
@@ -648,6 +648,16 @@ let compare_lvm2_uuids uuid1 uuid2 =
in
loop 0 0
+let stringify_args args =
+ let args = Array.to_list args in
+ let rec quote_args = function
+ | [] -> ""
+ | x :: xs -> " " ^ (Filename.quote x) ^ quote_args xs
+ in
+ match args with
+ | [] -> ""
+ | app :: xs -> app ^ quote_args xs
+
(* Run an external command, slurp up the output as a list of lines. *)
let external_command ?(echo_cmd = true) cmd =
if echo_cmd then
diff --git a/mllib/common_utils.mli b/mllib/common_utils.mli
index 7f288b4..5bcc692 100644
--- a/mllib/common_utils.mli
+++ b/mllib/common_utils.mli
@@ -239,6 +239,10 @@ val compare_version : string -> string -> int
val compare_lvm2_uuids : string -> string -> int
(** Compare two LVM2 UUIDs, ignoring '-' characters. *)
+val stringify_args : string array -> string
+(** Create a "pretty-print" representation of a program invocation
+ (i.e. executable and its arguments). *)
+
val external_command : ?echo_cmd:bool -> string -> string list
(** Run an external command, slurp up the output as a list of lines.
--
2.5.5