generator: Add a function to find an action by name.

Fairly simple refactoring.
This commit is contained in:
Richard W.M. Jones
2017-03-03 16:49:41 +00:00
parent 67ce5342c2
commit 994a8f6a71
3 changed files with 10 additions and 4 deletions

View File

@@ -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

View File

@@ -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. *)

View File

@@ -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