From 38a5e58b6caeec8562cd5a28e6f6c476173f51ff Mon Sep 17 00:00:00 2001 From: Sebastien Mondet Date: Mon, 19 Dec 2016 15:16:26 -0500 Subject: [PATCH] Make CLI-parsing types more readable Cf. comments in #11. Also, the change in `examples.ml` allows people exploring the example to easily just get the interesting type from Merlin: ```ocaml (string Genspio.EDSL.t -> bool Genspio.EDSL.t -> string Genspio.EDSL.t -> string Genspio.EDSL.t -> unit Genspio.EDSL.t, unit Genspio.EDSL.t) Genspio.EDSL.cli_options ``` --- src/lib/EDSL.mli | 15 ++++++++------- src/test/examples.ml | 5 +++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/lib/EDSL.mli b/src/lib/EDSL.mli index 3f199f9..b432c8c 100644 --- a/src/lib/EDSL.mli +++ b/src/lib/EDSL.mli @@ -97,9 +97,9 @@ val feed : string:string t -> unit t -> unit t val ( >> ) : string t -> unit t -> unit t val loop_while : bool t -> body:unit t -> unit t -type 'a cli_option = 'a Language.cli_option -type 'a option_spec = 'a Language.option_spec -type ('a, 'b) cli_options = ('a, 'b) Language.cli_options +type 'argument_type cli_option = 'argument_type Language.cli_option +type 'argument_type option_spec = 'argument_type Language.option_spec +type ('parse_function, 'return_type) cli_options = ('parse_function, 'return_type) Language.cli_options module Option_list : sig val string : ?default: string t -> @@ -110,13 +110,14 @@ module Option_list : sig doc:string -> char -> bool t option_spec val ( & ) : - 'a option_spec -> - ('b, 'c) cli_options -> ('a -> 'b, 'c) cli_options - val usage : string -> ('a, 'a) cli_options + 'argument_type option_spec -> + ('parse_function, 'return_type) cli_options -> + ('argument_type -> 'parse_function, 'return_type) cli_options + val usage : string -> ('last_return_type, 'last_return_type) cli_options end val parse_command_line : - ('a, unit t) cli_options -> 'a -> unit t + ('parse_function, unit t) cli_options -> 'parse_function -> unit t val string_concat: string t list -> string t diff --git a/src/test/examples.ml b/src/test/examples.ml index cad2d53..4cc38ab 100644 --- a/src/test/examples.ml +++ b/src/test/examples.ml @@ -133,7 +133,7 @@ let downloader () = ] end in let no_value = sprintf "none_%x" (Random.int 100_000) |> string in - parse_command_line + let cli_spec = Option_list.( string ~doc:"The URL to the stuff" 'u' @@ -146,7 +146,8 @@ let downloader () = ~doc:"Use as temp-dir" ~default:(Genspio.EDSL.string "/tmp/genspio-downloader-tmpdir") & usage "$0 -u URL [-c]" - ) + ) in + parse_command_line cli_spec begin fun url all_in_tmp filename_ov tmp_dir -> let current_name = tmp_file ~tmp_dir "current-name" in let set_output_of_download () =