harg 0.3.0.0 → 0.4.0.0
raw patch · 6 files changed
+40/−16 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Options.Harg.Construct: class HasDefaultValStr o (attr :: [OptAttr])
- Options.Harg.Construct: instance Options.Harg.Construct.HasDefaultValStr Options.Harg.Types.ArgumentOpt a
- Options.Harg.Construct: instance Options.Harg.Construct.HasDefaultValStr Options.Harg.Types.OptionOpt a
+ Options.Harg: class Build structure (f :: Type -> Type) k | f structure -> k
+ Options.Harg: class Construct (f :: Type -> Type) structure
+ Options.Harg: fromNested :: Construct Identity b => Nested b Identity -> b
+ Options.Harg: fromSingle :: Single a Identity -> a
+ Options.Harg.Construct: class HasDefaultStr o (attr :: [OptAttr])
+ Options.Harg.Construct: instance Options.Harg.Construct.HasDefaultStr Options.Harg.Types.ArgumentOpt a
+ Options.Harg.Construct: instance Options.Harg.Construct.HasDefaultStr Options.Harg.Types.OptionOpt a
+ Options.Harg.Nested: fromNested :: Construct Identity b => Nested b Identity -> b
+ Options.Harg.Single: fromSingle :: Single a Identity -> a
- Options.Harg: defaultStr :: (HasDefaultValStr o attr, NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "defaultStr" '["defaultVal", "required"]), NotInAttrs OptOptional attr (IncompatibleAttrsErr "defaultStr" "optional")) => String -> o attr a -> o (OptDefault : attr) a
+ Options.Harg: defaultStr :: (HasDefaultStr o attr, NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "defaultStr" '["defaultVal", "required"]), NotInAttrs OptOptional attr (IncompatibleAttrsErr "defaultStr" "optional")) => String -> o attr a -> o (OptDefault : attr) a
- Options.Harg.Construct: defaultStr :: (HasDefaultValStr o attr, NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "defaultStr" '["defaultVal", "required"]), NotInAttrs OptOptional attr (IncompatibleAttrsErr "defaultStr" "optional")) => String -> o attr a -> o (OptDefault : attr) a
+ Options.Harg.Construct: defaultStr :: (HasDefaultStr o attr, NotInAttrs OptDefault attr (DuplicateAttrMultipleErr "defaultStr" '["defaultVal", "required"]), NotInAttrs OptOptional attr (IncompatibleAttrsErr "defaultStr" "optional")) => String -> o attr a -> o (OptDefault : attr) a
Files
- CHANGELOG.md +6/−0
- harg.cabal +1/−1
- src/Options/Harg.hs +4/−0
- src/Options/Harg/Construct.hs +4/−4
- src/Options/Harg/Nested.hs +15/−6
- src/Options/Harg/Single.hs +10/−5
CHANGELOG.md view
@@ -1,5 +1,11 @@ # Changelog for harg +## 0.4.0.0 [2019.09.16]++- Fix wrong name in previous release (`HasDefaultValStr` -> `HasDefaultStr`)+- Expose `fromSingle` and `fromNested` for when f ~ Identity+- Expose classes `Build` and `Construct` from `higgledy`+ ## 0.3.0.0 [2019.09.16] - Remove `*With` variants of option constructors and make the `*With` variant behaviour the default
harg.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.2 name: harg-version: 0.3.0.0+version: 0.4.0.0 synopsis: Haskell program configuration using higher kinded data description: Please see the README on GitHub at <https://github.com/alexpeits/harg#readme> homepage: https://github.com/alexpeits/harg
src/Options/Harg.hs view
@@ -12,10 +12,12 @@ , Single (..) , single+ , fromSingle , Nested (..) , nested , getNested+ , fromNested , AssocListF (..) , (:+)@@ -82,7 +84,9 @@ -- *** higgledy , HKD.HKD+ , HKD.Build , HKD.build+ , HKD.Construct , HKD.construct ) where
src/Options/Harg/Construct.hs view
@@ -87,7 +87,7 @@ instance HasDefaultVal ArgumentOpt a where defaultVal a o = o { _aDefaultVal = Just a } -class HasDefaultValStr o (attr :: [OptAttr]) where+class HasDefaultStr o (attr :: [OptAttr]) where -- | Add a default unparsed value to an option. Cannot be used in conjuction -- with 'defaultVal', 'required' or 'optional'. defaultStr@@ -96,10 +96,10 @@ ) => String -> o attr a -> o (OptDefault ': attr) a -instance HasDefaultValStr OptionOpt a where+instance HasDefaultStr OptionOpt a where defaultStr s o = o { _oDefaultStr = Just s } -instance HasDefaultValStr ArgumentOpt a where+instance HasDefaultStr ArgumentOpt a where defaultStr s o = o { _aDefaultStr = Just s } class HasRequired o (attr :: [OptAttr]) where@@ -118,7 +118,7 @@ required o = o { _aDefaultVal = Nothing } -- | Class for options that can be optional. Cannot be used in conjunction with--- 'HasDefaultVal', 'HasDefaultValStr' or 'HasRequired'. Note that this will turn a+-- 'HasDefaultVal', 'HasDefaultStr' or 'HasRequired'. Note that this will turn a -- parser for @a@ into a parser for @Maybe a@, modifying the reader function -- appropriately. -- For example:
src/Options/Harg/Nested.hs view
@@ -9,13 +9,14 @@ {-# OPTIONS_GHC -fno-warn-orphans #-} module Options.Harg.Nested where -import Data.Coerce (Coercible, coerce)-import Data.Kind (Type)-import GHC.Generics (Generic)+import Data.Coerce (Coercible, coerce)+import Data.Functor.Identity (Identity(..))+import Data.Kind (Type)+import GHC.Generics (Generic) -import qualified Data.Aeson as JSON-import qualified Data.Barbie as B-import qualified Data.Generic.HKD as HKD+import qualified Data.Aeson as JSON+import qualified Data.Barbie as B+import qualified Data.Generic.HKD as HKD -- Orphan HKD FromJSON instance instance JSON.GFromJSON JSON.Zero (HKD.HKD_ f structure)@@ -74,6 +75,14 @@ => Nested b f -> f b getNested (Nested hkd) = HKD.construct hkd++-- | Helper for when f ~ Identity+fromNested+ :: HKD.Construct Identity b+ => Nested b Identity+ -> b+fromNested+ = runIdentity . getNested deriving newtype instance Generic (HKD.HKD b f) => Generic (Nested b f) deriving newtype instance JSON.FromJSON (HKD.HKD b f) => JSON.FromJSON (Nested b f)
src/Options/Harg/Single.hs view
@@ -5,13 +5,14 @@ {-# LANGUAGE UndecidableInstances #-} module Options.Harg.Single where -import qualified Data.Functor.Product as P-import Data.Kind (Type)-import GHC.Generics (Generic)+import Data.Functor.Identity (Identity(..))+import qualified Data.Functor.Product as P+import Data.Kind (Type)+import GHC.Generics (Generic) -import qualified Data.Aeson as JSON+import qualified Data.Aeson as JSON -import qualified Data.Barbie as B+import qualified Data.Barbie as B -- | @Single a f@ is a newtype around @f a@, which allows mixing non-nested@@ -37,6 +38,10 @@ -- | Wrap a value into a 'Single'. single :: f a -> Single a f single = Single++-- | Helper for when f ~ Identity+fromSingle :: Single a Identity -> a+fromSingle = runIdentity . getSingle deriving instance (Show a, Show (f a)) => Show (Single a f) deriving newtype instance Generic (f a) => Generic (Single a f)