Core.Command.run : API changed between v0.14 and v0.15?

409 Views Asked by At

The following code that was compiling successfully with Core v0.14 (ocaml 4.10), but fails with v0.15 (ocaml 4.11).

open Core;;
let command = Command.basic ~summary:"essai" (
  let open Command.Let_syntax in
  let%map_open s = anon(sequence ("n" %: int))  in 
  fun () ->
    List.iter s ~f:(fun x -> Printf.printf "n = %d\n" x ) ;
  )

 
let () = Command.run ~version:"0.0" ~build_info:"RWO" command;;

The error (with 4.11) :

File "cli.ml", line 10, characters 9-20:
10 | let () = Command.run ~version:"0.0" ~build_info:"RWO" command;;
              ^^^^^^^^^^^
Error (alert deprecated): Core.Command.run
[since 2021-03] Use [Command_unix]
File "cli.ml", line 10, characters 9-20:
10 | let () = Command.run ~version:"0.0" ~build_info:"RWO" command;;
              ^^^^^^^^^^^
Error: This expression has type [ `Use_Command_unix ]
       This is not a function; it cannot be applied.

The documentation of Core.Command.run states that it is obsolete - but I fail to find how to replace it.

2

There are 2 best solutions below

1
Chris On BEST ANSWER

I think you're looking for Command_unix as indicated by the message you received. Documentation link for Command_unix.run.

1
octachron On

The core library has been restructured in version 0.15: Unix-specific modules and functions have been moved to the core_unix library in order to make the main core library more portable (or at least javascript compatible).

The function Command_unix.run in core_unix library is exactly the same as the Command.run function in previous versions of the core library.