type and type string option
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <[email protected]> |
I have this little Ocaml code that should print the value of an
environment variable specified as an anonymous argument. If no argument
is given, the environment variable content to print is EDITOR.
open Core.Std
let spec =
let open Command.Spec in
empty
+> anon (maybe ("var_name" %: string))
let print_value variable ()=
let getenv_value_of varname =
try
Sys.getenv varname
with Not_found -> varname ^ " not defined"
in match variable with
| None -> print_endline (getenv_value_of "EDITOR")
| Some name -> print_endline (getenv_value_of name)
let command = Command.basic
~summary:"Print the value of an environment variable"
~readme:(fun () -> "Print the value of an environment variable you
provide or the EDITOR variable it you didn't provide any")
spec
print_value
let () = Command.run ~version:"1.0" ~build_info:"RWO" command
If I try to compile it with corebuild -quiet print_en.native
I have this error:
+ ocamlfind ocamlc -c -w A-4-33-40-41-42-43-34-44 -strict-sequence -g
-bin-annot -short-paths -thread -package core -ppx 'ppx-jane -as-ppx' -o
MrHide_env_variables.cmo MrHide_env_variables.ml
File "MrHide_env_variables.ml", line 13, characters 19-43:
Error: This expression has type string but an expression was expected of
type
string option
Command exited with code 2.
Hint: Recursive traversal of subdirectories was not enabled for this build,
as the working directory does not look like an ocamlbuild project (no
'_tags' or 'myocamlbuild.ml' file). If you have modules in
subdirectories,
you should add the option "-r" or create an empty '_tags' file.
To enable recursive traversal for some subdirectories only, you can
use the
following '_tags' file:
true: -traverse
<dir1> or <dir2>: traverse
I can not see how to solve this.
cedlemo