# Hyphen/dash in CLI command long flag argument

**URL:** <https://discourse.slicer.org/t/hyphen-dash-in-cli-command-long-flag-argument/19526>\
**Category:** Support\
**Created:** [September 6, 2021, 5:00am UTC](https://discourse.slicer.org/t/hyphen-dash-in-cli-command-long-flag-argument/19526 "2021-09-06T05:00:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![benzwick](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/benzwick/32/80521_2.png) [@benzwick](https://discourse.slicer.org/u/benzwick)\
**Post date:** [September 6, 2021, 5:00am UTC](https://discourse.slicer.org/t/hyphen-dash-in-cli-command-long-flag-argument/19526/1 "2021-09-06T05:00:49Z")

</div>

I am developing a Python CLI module for some software that uses hyphens in command line arguments. I created the XML file and loaded everything into 3D Slicer but I get the following error due to the hyphen/dash in the long flags:

```auto
ModuleDescriptionParser Error: <longflag> can only contain letters, numbers and underscores and must start with a _ or letter. The offending name is "input-file"

```

Is there any way to use flags with hyphens, e.g. `--input-file`, in a CLI extension?

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [September 7, 2021, 5:41pm UTC](https://discourse.slicer.org/t/hyphen-dash-in-cli-command-long-flag-argument/19526/2 "2021-09-07T17:41:27Z")

</div>

At least for C++ cli modules the `--` is added automatically if you just specify `input-file`. Is this not the case for python cli?

---

<div class="post-metadata">

**Author:** ![benzwick](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/benzwick/32/80521_2.png) [@benzwick](https://discourse.slicer.org/u/benzwick)\
**Post date:** [September 8, 2021, 1:56am UTC](https://discourse.slicer.org/t/hyphen-dash-in-cli-command-long-flag-argument/19526/3 "2021-09-08T01:56:25Z")

</div>

Yes, the `--` at the start is added automatically (in the XML file I use `<longflag>input-file</longflag>`) but the hyphen in the middle in e.g. `input-file` is not allowed.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 8, 2021, 2:47am UTC](https://discourse.slicer.org/t/hyphen-dash-in-cli-command-long-flag-argument/19526/4 "2021-09-08T02:47:05Z")

</div>

If you cannot change the command-line argument names to be compatible with the [Slicer Execution Model](https://www.slicer.org/wiki/Documentation/Nightly/Developers/SlicerExecutionModel#XML_Schema), then you can create a Python scripted CLI module that runs the executable. See for example [this module](https://github.com/simonoxen/SlicerANTs/tree/master/antsCommand).

---

<div class="post-metadata">

**Author:** ![benzwick](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/benzwick/32/80521_2.png) [@benzwick](https://discourse.slicer.org/u/benzwick)\
**Post date:** [September 8, 2021, 3:35am UTC](https://discourse.slicer.org/t/hyphen-dash-in-cli-command-long-flag-argument/19526/5 "2021-09-08T03:35:06Z")

</div>

I’ve changed the arguments in my program to remove the hyphens. However, there are many programs that use this style. Is there any change planned for Slicer Execution Model to support these argument names in the future? The Python argparse module simply replaces the hyphen `-` with underscore `_` so something similar could be done in Slicer XML as well.

As an aside, I am also working on creating an extension for a standalone C++ CLI program that has similar argument names. Do you recommend to use the same approach as the antsCommand module in the link you mentioned (i.e. create a Python CLI module that provides an interface to the external C++ program)?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 8, 2021, 3:50am UTC](https://discourse.slicer.org/t/hyphen-dash-in-cli-command-long-flag-argument/19526/6 "2021-09-08T03:50:05Z")

</div>

> [@benzwick](#):
>
> I’ve changed the arguments in my program to remove the hyphens. However, there are many programs that use this style. Is there any change planned for Slicer Execution Model to support these argument names in the future?

Yes, indeed many programs allow using long arguments but usually short form of the arguments are available, too. For example, if a program accepts `--input-file` and `-i` to specify an input file then we simply use the short form.

I agree that it would be nice to have a way to specify arguments that contain `-` in the name. However, since you can usually use the short form of the arguments, change the argument names, or if all else fail then use an adaptor script, this enhancement has never made it to the top of anyone’s priority list. If you decide to implement it then we’ll be happy to review and merge this improvement.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 8, 2021, 3:57am UTC](https://discourse.slicer.org/t/hyphen-dash-in-cli-command-long-flag-argument/19526/7 "2021-09-08T03:57:07Z")

</div>

By the way, this is a known limitation - see [https://github.com/Slicer/SlicerExecutionModel/issues/17](https://github.com/Slicer/SlicerExecutionModel/issues/17)
