Skip to content

Commit

Permalink
Make CLI-parsing types more readable
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
smondet committed Dec 19, 2016
1 parent 728ea4f commit 38a5e58
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
15 changes: 8 additions & 7 deletions src/lib/EDSL.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand All @@ -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

Expand Down
5 changes: 3 additions & 2 deletions src/test/examples.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -146,7 +146,8 @@ let downloader () =
~doc:"Use <dir> 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 () =
Expand Down

0 comments on commit 38a5e58

Please sign in to comment.