On Friday, 14 July 2017 15:39:22 CEST Richard W.M. Jones wrote:
+let lvs_has_S_opt = lazy (
+ let out = command "lvm" ["lvs"; "--help"] in
+ String.find out "-S" >= 0
+)
Could you please add the comment for this?
(* Check whether lvs has -S to filter its output.
* It is available only in lvm2 >= 2.02.107.
*)
+and convert_lvm_output ?(prefix = "") out =
+ let lines = String.nsplit "\n" out in
+
+ (* Skip leading and trailing ("pvs", I'm looking at you) whitespace. *)
+ let lines = List.map String.trim lines in
+
+ (* Skip empty lines. *)
+ let lines = List.filter ((<>) "") lines in
+
+ (* Ignore "unknown device" message (RHBZ#1054761). *)
+ let lines = List.filter ((<>) "unknown device") lines in
+
+ (* Add a prefix? *)
+ let lines = List.map ((^) prefix) lines in
A small optimization here could be to avoid the map if the prefix is
empty:
let lines =
if prefix <> "" then List.map ((^) prefix) lines
else lines in
(or even not giving ?prefix a default value, and matching on None/Some)
--
Pino Toscano