diff --git a/optparse-generic.cabal b/optparse-generic.cabal index a03f37a..f852261 100644 --- a/optparse-generic.cabal +++ b/optparse-generic.cabal @@ -30,7 +30,9 @@ Library optparse-applicative >= 0.11.0 && < 0.14, time >= 1.5 && < 1.7 , void < 0.8 , - bytestring < 0.11 + bytestring < 0.11, + semigroups >= 0.18.1 + if impl(ghc < 7.8) Build-Depends: singletons >= 0.10.0 && < 1.0 , diff --git a/src/Options/Generic.hs b/src/Options/Generic.hs index efa6064..36a4714 100644 --- a/src/Options/Generic.hs +++ b/src/Options/Generic.hs @@ -235,6 +235,7 @@ import Control.Applicative import Control.Monad.IO.Class (MonadIO(..)) import Data.Char (toLower, toUpper) import Data.Monoid +import Data.List.NonEmpty (NonEmpty((:|))) import Data.Proxy import Data.Text (Text) import Data.Typeable (Typeable) @@ -476,6 +477,9 @@ instance (Num a, ParseField a) => ParseFields (Product a) where instance ParseField a => ParseFields [a] where parseFields = parseListOfField +instance ParseField a => ParseFields (NonEmpty a) where + parseFields h m = (:|) <$> parseField h m <*> parseListOfField h m + {-| Use this to annotate a field with a type-level string (i.e. a `Symbol`) representing the help description for that field: @@ -589,6 +593,9 @@ instance (Num a, ParseField a) => ParseRecord (Product a) where instance ParseField a => ParseRecord [a] where parseRecord = fmap getOnly parseRecord +instance ParseField a => ParseRecord (NonEmpty a) where + parseRecord = fmap getOnly parseRecord + instance (ParseFields a, ParseFields b) => ParseRecord (a, b) instance (ParseFields a, ParseFields b, ParseFields c) => ParseRecord (a, b, c) instance (ParseFields a, ParseFields b, ParseFields c, ParseFields d) => ParseRecord (a, b, c, d)