mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
generator: Add a function to find an action by name.
Fairly simple refactoring.
This commit is contained in:
@@ -187,3 +187,8 @@ let fish_functions = List.filter is_fish
|
||||
* alphabetically, so this is useful:
|
||||
*)
|
||||
let sort = List.sort action_compare
|
||||
|
||||
(* Find a single action by name, or give an error. *)
|
||||
let find name =
|
||||
try List.find (fun { name = n } -> n = name) actions
|
||||
with Not_found -> failwithf "could not find action named '%s'" name
|
||||
|
||||
@@ -47,6 +47,10 @@ val sort : Types.action list -> Types.action list
|
||||
(** Sort the functions alphabetically by name
|
||||
(see also {!Utils.action_compare}). *)
|
||||
|
||||
val find : string -> Types.action
|
||||
(** Find an action by name. If it doesn't exist, this fails with an
|
||||
error. *)
|
||||
|
||||
val is_documented : Types.action -> bool
|
||||
(** Returns true if function should be documented, false otherwise. *)
|
||||
|
||||
|
||||
@@ -380,10 +380,7 @@ and generate_test_command_call ?(expect_error = false) ?(do_return = true) ?test
|
||||
match cmd with [] -> assert false | name :: args -> name, args in
|
||||
|
||||
(* Look up the function. *)
|
||||
let f =
|
||||
try List.find (fun { name = n } -> n = name) actions
|
||||
with Not_found ->
|
||||
failwithf "%s: in test, command %s was not found" test_name name in
|
||||
let f = Actions.find name in
|
||||
|
||||
(* Look up the arguments and return type. *)
|
||||
let style_ret, style_args, style_optargs = f.style in
|
||||
|
||||
Reference in New Issue
Block a user