# Questions about updating code using Command library

**URL:** https://discuss.ocaml.org/t/questions-about-updating-code-using-command-library/4273
**Category:** Ecosystem
**Created:** [August 20, 2019, 6:27pm UTC](https://discuss.ocaml.org/t/questions-about-updating-code-using-command-library/4273 "2019-08-20T18:27:55Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![basus](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/basus/32/29_2.png) [@basus](https://discuss.ocaml.org/u/basus)
#### Post date: [August 20, 2019, 6:27pm UTC](https://discuss.ocaml.org/t/questions-about-updating-code-using-command-library/4273/1 "2019-08-20T18:27:55Z")

</div>

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](https://dev.realworldocaml.org/command-line-parsing.html) 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](https://ocaml.janestreet.com/ocaml-core/latest/doc/core_kernel/Core_kernel/Command/Arg_type/Export/index.html) 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!

---

<div class="post-metadata">

### Author: ![bcc32](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/bcc32/32/203_2.png) [@bcc32](https://discuss.ocaml.org/u/bcc32)
#### Post date: [August 20, 2019, 7:07pm UTC](https://discuss.ocaml.org/t/questions-about-updating-code-using-command-library/4273/2 "2019-08-20T19:07:09Z")

</div>

> [@basus](#):
>
> - 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](https://ocaml.janestreet.com/ocaml-core/latest/doc/core_kernel/Core_kernel/Command/Arg_type/Export/index.html) either.

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

> [@basus](#):
>
> 1. 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.

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

1. Define a “config” parameter that includes all of the common specifications:

```ocaml
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`](https://github.com/janestreet/async_unix/blob/eedc331aba5b4a81f629195ed5999bc4dedf4da9/src/log.ml#L1296) for an example.

---

<div class="post-metadata">

### Author: ![XVilka](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/xvilka/32/5334_2.png) [@XVilka](https://discuss.ocaml.org/u/XVilka)
#### Post date: [August 21, 2019, 4:26am UTC](https://discuss.ocaml.org/t/questions-about-updating-code-using-command-library/4273/3 "2019-08-21T04:26:25Z")

</div>

Worth opening a bug in RWO for that.

---

<div class="post-metadata">

### Author: ![jjb](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/jjb/32/2713_2.png) [@jjb](https://discuss.ocaml.org/u/jjb)
#### Post date: [August 21, 2019, 8:38pm UTC](https://discuss.ocaml.org/t/questions-about-updating-code-using-command-library/4273/4 "2019-08-21T20:38:39Z")

</div>

> [@basus](#):
>
> 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.

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](https://github.com/facebook/infer/blob/master/sledge/src/sledge.ml).

---

<div class="post-metadata">

### Author: ![basus](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/basus/32/29_2.png) [@basus](https://discuss.ocaml.org/u/basus)
#### Post date: [August 22, 2019, 6:47pm UTC](https://discuss.ocaml.org/t/questions-about-updating-code-using-command-library/4273/5 "2019-08-22T18:47:03Z")

</div>

Thanks, I used @bcc32’s suggestion and updated my code accordingly. I also [filed a bug](https://github.com/realworldocaml/book/issues/3126) on the Real World OCaml Github tracker about changing the use of the `file` type.
