---
sysprep/main.ml | 6 ++++++
sysprep/sysprep_operation.ml | 13 +++++++++++++
sysprep/sysprep_operation.mli | 9 +++++++++
3 files changed, 28 insertions(+)
diff --git a/sysprep/main.ml b/sysprep/main.ml
index 5d64538..4919783 100644
--- a/sysprep/main.ml
+++ b/sysprep/main.ml
@@ -221,6 +221,12 @@ read the man page virt-sysprep(1).
let trace = !trace in
let verbose = !verbose in
+ (* At this point we know which operations are enabled. So call the
+ * not_enabled_check_args method of all *disabled* operations, so
+ * they have a chance to check for unused command line args.
+ *)
+ Sysprep_operation.not_enabled_check_args ?operations ();
+
(* Parse the mount options string into a function that maps the
* mountpoint to the mount options.
*)
diff --git a/sysprep/sysprep_operation.ml b/sysprep/sysprep_operation.ml
index 19ccfe0..09231cb 100644
--- a/sysprep/sysprep_operation.ml
+++ b/sysprep/sysprep_operation.ml
@@ -43,6 +43,7 @@ type operation = {
pod_description : string option;
pod_notes : string option;
extra_args : extra_arg list;
+ not_enabled_check_args : unit -> unit;
perform_on_filesystems : filesystem_side_effects callback option;
perform_on_devices : device_side_effects callback option;
}
@@ -60,6 +61,7 @@ let defaults = {
pod_description = None;
pod_notes = None;
extra_args = [];
+ not_enabled_check_args = (fun () -> ());
perform_on_filesystems = None;
perform_on_devices = None;
}
@@ -272,6 +274,17 @@ let list_operations () =
op.heading
) !all_operations
+let not_enabled_check_args ?operations () =
+ let enabled_ops =
+ match operations with
+ | None -> !enabled_by_default_operations
+ | Some opset -> (* just the operation names listed *)
+ OperationSet.elements opset in
+ let all_ops = opset_of_oplist !all_operations in
+ let enabled_ops = opset_of_oplist enabled_ops in
+ let disabled_ops = OperationSet.diff all_ops enabled_ops in
+ OperationSet.iter (fun op -> op.not_enabled_check_args ()) disabled_ops
+
let compare_operations { order = o1; name = n1 } { order = o2; name = n2 } =
let i = compare o1 o2 in
if i <> 0 then i else compare n1 n2
diff --git a/sysprep/sysprep_operation.mli b/sysprep/sysprep_operation.mli
index c2057ed..d10ef1e 100644
--- a/sysprep/sysprep_operation.mli
+++ b/sysprep/sysprep_operation.mli
@@ -73,6 +73,11 @@ type operation = {
You can decide the types of the arguments, whether they are
mandatory etc. *)
+ not_enabled_check_args : unit -> unit;
+ (** If the operation is [not] enabled (or disabled), this function is
+ called after argument parsing and can be used to check that
+ no useless extra_args were passed by the user. *)
+
perform_on_filesystems : filesystem_side_effects callback option;
(** The function which is called to perform this operation, when
enabled.
@@ -169,6 +174,10 @@ val remove_all_from_set : set -> set
(** [remove_all_from_set set] removes from [set] all the available
operations. *)
+val not_enabled_check_args : ?operations:set -> unit -> unit
+(** Call [not_enabled_check_args] on all operations in the set
+ which are {i not} enabled. *)
+
val perform_operations_on_filesystems : ?operations:set -> verbose:bool ->
quiet:bool -> Guestfs.guestfs -> string -> filesystem_side_effects -> unit
(** Perform all operations, or the subset listed in the [operations] set. *)
--
2.0.4