{-# LANGUAGE DeriveDataTypeable #-}

-- | The underlying CmdArgs type.
module System.Console.CmdArgs.Implicit.Type(
    -- cmdArgs_privateArgsSeen is exported, otherwise Haddock
    -- gets confused when using RecordWildCards
    CmdArgs(..), cmdArgsHasValue, embed, reembed,
    CmdArgsPrivate, incArgsSeen, getArgsSeen
    ) where

import System.Console.CmdArgs.Verbosity

import Data.Data
import Data.Maybe


-- | A structure to store the additional data relating to @--help@,
--   @--version@, @--quiet@ and @--verbose@.
data CmdArgs a = CmdArgs
    {forall a. CmdArgs a -> a
cmdArgsValue :: a -- ^ The underlying value being wrapped.
    ,forall a. CmdArgs a -> Maybe String
cmdArgsHelp :: Maybe String -- ^ @Just@ if @--help@ is given, then gives the help message for display, including a trailing newline.
    ,forall a. CmdArgs a -> Maybe String
cmdArgsVersion :: Maybe String -- ^ @Just@ if @--version@ is given, then gives the version message for display, including a trailing newline.
    ,forall a. CmdArgs a -> Maybe Verbosity
cmdArgsVerbosity :: Maybe Verbosity -- ^ @Just@ if @--quiet@ or @--verbose@ is given, then gives the verbosity to use.
    ,forall a. CmdArgs a -> CmdArgsPrivate
cmdArgsPrivate :: CmdArgsPrivate -- ^ Private: Only exported due to Haddock limitations.
    }
    deriving (Int -> CmdArgs a -> ShowS
forall a. Show a => Int -> CmdArgs a -> ShowS
forall a. Show a => [CmdArgs a] -> ShowS
forall a. Show a => CmdArgs a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CmdArgs a] -> ShowS
$cshowList :: forall a. Show a => [CmdArgs a] -> ShowS
show :: CmdArgs a -> String
$cshow :: forall a. Show a => CmdArgs a -> String
showsPrec :: Int -> CmdArgs a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> CmdArgs a -> ShowS
Show,CmdArgs a -> CmdArgs a -> Bool
forall a. Eq a => CmdArgs a -> CmdArgs a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CmdArgs a -> CmdArgs a -> Bool
$c/= :: forall a. Eq a => CmdArgs a -> CmdArgs a -> Bool
== :: CmdArgs a -> CmdArgs a -> Bool
$c== :: forall a. Eq a => CmdArgs a -> CmdArgs a -> Bool
Eq,CmdArgs a -> CmdArgs a -> Bool
CmdArgs a -> CmdArgs a -> Ordering
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {a}. Ord a => Eq (CmdArgs a)
forall a. Ord a => CmdArgs a -> CmdArgs a -> Bool
forall a. Ord a => CmdArgs a -> CmdArgs a -> Ordering
forall a. Ord a => CmdArgs a -> CmdArgs a -> CmdArgs a
min :: CmdArgs a -> CmdArgs a -> CmdArgs a
$cmin :: forall a. Ord a => CmdArgs a -> CmdArgs a -> CmdArgs a
max :: CmdArgs a -> CmdArgs a -> CmdArgs a
$cmax :: forall a. Ord a => CmdArgs a -> CmdArgs a -> CmdArgs a
>= :: CmdArgs a -> CmdArgs a -> Bool
$c>= :: forall a. Ord a => CmdArgs a -> CmdArgs a -> Bool
> :: CmdArgs a -> CmdArgs a -> Bool
$c> :: forall a. Ord a => CmdArgs a -> CmdArgs a -> Bool
<= :: CmdArgs a -> CmdArgs a -> Bool
$c<= :: forall a. Ord a => CmdArgs a -> CmdArgs a -> Bool
< :: CmdArgs a -> CmdArgs a -> Bool
$c< :: forall a. Ord a => CmdArgs a -> CmdArgs a -> Bool
compare :: CmdArgs a -> CmdArgs a -> Ordering
$ccompare :: forall a. Ord a => CmdArgs a -> CmdArgs a -> Ordering
Ord,CmdArgs a -> DataType
CmdArgs a -> Constr
forall {a}. Data a => Typeable (CmdArgs a)
forall a. Data a => CmdArgs a -> DataType
forall a. Data a => CmdArgs a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b) -> CmdArgs a -> CmdArgs a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> CmdArgs a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> CmdArgs a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CmdArgs a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CmdArgs a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> CmdArgs a -> m (CmdArgs a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> CmdArgs a -> m (CmdArgs a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (CmdArgs a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CmdArgs a -> c (CmdArgs a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (CmdArgs a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (CmdArgs a))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (CmdArgs a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CmdArgs a -> c (CmdArgs a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (CmdArgs a))
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CmdArgs a -> m (CmdArgs a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> CmdArgs a -> m (CmdArgs a)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CmdArgs a -> m (CmdArgs a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> CmdArgs a -> m (CmdArgs a)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CmdArgs a -> m (CmdArgs a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> CmdArgs a -> m (CmdArgs a)
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CmdArgs a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> CmdArgs a -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> CmdArgs a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> CmdArgs a -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CmdArgs a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CmdArgs a -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CmdArgs a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CmdArgs a -> r
gmapT :: (forall b. Data b => b -> b) -> CmdArgs a -> CmdArgs a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> CmdArgs a -> CmdArgs a
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (CmdArgs a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (CmdArgs a))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (CmdArgs a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (CmdArgs a))
dataTypeOf :: CmdArgs a -> DataType
$cdataTypeOf :: forall a. Data a => CmdArgs a -> DataType
toConstr :: CmdArgs a -> Constr
$ctoConstr :: forall a. Data a => CmdArgs a -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (CmdArgs a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (CmdArgs a)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CmdArgs a -> c (CmdArgs a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CmdArgs a -> c (CmdArgs a)
Data,Typeable)

cmdArgsHasValue :: CmdArgs a -> Bool
cmdArgsHasValue :: forall a. CmdArgs a -> Bool
cmdArgsHasValue CmdArgs a
x = forall a. Maybe a -> Bool
isNothing (forall a. CmdArgs a -> Maybe String
cmdArgsHelp CmdArgs a
x) Bool -> Bool -> Bool
&& forall a. Maybe a -> Bool
isNothing (forall a. CmdArgs a -> Maybe String
cmdArgsVersion CmdArgs a
x)

instance Functor CmdArgs where
    fmap :: forall a b. (a -> b) -> CmdArgs a -> CmdArgs b
fmap a -> b
f CmdArgs a
x = CmdArgs a
x{cmdArgsValue :: b
cmdArgsValue = a -> b
f forall a b. (a -> b) -> a -> b
$ forall a. CmdArgs a -> a
cmdArgsValue CmdArgs a
x}


embed :: a -> CmdArgs a
embed :: forall a. a -> CmdArgs a
embed a
x = forall a.
a
-> Maybe String
-> Maybe String
-> Maybe Verbosity
-> CmdArgsPrivate
-> CmdArgs a
CmdArgs a
x forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing (Int -> CmdArgsPrivate
CmdArgsPrivate Int
0)

reembed :: CmdArgs a -> (a, a -> CmdArgs a)
reembed :: forall a. CmdArgs a -> (a, a -> CmdArgs a)
reembed CmdArgs a
x = (forall a. CmdArgs a -> a
cmdArgsValue CmdArgs a
x, \a
y -> CmdArgs a
x{cmdArgsValue :: a
cmdArgsValue=a
y})


data CmdArgsPrivate = CmdArgsPrivate
    Int -- ^ The number of arguments that have been seen
    deriving (CmdArgsPrivate -> CmdArgsPrivate -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CmdArgsPrivate -> CmdArgsPrivate -> Bool
$c/= :: CmdArgsPrivate -> CmdArgsPrivate -> Bool
== :: CmdArgsPrivate -> CmdArgsPrivate -> Bool
$c== :: CmdArgsPrivate -> CmdArgsPrivate -> Bool
Eq,Eq CmdArgsPrivate
CmdArgsPrivate -> CmdArgsPrivate -> Bool
CmdArgsPrivate -> CmdArgsPrivate -> Ordering
CmdArgsPrivate -> CmdArgsPrivate -> CmdArgsPrivate
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: CmdArgsPrivate -> CmdArgsPrivate -> CmdArgsPrivate
$cmin :: CmdArgsPrivate -> CmdArgsPrivate -> CmdArgsPrivate
max :: CmdArgsPrivate -> CmdArgsPrivate -> CmdArgsPrivate
$cmax :: CmdArgsPrivate -> CmdArgsPrivate -> CmdArgsPrivate
>= :: CmdArgsPrivate -> CmdArgsPrivate -> Bool
$c>= :: CmdArgsPrivate -> CmdArgsPrivate -> Bool
> :: CmdArgsPrivate -> CmdArgsPrivate -> Bool
$c> :: CmdArgsPrivate -> CmdArgsPrivate -> Bool
<= :: CmdArgsPrivate -> CmdArgsPrivate -> Bool
$c<= :: CmdArgsPrivate -> CmdArgsPrivate -> Bool
< :: CmdArgsPrivate -> CmdArgsPrivate -> Bool
$c< :: CmdArgsPrivate -> CmdArgsPrivate -> Bool
compare :: CmdArgsPrivate -> CmdArgsPrivate -> Ordering
$ccompare :: CmdArgsPrivate -> CmdArgsPrivate -> Ordering
Ord,Typeable CmdArgsPrivate
CmdArgsPrivate -> DataType
CmdArgsPrivate -> Constr
(forall b. Data b => b -> b) -> CmdArgsPrivate -> CmdArgsPrivate
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> CmdArgsPrivate -> u
forall u. (forall d. Data d => d -> u) -> CmdArgsPrivate -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CmdArgsPrivate -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CmdArgsPrivate -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> CmdArgsPrivate -> m CmdArgsPrivate
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> CmdArgsPrivate -> m CmdArgsPrivate
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CmdArgsPrivate
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CmdArgsPrivate -> c CmdArgsPrivate
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CmdArgsPrivate)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c CmdArgsPrivate)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> CmdArgsPrivate -> m CmdArgsPrivate
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> CmdArgsPrivate -> m CmdArgsPrivate
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> CmdArgsPrivate -> m CmdArgsPrivate
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> CmdArgsPrivate -> m CmdArgsPrivate
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> CmdArgsPrivate -> m CmdArgsPrivate
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> CmdArgsPrivate -> m CmdArgsPrivate
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> CmdArgsPrivate -> u
$cgmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> CmdArgsPrivate -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> CmdArgsPrivate -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> CmdArgsPrivate -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CmdArgsPrivate -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CmdArgsPrivate -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CmdArgsPrivate -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CmdArgsPrivate -> r
gmapT :: (forall b. Data b => b -> b) -> CmdArgsPrivate -> CmdArgsPrivate
$cgmapT :: (forall b. Data b => b -> b) -> CmdArgsPrivate -> CmdArgsPrivate
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c CmdArgsPrivate)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c CmdArgsPrivate)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CmdArgsPrivate)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CmdArgsPrivate)
dataTypeOf :: CmdArgsPrivate -> DataType
$cdataTypeOf :: CmdArgsPrivate -> DataType
toConstr :: CmdArgsPrivate -> Constr
$ctoConstr :: CmdArgsPrivate -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CmdArgsPrivate
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CmdArgsPrivate
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CmdArgsPrivate -> c CmdArgsPrivate
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CmdArgsPrivate -> c CmdArgsPrivate
Data,Typeable)

incArgsSeen :: CmdArgs a -> CmdArgs a
incArgsSeen x :: CmdArgs a
x@CmdArgs{cmdArgsPrivate :: forall a. CmdArgs a -> CmdArgsPrivate
cmdArgsPrivate = CmdArgsPrivate Int
i} = CmdArgs a
x{cmdArgsPrivate :: CmdArgsPrivate
cmdArgsPrivate = Int -> CmdArgsPrivate
CmdArgsPrivate (Int
iforall a. Num a => a -> a -> a
+Int
1)}
getArgsSeen :: CmdArgs a -> Int
getArgsSeen CmdArgs{cmdArgsPrivate :: forall a. CmdArgs a -> CmdArgsPrivate
cmdArgsPrivate = CmdArgsPrivate Int
i} = Int
i

instance Show CmdArgsPrivate where show :: CmdArgsPrivate -> String
show CmdArgsPrivate
_ = String
"CmdArgsPrivate"