Questions about updating code using Command library

I’ve been updating one of my projects to the latest version of Core (v0.12.3) and it seems like the Command module has undergone a lot of changes. I have some questions about how to do things I used to with the older Command with the current version. I have been using the current development version of Real World OCaml as a guide.

  1. It seems there is no longer a file type for command arguments. RWO says that there should be a file type as part of Command.Let_syntax but I get an unbound value file error. I can’t find a file type in the documentation either.

  2. Previously I could define a specification to be common to all commands (for example, debug and verbose output flags) and then use the +> combinator to include it in all other specifications. I can’t figure out how to do this with the current version.

Thanks!

file has been renamed Filename.arg_type. A number of such built-in arg types have been moved to their respective modules.

You can still do this. I can think of two common ways:

  1. Define a “config” parameter that includes all of the common specifications:
module Config = struct
  type t = { verbose : bool; debug : bool }

  let param =
    let open Command.Let_syntax in
    let%map_open verbose = flag "-verbose" no_arg ~doc:" verbose"
    and debug = flag "-debug" no_arg ~doc:" debug" in
    { verbose; debug }
end

(* later *)

let _ =
  Command.basic ~summary:"some command"
    (let%map_open.Command.Let_syntax config = Config.param in
     (* do something according to config *))
  1. Define a parameter that imperatively sets some global options. See Async.Log.Global.set_level_via_param for an example.

Worth opening a bug in RWO for that.

1 Like

I’m not sure just what you want to do, but some amount of that sort of thing is done with the current Command api here.

Thanks, I used @bcc32’s suggestion and updated my code accordingly. I also filed a bug on the Real World OCaml Github tracker about changing the use of the file type.