{-# LANGUAGE RecordWildCards, PatternGuards #-}
module System.Console.CmdArgs.Implicit(
cmdArgs, cmdArgsMode, cmdArgsRun, cmdArgs_, cmdArgsMode_, cmdArgsApply, CmdArgs(..),
module System.Console.CmdArgs.Implicit.UI,
(&=), modes, enum,
(+=), record, atom, Annotate((:=)), enum_, modes_,
module System.Console.CmdArgs.Verbosity,
module System.Console.CmdArgs.Default,
Ann, Mode,
Data, Typeable
) where
import Data.Data
import Data.Maybe
import Data.Generics.Any
import System.Exit
import System.Console.CmdArgs.Explicit(Mode,processArgs,remap,modeReform)
import System.Console.CmdArgs.Implicit.Ann
import System.Console.CmdArgs.Annotate hiding ((&=))
import qualified System.Console.CmdArgs.Annotate as A((&=))
import System.Console.CmdArgs.Implicit.Type
import System.Console.CmdArgs.Implicit.Local
import System.Console.CmdArgs.Implicit.Global
import System.Console.CmdArgs.Implicit.UI
import System.Console.CmdArgs.Verbosity
import System.Console.CmdArgs.Default
cmdArgs :: Data a => a -> IO a
cmdArgs :: a -> IO a
cmdArgs = Mode (CmdArgs a) -> IO a
forall a. Mode (CmdArgs a) -> IO a
cmdArgsRun (Mode (CmdArgs a) -> IO a) -> (a -> Mode (CmdArgs a)) -> a -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Mode (CmdArgs a)
forall a. Data a => a -> Mode (CmdArgs a)
cmdArgsMode
cmdArgs_ :: Data a => Annotate Ann -> IO a
cmdArgs_ :: Annotate Ann -> IO a
cmdArgs_ = Mode (CmdArgs a) -> IO a
forall a. Mode (CmdArgs a) -> IO a
cmdArgsRun (Mode (CmdArgs a) -> IO a)
-> (Annotate Ann -> Mode (CmdArgs a)) -> Annotate Ann -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Annotate Ann -> Mode (CmdArgs a)
forall a. Data a => Annotate Ann -> Mode (CmdArgs a)
cmdArgsMode_
cmdArgsCapture :: Data a => Capture Ann -> Mode (CmdArgs a)
cmdArgsCapture :: Capture Ann -> Mode (CmdArgs a)
cmdArgsCapture = (CmdArgs Any -> CmdArgs a)
-> (CmdArgs a -> (CmdArgs Any, CmdArgs Any -> CmdArgs a))
-> Mode (CmdArgs Any)
-> Mode (CmdArgs a)
forall (m :: * -> *) a b.
Remap m =>
(a -> b) -> (b -> (a, a -> b)) -> m a -> m b
remap CmdArgs Any -> CmdArgs a
embed CmdArgs a -> (CmdArgs Any, CmdArgs Any -> CmdArgs a)
forall (f :: * -> *) a.
(Functor f, Data a) =>
f a -> (f Any, CmdArgs Any -> CmdArgs a)
proj (Mode (CmdArgs Any) -> Mode (CmdArgs a))
-> (Capture Ann -> Mode (CmdArgs Any))
-> Capture Ann
-> Mode (CmdArgs a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Prog_ -> Mode (CmdArgs Any)
global (Prog_ -> Mode (CmdArgs Any))
-> (Capture Ann -> Prog_) -> Capture Ann -> Mode (CmdArgs Any)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Capture Ann -> Prog_
local
where embed :: CmdArgs Any -> CmdArgs a
embed = (Any -> a) -> CmdArgs Any -> CmdArgs a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Any -> a
forall a. Typeable a => Any -> a
fromAny
proj :: f a -> (f Any, CmdArgs Any -> CmdArgs a)
proj f a
x = ((a -> Any) -> f a -> f Any
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> Any
forall a. Data a => a -> Any
Any f a
x, CmdArgs Any -> CmdArgs a
embed)
cmdArgsMode :: Data a => a -> Mode (CmdArgs a)
cmdArgsMode :: a -> Mode (CmdArgs a)
cmdArgsMode = Capture Ann -> Mode (CmdArgs a)
forall a. Data a => Capture Ann -> Mode (CmdArgs a)
cmdArgsCapture (Capture Ann -> Mode (CmdArgs a))
-> (a -> Capture Ann) -> a -> Mode (CmdArgs a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Capture Ann
forall val ann. (Data val, Data ann) => val -> Capture ann
capture
cmdArgsMode_ :: Data a => Annotate Ann -> Mode (CmdArgs a)
cmdArgsMode_ :: Annotate Ann -> Mode (CmdArgs a)
cmdArgsMode_ = Capture Ann -> Mode (CmdArgs a)
forall a. Data a => Capture Ann -> Mode (CmdArgs a)
cmdArgsCapture (Capture Ann -> Mode (CmdArgs a))
-> (Annotate Ann -> Capture Ann)
-> Annotate Ann
-> Mode (CmdArgs a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Annotate Ann -> Capture Ann
forall a. Show a => Annotate a -> Capture a
capture_
cmdArgsRun :: Mode (CmdArgs a) -> IO a
cmdArgsRun :: Mode (CmdArgs a) -> IO a
cmdArgsRun Mode (CmdArgs a)
m = CmdArgs a -> IO a
forall a. CmdArgs a -> IO a
cmdArgsApply (CmdArgs a -> IO a) -> IO (CmdArgs a) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Mode (CmdArgs a) -> IO (CmdArgs a)
forall a. Mode a -> IO a
processArgs Mode (CmdArgs a)
m
cmdArgsApply :: CmdArgs a -> IO a
cmdArgsApply :: CmdArgs a -> IO a
cmdArgsApply CmdArgs{a
Maybe String
Maybe Verbosity
CmdArgsPrivate
cmdArgsPrivate :: forall a. CmdArgs a -> CmdArgsPrivate
cmdArgsVerbosity :: forall a. CmdArgs a -> Maybe Verbosity
cmdArgsVersion :: forall a. CmdArgs a -> Maybe String
cmdArgsHelp :: forall a. CmdArgs a -> Maybe String
cmdArgsValue :: forall a. CmdArgs a -> a
cmdArgsPrivate :: CmdArgsPrivate
cmdArgsVerbosity :: Maybe Verbosity
cmdArgsVersion :: Maybe String
cmdArgsHelp :: Maybe String
cmdArgsValue :: a
..}
| Just String
x <- Maybe String
cmdArgsHelp = do String -> IO ()
putStr String
x; IO a
forall a. IO a
exitSuccess
| Just String
x <- Maybe String
cmdArgsVersion = do String -> IO ()
putStr String
x; IO a
forall a. IO a
exitSuccess
| Bool
otherwise = do
IO () -> (Verbosity -> IO ()) -> Maybe Verbosity -> IO ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()) Verbosity -> IO ()
setVerbosity Maybe Verbosity
cmdArgsVerbosity
a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return a
cmdArgsValue
_cmdArgsReform :: Mode (CmdArgs a) -> CmdArgs a -> [String]
_cmdArgsReform :: Mode (CmdArgs a) -> CmdArgs a -> [String]
_cmdArgsReform Mode (CmdArgs a)
m CmdArgs a
x = [String] -> Maybe [String] -> [String]
forall a. a -> Maybe a -> a
fromMaybe (String -> [String]
forall a. HasCallStack => String -> a
error String
err) (Maybe [String] -> [String]) -> Maybe [String] -> [String]
forall a b. (a -> b) -> a -> b
$ Mode (CmdArgs a) -> CmdArgs a -> Maybe [String]
forall a. Mode a -> a -> Maybe [String]
modeReform Mode (CmdArgs a)
m CmdArgs a
x
where err :: String
err = String
"System.Console.CmdArgs.Implicit.cmdArgsReform: cannot reform the arguments, perhaps the mode was not " String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
"generated by cmdArgsMode/cmdArgsMode_ ?"
modes :: Data val => [val] -> val
modes :: [val] -> val
modes = [val] -> val
forall val. Data val => [val] -> val
many
enum :: Data val => [val] -> val
enum :: [val] -> val
enum = [val] -> val
forall val. Data val => [val] -> val
many
{-# INLINE (&=) #-}
(&=) :: Data val => val -> Ann -> val
&= :: val -> Ann -> val
(&=) = val -> Ann -> val
forall val ann. (Data val, Data ann) => val -> ann -> val
(A.&=)
enum_ :: (Data c, Data f) => (c -> f) -> [Annotate Ann] -> Annotate Ann
enum_ :: (c -> f) -> [Annotate Ann] -> Annotate Ann
enum_ = (c -> f) -> [Annotate Ann] -> Annotate Ann
forall ann c f.
(Data c, Data f) =>
(c -> f) -> [Annotate ann] -> Annotate ann
(:=+)
modes_ :: [Annotate Ann] -> Annotate Ann
modes_ :: [Annotate Ann] -> Annotate Ann
modes_ = [Annotate Ann] -> Annotate Ann
forall a. [Annotate a] -> Annotate a
many_