Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] allow passing list literals to mod builders #488

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Options/Applicative/Builder.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE TypeFamilies #-}
module Options.Applicative.Builder (
-- * Parser builders
--
Expand Down Expand Up @@ -118,6 +119,7 @@ import Options.Applicative.Common
import Options.Applicative.Types
import Options.Applicative.Help.Pretty
import Options.Applicative.Help.Chunk
import GHC.Exts (IsList(..))

-- Readers --

Expand Down Expand Up @@ -383,6 +385,11 @@ option r m = mkParser d g rdr
newtype InfoMod a = InfoMod
{ applyInfoMod :: ParserInfo a -> ParserInfo a }

instance IsList (InfoMod a) where
type Item (InfoMod a) = InfoMod a
fromList = mconcat
toList = pure

instance Monoid (InfoMod a) where
mempty = InfoMod id
mappend = (<>)
Expand Down Expand Up @@ -474,6 +481,11 @@ instance Monoid PrefsMod where
mempty = PrefsMod id
mappend = (<>)

instance IsList PrefsMod where
type Item PrefsMod = PrefsMod
fromList = mconcat
toList = pure

instance Semigroup PrefsMod where
m1 <> m2 = PrefsMod $ applyPrefsMod m2 . applyPrefsMod m1

Expand Down
7 changes: 7 additions & 0 deletions src/Options/Applicative/Builder/Internal.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE TypeFamilies #-}
module Options.Applicative.Builder.Internal (
-- * Internals
Mod(..),
Expand Down Expand Up @@ -31,6 +32,7 @@ import Prelude

import Options.Applicative.Common
import Options.Applicative.Types
import GHC.Exts (IsList(..))

data OptionFields a = OptionFields
{ optNames :: [OptName]
Expand Down Expand Up @@ -127,6 +129,11 @@ data Mod f a = Mod (f a -> f a)
(DefaultProp a)
(OptProperties -> OptProperties)

instance IsList (Mod f a) where
type Item (Mod f a) = Mod f a
fromList = mconcat
toList = pure

optionMod :: (OptProperties -> OptProperties) -> Mod f a
optionMod = Mod id mempty

Expand Down