Closed dan-t closed 10 years ago
Oh, sorry, it's the difference in the help text, which makes perfectly sense. Thanks for this great library!
Greetings, Daniel
Glad you like it - I was actually checking out cabal-bounds just minutes ago :-)
If you have multiple fields that are the same, you can omit them from subsequent constructors, and they will be inferred to be the same as before. e.g. no need to include only
in updateArgs
.
On Tue, Feb 25, 2014 at 01:23:46AM -0800, Neil Mitchell wrote:
If you have multiple fields that are the same, you can omit them from subsequent constructors, and they will be inferred to be the same as before. e.g. no need to include only in updateArgs.
Thanks for the hint! :)
Perhaps the only additional thing I would like to have in cmdargs is the ability to give multiple values to an option. I think that's not possible at the moment, right?
So it would be nice to be able to write '--executable=exe1,exe2' instead of '--executable=exe1 --executable=exe2'.
Greetings, Daniel
The only issue with exe1,exe2
is that it wouldn't know if commas make sense as a valid single atom for a String, so you can't always split. One thing you can do is post-process the output of cmdargs, so take all executable fields and do a {executable = concatMap splitOnComma executable}
, then you can have comma splitting back.
On Tue, Feb 25, 2014 at 02:52:28AM -0800, Neil Mitchell wrote:
The only issue with exe1,exe2 is that it wouldn't know if commas make sense as a valid single atom for a String, so you can't always split.
Yes, that's true.
But the splitter could be specified by the user, something like:
executable = def &= splitter "," &= ...
Perhaps better that the splitter isn't specified for every option but for all of them.
Would you consider a patch with such an addition?
One thing you can do is post-process the output of cmdargs, so take all executable fields and do a {executable = concatMap splitOnComma executable}, then you can have comma splitting back.
Yes, perhaps I will tackle it that way.
Greetings, Daniel
I suspect the correct thing to do is to add parser :: Either String a -> Ann
, so you can write an arbitrary parser for any type. Once you have that, adding splitter
on top of parser
is easy. However, writing parser
is a bit tricky because the type doesn't force a
, so perhaps it needs to be a val -> val
type. I haven't looked in to the details. I'd willingly accept a patch for either splitter
or parser
.
I think that I might prefer the splitter
one, because you could use this information for the help text. So by having
a splitter ","
you could e.g. display:
-e --executable=ITEM[,...]
Greetings, Daniel
Hi Neil,
I have a bit of a hard time groking the CmdArgs code base.
I can see that the first step of adding a 'splitter' would be extending the 'Ann' data structure with a new constructor.
The 'Ann's are stored in 'Capture' which is used to initialize 'Prog'. Inside of 'Prog' there's 'Flag', which has the function 'flagValue', which looks like it could be useful for implementing the 'splitter', but the type of the function is 'String -> a -> Either String a', and I don't quite get why the function gets an 'a' and returns one.
Also if would like to modify the help message like described, then I don't quite see where I should apply the modification.
Well all these mappings and remappings make it really hard to follow.
Greetings, Daniel
Sorry for the delay in replying, things got a bit hectic at work. The truth is that the CmdArgs code base can be a little opaque - I plan to give it a good refactoring at some point, but haven't yet had the time, or quite figured out what the result would look like. The Global
vs Local
split is also quite hard to follow.
The idea behind flagValue
is that if your mode is of type A
, then flagValue
takes the argument the user entered, and the existing A
, and returns a Left
error message (e.g. failed to parse) or a Right
new value of A
, e.g. a{myfield = newcontents}.
Applying the help message should be easier, somewhere around https://github.com/ndmitchell/cmdargs/blob/master/System/Console/CmdArgs/Implicit/Local.hs#L202 I would have thought.
Hi Neil,
some arguments seem to be considered, others not, here -e, -l, -t and -b aren't considered:
The data structure for the arguments is:
And the initialization of the arguments:
That's the case for
cmdargs 0.10.7
. Any ideas? Thanks!Greetings, Daniel