# Set configuration via command line arguments

**URL:** <https://discuss.ocaml.org/t/set-configuration-via-command-line-arguments/13668>\
**Category:** Learning\
**Tags:** learning, commandline, async\
**Created:** [December 18, 2023, 4:20pm UTC](https://discuss.ocaml.org/t/set-configuration-via-command-line-arguments/13668 "2023-12-18T16:20:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vivanov](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/vivanov/32/4455_2.png) [@vivanov](https://discuss.ocaml.org/u/vivanov)\
**Post date:** [December 18, 2023, 4:20pm UTC](https://discuss.ocaml.org/t/set-configuration-via-command-line-arguments/13668/1 "2023-12-18T16:20:40Z")

</div>

Hey, I am looking to set some parameters in my program via the command line arguments. I can’t think of a way to do this. I have the following structure of my modules:

```auto
ModuleA: 
  buffer_size = 16
  depth = 10

ModuleB:
  queue_size = 8

ModuleC:
  open ModuleA
  open ModuleB
  function my_function

ModuleD:
  open ModuleC
  Command_unix.run my_function

```

---

<div class="post-metadata">

**Author:** ![nojb](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/nojb/32/519_2.png) [@nojb](https://discuss.ocaml.org/u/nojb)\
**Post date:** [December 18, 2023, 4:34pm UTC](https://discuss.ocaml.org/t/set-configuration-via-command-line-arguments/13668/2 "2023-12-18T16:34:02Z")

</div>

If you want to preserve your existing module structure, a simple way of doing it is by introducing, say, a module `Args` at the root of your dependency graph that extracts the parameters from the command-line (code not tested):

```ocaml
Args:
  let buffer_size = ref 16
  let depth = ref 10
  let queue_size = ref 8
  let () =
    Arg.parse
      [ "-buffer-size", Set_int buffer_size, "...";
        "-depth", Set_int depth, "...";
        "-queue-size", Set_int queue_size, "..."
      ] ignore "..."

ModuleA:
  let buffer_size = !Args.buffer_size
  let depth = !Args.depth

ModuleB:
  let queue_size = !Args.queue_size

```

Cheers,  
Nicolas
