I've been using cmdargs for argument processing for a while, and it's great. However, I don't see a facility for long option names with a single hyphen, e.g. -option1 -option2
or the more difficult -optx
which is equivalent to --opt=x
. I need to maintain compatibility with an existing application, so these formats are both necessary.
System.Console.Getopt doesn't seem up to it either. Can anyone either provide a sample of how to do this with cmdargs, or suggest an alternative library which will support this?
Probably the simplest thing you can do is to do a quick pre-processing pass yourself. For example, if you need to support exactly the three options -option1
, -option2
, and -optx
, Something like this should work:
munge "-option1" = "--option1"
munge "-option2" = "--option2"
munge s | "-opt" `isPrefixOf` s = "--opt=" ++ drop 4 s
munge s = s
main = do
realArgs <- getArgs
withArgs (map munge realArgs) mainThatUsesCmdArgs
As you say, though, the help messages would then no longer mention the possibility of having these short forms. (Perhaps that's a good thing, though.)
If you want more, you will probably have to convince somebody to modify cmdargs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With