mirror of
https://github.com/ilyakooo0/optparse-applicative.git
synced 2024-09-19 06:28:23 +03:00
Allow options to consume an arbitrary number of arguments
This commit is contained in:
parent
37fe3df3bf
commit
1f3a68b41e
@ -64,7 +64,7 @@ resetArgs = modify $ \s -> s
|
|||||||
, skippedArgs = [] }
|
, skippedArgs = [] }
|
||||||
|
|
||||||
data BaseOption a
|
data BaseOption a
|
||||||
= BaseReg [OptName] (ReadM a)
|
= BaseReg [OptName] (ArgParser a)
|
||||||
| BaseFlag [OptName] a
|
| BaseFlag [OptName] a
|
||||||
| BaseCommand String a
|
| BaseCommand String a
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ instance Pretty1 BaseOption where
|
|||||||
|
|
||||||
instance Opt BaseOption where
|
instance Opt BaseOption where
|
||||||
optFind arg (BaseReg ns v)
|
optFind arg (BaseReg ns v)
|
||||||
| matchNames arg ns = Just (argParser1 v)
|
| matchNames arg ns = Just v
|
||||||
optFind arg (BaseFlag ns x)
|
optFind arg (BaseFlag ns x)
|
||||||
| matchNames arg ns = Just (pure x)
|
| matchNames arg ns = Just (pure x)
|
||||||
optFind arg (BaseCommand cmd x)
|
optFind arg (BaseCommand cmd x)
|
||||||
|
@ -95,6 +95,7 @@ module Options.Applicative.Builder (
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
|
import Control.Monad.Except
|
||||||
import Data.Foldable (asum)
|
import Data.Foldable (asum)
|
||||||
import Data.Monoid (Monoid (..)
|
import Data.Monoid (Monoid (..)
|
||||||
#if __GLASGOW_HASKELL__ > 702
|
#if __GLASGOW_HASKELL__ > 702
|
||||||
@ -262,8 +263,13 @@ switch = flag False True
|
|||||||
-- 'infoOption' instead.
|
-- 'infoOption' instead.
|
||||||
abortOption :: HasOption (WithInfo OptProperties BaseOption) f
|
abortOption :: HasOption (WithInfo OptProperties BaseOption) f
|
||||||
=> ParseError -> Mod OptionFields a -> f a
|
=> ParseError -> Mod OptionFields a -> f a
|
||||||
abortOption err m = option (readerAbort err) . (`mappend` m) $ mconcat
|
abortOption err m = liftOption
|
||||||
[ noArgError err , metavar "" ]
|
. WithInfo (mkProps d g)
|
||||||
|
. BaseReg (optNames fields)
|
||||||
|
$ throwError err
|
||||||
|
where
|
||||||
|
Mod f d g = metavar "" `mappend` m
|
||||||
|
fields = f (OptionFields [] mempty err)
|
||||||
|
|
||||||
-- | An option that always fails and displays a message.
|
-- | An option that always fails and displays a message.
|
||||||
infoOption :: HasOption (WithInfo OptProperties BaseOption) f
|
infoOption :: HasOption (WithInfo OptProperties BaseOption) f
|
||||||
@ -278,7 +284,10 @@ strOption = option str
|
|||||||
-- | Builder for an option using the 'auto' reader.
|
-- | Builder for an option using the 'auto' reader.
|
||||||
option :: HasOption (WithInfo OptProperties BaseOption) f
|
option :: HasOption (WithInfo OptProperties BaseOption) f
|
||||||
=> ReadM a -> Mod OptionFields a -> f a
|
=> ReadM a -> Mod OptionFields a -> f a
|
||||||
option r m = liftOption . WithInfo (mkProps d g) . BaseReg (optNames fields) $ r
|
option r m = liftOption
|
||||||
|
. WithInfo (mkProps d g)
|
||||||
|
. BaseReg (optNames fields)
|
||||||
|
. argParser1 $ r
|
||||||
where
|
where
|
||||||
Mod f d g = metavar "ARG" `mappend` m
|
Mod f d g = metavar "ARG" `mappend` m
|
||||||
fields = f (OptionFields [] mempty (ErrorMsg ""))
|
fields = f (OptionFields [] mempty (ErrorMsg ""))
|
||||||
|
Loading…
Reference in New Issue
Block a user