summaryrefslogtreecommitdiffstats
path: root/sysprep
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-04-11 16:20:23 +0100
committerRichard W.M. Jones <rjones@redhat.com>2012-04-11 16:26:32 +0100
commit16b2ffa97ea8b2872306bc4400605821440f6589 (patch)
tree931d942815f2fc0b47ae56805edff5973a86359b /sysprep
parenta3d6629a0b54aca6d7b5b38750399b5396cdbf07 (diff)
downloadlibguestfs-16b2ffa97ea8b2872306bc4400605821440f6589.tar.gz
libguestfs-16b2ffa97ea8b2872306bc4400605821440f6589.tar.xz
libguestfs-16b2ffa97ea8b2872306bc4400605821440f6589.zip
sysprep: Make a common Utils.compare_command_line_args function.
This isn't quite code motion, since the new function also ignores case (which previously we didn't ignore).
Diffstat (limited to 'sysprep')
-rw-r--r--sysprep/sysprep_operation.ml6
-rw-r--r--sysprep/utils.ml3
-rw-r--r--sysprep/utils.mli5
3 files changed, 10 insertions, 4 deletions
diff --git a/sysprep/sysprep_operation.ml b/sysprep/sysprep_operation.ml
index a77b66d2..b48d8f8b 100644
--- a/sysprep/sysprep_operation.ml
+++ b/sysprep/sysprep_operation.ml
@@ -138,10 +138,8 @@ let dump_pod_options () =
| Arg.Rest _ -> assert false (* XXX not implemented *)
) args in
- let args = List.sort (
- fun (a, _) (b, _) ->
- compare (skip_dashes a) (skip_dashes b)
- ) args in
+ let args =
+ List.sort (fun (a, _) (b, _) -> compare_command_line_args a b) args in
List.iter (
fun (arg_name, (op_name, heading, pod)) ->
diff --git a/sysprep/utils.ml b/sysprep/utils.ml
index ad265984..003ae865 100644
--- a/sysprep/utils.ml
+++ b/sysprep/utils.ml
@@ -81,3 +81,6 @@ let skip_dashes str =
let i = loop 0 in
if i = 0 then str
else String.sub str i (n-i)
+
+let compare_command_line_args a b =
+ compare (String.lowercase (skip_dashes a)) (String.lowercase (skip_dashes b))
diff --git a/sysprep/utils.mli b/sysprep/utils.mli
index 51426f44..2b7e3208 100644
--- a/sysprep/utils.mli
+++ b/sysprep/utils.mli
@@ -44,3 +44,8 @@ val skip_dashes : string -> string
If the string contains only dash characters, this raises
[Invalid_argument "skip_dashes"]. *)
+
+val compare_command_line_args : string -> string -> int
+(** Compare two command line arguments (eg. ["-a"] and ["--V"]),
+ ignoring leading dashes and case. Note this assumes the
+ strings are 7 bit ASCII. *)