cmdargs
cmdargs copied to clipboard
System.Console.CmdArgs.Explicit.helpText: required arguments are rendered as optional and vice versa
The help text rendering (System.Console.CmdArgs.Explicit.helpText) renders required arguments as optional (with square brackets) and optional arguments as required (without square brackets).
Example
module CmdArgsExplicit where
import System.Console.CmdArgs.Explicit
import System.Console.CmdArgs.Text
argMode :: Mode ()
argMode = (modeEmpty ())
{ modeNames = ["Main"]
, modeArgs = ([argReq, argOpt], Nothing)
}
where
argReq = (flagArg (\ _ _ -> Right ()) "REQ"){argRequire = True}
argOpt = flagArg (\ _ _ -> Right ()) "OPT"
main :: IO ()
main
= putStr
$ showText defaultWrap
$ helpText [] HelpFormatAll argMode
Expected output: Main REQ [OPT]
Actual output: Main [REQ] OPT
PS
The function flagArg
creates optional arguments. I would prefer, if it created required arguments.
Nevertheless, CmdArgs
is really awesome!
OK, certainly a bug - I've got the boolean test the wrong way round - I figure out if it's required, then only put []
around it if it is required, when it should be if it's not required.
Unfortunately, I have a few places where I explicitly put []
around stuff, probably a reaction to the fact the required test wasn't doing what it should. I'll find them, take them out, and then put fix the condition.
PS. The reason flagArg
is optional by default is that most command line programs have everything be optional as standard, so it was trying to follow the convention.
Hmm, this one actually turns out to be a little tricky to solve without breaking anything else...
CmdArgs Explicit can deal with a list of required arguments, followed by an optional argument that is repeated. CmdArgs Implicit can deal with much the same format, but it groups all the arguments into one argument, calls it implicit, says it is repeating, and then fakes the command structure information to get it working. Once Explicit puts on the [brackets]
automatically you have a problem as you end up with incorrect surrounding brackets. The full solution is to make Implicit map to Explicit properly, and then fix Explicit. In the meantime, I've made it so Explicit never puts square brackets around an argument (a release will be out in about an hour), and you can change the help text to [ITEM]
yourself if you want. Longer term, I'll fix it properly.