Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.
Hello, is there some way to require at least one of two switches, when using optparse-applicative? So all of:
optparse-applicative
myexe -a
myexe -b
myexe -ab
myexe -ba
should work, but not just myexe without any options.
myexe
you could do onlyA <|> onlyB <|> both where each of those contain one or both of the individual Parsers
onlyA <|> onlyB <|> both
Parser
Torsten Schmits said:
Really? I'm not getting that to work. Seems like the parser doesn't have backtracking, so I think it would be difficult: https://github.com/pcapriotti/optparse-applicative/issues/404
oh :grimacing:
guess you'll have to throw an error yourself
what are -a and -b actually?
-a
-b
it might be the case that they're more suited to be sub-commands?
Georgi Lyubenov // googleson78 said:
It's for a small tool to create initial Cabal/Nix project setups, so the switches are supposed to be translated to --lib, --exe, and --libandexe.
--lib
--exe
--libandexe
so how about --create which accepts lib or exe or both? (translating to a data Mode = Lib | Exe | Both)
--create
lib
exe
both
data Mode = Lib | Exe | Both
you can easily have a default value too, that way
Hello, is there some way to require at least one of two switches, when using
optparse-applicative
? So all of:myexe -a
myexe -b
myexe -ab
ormyexe -ba
should work, but not just
myexe
without any options.you could do
onlyA <|> onlyB <|> both
where each of those contain one or both of the individualParser
sTorsten Schmits said:
Really? I'm not getting that to work. Seems like the parser doesn't have backtracking, so I think it would be difficult: https://github.com/pcapriotti/optparse-applicative/issues/404
oh :grimacing:
guess you'll have to throw an error yourself
what are
-a
and-b
actually?it might be the case that they're more suited to be sub-commands?
Georgi Lyubenov // googleson78 said:
It's for a small tool to create initial Cabal/Nix project setups, so the switches are supposed to be translated to
--lib
,--exe
, and--libandexe
.so how about
--create
which acceptslib
orexe
orboth
? (translating to adata Mode = Lib | Exe | Both
)you can easily have a default value too, that way