Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.Console.CmdArgs.Explicit.helpText: required arguments are rendered as optional and vice versa #15

Open
Flupp opened this issue Oct 10, 2014 · 2 comments

Comments

@Flupp
Copy link

Flupp commented Oct 10, 2014

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!

@ndmitchell
Copy link
Owner

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.

@ndmitchell
Copy link
Owner

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.

jsonn pushed a commit to jsonn/pkgsrc that referenced this issue Jun 4, 2015
CHANGES:
0.10.13
    #24, support Ratio in some places
    ndmitchell/cmdargs#24
0.10.12
    GHC 7.2 compatibility
0.10.11
    #15, never put [brackets] around optional args in Explicit
    ndmitchell/cmdargs#15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants