# Command line argument parsing

**URL:** https://discourse.paraview.org/t/command-line-argument-parsing/4490
**Category:** Development
**Tags:** proposal
**Created:** [June 3, 2020, 1:02pm UTC](https://discourse.paraview.org/t/command-line-argument-parsing/4490 "2020-06-03T13:02:50Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [June 3, 2020, 1:02pm UTC](https://discourse.paraview.org/t/command-line-argument-parsing/4490/1 "2020-06-03T13:02:50Z")

</div>

Is it time to rework the command line parsing to be bit cleaner? The current `vtkPVOptions` implementation is quite dated.

[cxxopts](https://github.com/jarro2783/cxxopts) seems like a very elegant choice. It also has mechanism to group options into categories, thus making it easier to parse `--help` output. Here’s an output from an another test program using cxxopts

```bash
> ./demo --help
Usage:
  ./demo [OPTION...]

  -h, --help help

 Mode options:
  -s, --server run as server
      --hybrid run as client and server

 Client options:
  -u, --url arg address for server to connect to (default:
                 ofi+tcp;ofi_rxm://192.168.0.23:37585)

```

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [June 4, 2020, 3:01am UTC](https://discourse.paraview.org/t/command-line-argument-parsing/4490/2 "2020-06-04T03:01:14Z")

</div>

+1 for cxxopts !

We are using it at [F3D](https://gitlab.kitware.com/f3d/f3d/-/blob/master/src/cxxopts.hpp). Well, a slightly modified version for our needs, and are quite happy with it.  
We especially like the way it handles defaults values / no values, letting us use this kind of mechanism :

```
demo --activate-option : run and activate an option with a default value
demo --activate-option=value : run and activate an option with a user provided value

```

In the case of ParaView, that would remove the need for `--stereo-type` for example.

It means however that ParaView will loose retro compatibility with old scripts, so we may need to provide a CMake-enablable compatibility/deprecration layer for a few versions.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [June 4, 2020, 3:01am UTC](https://discourse.paraview.org/t/command-line-argument-parsing/4490/3 "2020-06-04T03:01:49Z")

</div>

FYI @Michael @Joachim_Pouderoux

---

<div class="post-metadata">

### Author: ![Andrew\_Maclean](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/a/e56c9b/32.png) [@Andrew\_Maclean](https://discourse.paraview.org/u/Andrew_Maclean)
#### Post date: [June 4, 2020, 8:16am UTC](https://discourse.paraview.org/t/command-line-argument-parsing/4490/4 "2020-06-04T08:16:09Z")

</div>

+1 from me. I have a few examples in the VTKExamples that will really benefit from this. It will benefit many users, especially for those coming from a Python background where this is second nature.

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [June 4, 2020, 12:44pm UTC](https://discourse.paraview.org/t/command-line-argument-parsing/4490/5 "2020-06-04T12:44:33Z")

</div>

Good point! We should probably add it to VTK itself and update tests/examples to start using it too.

---

<div class="post-metadata">

### Author: ![chart3388](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/c/82dd89/32.png) [@chart3388](https://discourse.paraview.org/u/chart3388)
#### Post date: [June 4, 2020, 9:08pm UTC](https://discourse.paraview.org/t/command-line-argument-parsing/4490/6 "2020-06-04T21:08:57Z")

</div>

I like cxxopts. The one thing I can recall is it needs support for gcc 4.9 or greater. If I recall correctly you currently support gcc 4.8.5 with 5.8.0. Might be an issue as I know a few folks still use 4.8.5 with ParaView given the latest round of issues when 5.8.0 came out.

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [June 5, 2020, 2:01am UTC](https://discourse.paraview.org/t/command-line-argument-parsing/4490/7 "2020-06-05T02:01:50Z")

</div>

good point. I don’t think this will be happening for 5.9, maybe 5.10 at the earliest. By then we may be able to revise the minimum supported gcc versions.

---

<div class="post-metadata">

### Author: ![Andrew\_Maclean](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/a/e56c9b/32.png) [@Andrew\_Maclean](https://discourse.paraview.org/u/Andrew_Maclean)
#### Post date: [August 25, 2020, 1:15am UTC](https://discourse.paraview.org/t/command-line-argument-parsing/4490/8 "2020-08-25T01:15:32Z")

</div>

I was looking at cxxopts a while back, it has trouble with negative positional parameters. e.g.

```bash
demo -1 12

```

However this is solvable by putting optional parameters first and using `--` before the positional parameters e.g.  
e.g.

```bash
demo -r -- -1 12

```

This means the user has to know this, it stumped me at first. See: [https://github.com/jarro2783/cxxopts/issues/254](https://github.com/jarro2783/cxxopts/issues/254)

---

<div class="post-metadata">

### Author: ![Andrew\_Maclean](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/a/e56c9b/32.png) [@Andrew\_Maclean](https://discourse.paraview.org/u/Andrew_Maclean)
#### Post date: [August 25, 2020, 1:20am UTC](https://discourse.paraview.org/t/command-line-argument-parsing/4490/9 "2020-08-25T01:20:57Z")

</div>

Do also consider [CLI11](https://github.com/CLIUtils/CLI11), this is much closer to the same behaviour as `argparse` and allows really complex inputs (if needed). It is also available as a single header. The license looks to be similar to the old VTK license, so there is probably no issues there.  
It is very easy to use e.g.

```auto
// ...
  // Initialise the ArgParameters
  ArgParameters ap{true, 3, -45};

  CLI::App app{GetProgramName(argv[0]) +
               " - testing positional command line options"};
  bool r = false;
  app.add_flag("-r, --radians", r, "Use radians");
  app.add_option("angle", ap.angle, "The angle", true);
  app.add_option("dp", ap.dp, "The decimal precision", true);

  CLI11_PARSE(app, argc, argv);

  ap.degrees &= !r;
// ...

```

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [April 5, 2021, 1:29am UTC](https://discourse.paraview.org/t/command-line-argument-parsing/4490/10 "2021-04-05T01:29:42Z")

</div>

I am going to resurrect this topic. We will be tackling this in near future.

Looking at [CLI11](https://github.com/CLIUtils/CLI11), I do like the [subcommands](https://cliutils.github.io/CLI11/book/chapters/subcommands.html). I can see how ParaView-based applications could use that to separate their app specific cmd-options and cmd-options to pass on to the ParaView engine.

What do folks think? Is there a general preference? Since cxxopts and CLI11 are both robust choices, I think it simply boils down to what we as developers prefer. If the developers are more familiar with one over another, I think it may be wise to just stick with the familiar one. Is there are general preference among the developers?

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [April 6, 2021, 9:16am UTC](https://discourse.paraview.org/t/command-line-argument-parsing/4490/11 "2021-04-06T09:16:09Z")

</div>

familiar with cxxopts here, but not closed to CLI11 at all.

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.paraview.org/user_avatar/discourse.paraview.org/cory.quammen/32/11193_2.png) [@cory.quammen](https://discourse.paraview.org/u/cory.quammen)
#### Post date: [April 6, 2021, 6:26pm UTC](https://discourse.paraview.org/t/command-line-argument-parsing/4490/12 "2021-04-06T18:26:58Z")

</div>

cxxopts requires gcc 4.9+ and above, but ParaView requires only gcc 4.8+, and I expect it will need to support it for some time. CLI11 supports gcc 4.8+

CLI11 looks like it has just about everything we could need.

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [April 8, 2021, 12:39pm UTC](https://discourse.paraview.org/t/command-line-argument-parsing/4490/13 "2021-04-08T12:39:26Z")

</div>

Based on the comments and the fact that CLI11 supports subcommands which potentially may be a very nice way to support custom applications / paraview-variants, I think I’ll proceed with CLI11.

thanks, everyone!

---

<div class="post-metadata">

### Author: ![danlipsa](https://discourse.paraview.org/user_avatar/discourse.paraview.org/danlipsa/32/1563_2.png) [@danlipsa](https://discourse.paraview.org/u/danlipsa)
#### Post date: [May 6, 2021, 2:31pm UTC](https://discourse.paraview.org/t/command-line-argument-parsing/4490/14 "2021-05-06T14:31:28Z")

</div>

@utkarsh.ayachit Did you get around doing this? Would it make sense to add this to VTK? I want to add a small executable in VTK that would benefit from using a options library. Now I use cxxopts but I could easily switch.  
[https://gitlab.kitware.com/vtk/vtk/-/merge\_requests/7938](https://gitlab.kitware.com/vtk/vtk/-/merge_requests/7938)

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [May 6, 2021, 2:44pm UTC](https://discourse.paraview.org/t/command-line-argument-parsing/4490/15 "2021-05-06T14:44:12Z")

</div>

nope. I didn’t…would be nice you or someone has time to add `CLI11` as TPL to VTK.

---

<div class="post-metadata">

### Author: ![danlipsa](https://discourse.paraview.org/user_avatar/discourse.paraview.org/danlipsa/32/1563_2.png) [@danlipsa](https://discourse.paraview.org/u/danlipsa)
#### Post date: [May 8, 2021, 11:44pm UTC](https://discourse.paraview.org/t/command-line-argument-parsing/4490/16 "2021-05-08T23:44:57Z")

</div>

Thanks, I ended up not adding that executable so I don’t need an option library in VTK anymore, but it may still be useful to have it there instead of ParaView.

---

<div class="post-metadata">

### Author: ![vbolea](https://discourse.paraview.org/user_avatar/discourse.paraview.org/vbolea/32/4121_2.png) [@vbolea](https://discourse.paraview.org/u/vbolea)
#### Post date: [May 10, 2021, 9:31pm UTC](https://discourse.paraview.org/t/command-line-argument-parsing/4490/17 "2021-05-10T21:31:46Z")

</div>

I am late to this conversation, but I want to add Boost.Program\_options library to the debate. The main advantage of using this instead of the previously mentioned libraries is that is part of Boost library meaning that its well documented, known and it has a good change to eventually make it to the standard library.

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [May 11, 2021, 8:23am UTC](https://discourse.paraview.org/t/command-line-argument-parsing/4490/18 "2021-05-11T08:23:39Z")

</div>

I can’t recall exactly why, but we’ve stayed away from making boost a required dependency of VTK/ParaView.

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.paraview.org/user_avatar/discourse.paraview.org/cory.quammen/32/11193_2.png) [@cory.quammen](https://discourse.paraview.org/u/cory.quammen)
#### Post date: [May 11, 2021, 1:43pm UTC](https://discourse.paraview.org/t/command-line-argument-parsing/4490/19 "2021-05-11T13:43:56Z")

</div>

IIRC it is because boost is often just a huge pain to build.

---

<div class="post-metadata">

### Author: ![vbolea](https://discourse.paraview.org/user_avatar/discourse.paraview.org/vbolea/32/4121_2.png) [@vbolea](https://discourse.paraview.org/u/vbolea)
#### Post date: [May 11, 2021, 2:34pm UTC](https://discourse.paraview.org/t/command-line-argument-parsing/4490/20 "2021-05-11T14:34:47Z")

</div>

Yeah, that’s true, especially for small libraries, boost building system is overkill. It uses its ad-hoc compiling scripts which is probably due to licensing issues.

On the other hand if the library is small enough we could cmakify it, hoping that it does not depend on another boost library (which depends on another boost library…) which maybe not worth the effort and more important: its maintanance.

[Next page](https://discourse.paraview.org/t/command-line-argument-parsing/4490.md?page=2)
