module System.Console.CmdArgs.Implicit.Type(
CmdArgs(..), cmdArgsHasValue, embed, reembed,
CmdArgsPrivate, incArgsSeen, getArgsSeen
) where
import System.Console.CmdArgs.Verbosity
import Data.Data
import Data.Maybe
data CmdArgs a = CmdArgs
{cmdArgsValue :: a
,cmdArgsHelp :: Maybe String
,cmdArgsVersion :: Maybe String
,cmdArgsVerbosity :: Maybe Verbosity
,cmdArgsPrivate :: CmdArgsPrivate
}
deriving (Show,Eq,Ord,Data,Typeable)
cmdArgsHasValue :: CmdArgs a -> Bool
cmdArgsHasValue x = isNothing (cmdArgsHelp x) && isNothing (cmdArgsVersion x)
instance Functor CmdArgs where
fmap f x = x{cmdArgsValue = f $ cmdArgsValue x}
embed :: a -> CmdArgs a
embed x = CmdArgs x Nothing Nothing Nothing (CmdArgsPrivate 0)
reembed :: CmdArgs a -> (a, a -> CmdArgs a)
reembed x = (cmdArgsValue x, \y -> x{cmdArgsValue=y})
data CmdArgsPrivate = CmdArgsPrivate
Int
deriving (Eq,Ord,Data,Typeable)
incArgsSeen x@CmdArgs{cmdArgsPrivate = CmdArgsPrivate i} = x{cmdArgsPrivate = CmdArgsPrivate (i+1)}
getArgsSeen CmdArgs{cmdArgsPrivate = CmdArgsPrivate i} = i
instance Show CmdArgsPrivate where show _ = "CmdArgsPrivate"