Hyphen/dash in CLI command long flag argument

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:

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?

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

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.

If you cannot change the command-line argument names to be compatible with the Slicer Execution Model, then you can create a Python scripted CLI module that runs the executable. See for example this module.

1 Like

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)?

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.

1 Like

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

1 Like