module WithCli.Pure (
  withCliPure,
  WithCliPure(),
  Result(..),
  handleResult,
  HasArguments(argumentsParser),
  atomicArgumentsParser,
  Argument(argumentType, parseArgument),
  -- * Modifiers
  Modifier(..),
  -- * Useful Re-exports
  GHC.Generic,
  Typeable,
  Proxy(..),
) where

import           Data.Proxy
import           Data.Typeable
import           GHC.Generics as GHC

import           WithCli.Argument
import           WithCli.HasArguments
import           WithCli.Modifier
import           WithCli.Parser
import           WithCli.Pure.Internal
import           WithCli.Result

-- | Pure variant of 'WithCli.withCliModified'.
withCliPure :: WithCliPure function a => String -> [Modifier] -> [String]
  -> function
    -- ^ The @function@ parameter can be a
    -- function with arbitrary many parameters as long as they have an instance
    -- for 'HasArguments'. You can choose the return type of @function@ freely,
    -- 'withCliPure' will return it wrapped in 'Result' to account for parse
    -- errors, etc. (see 'Result').
  -> Result a
withCliPure :: forall function a.
WithCliPure function a =>
String -> [Modifier] -> [String] -> function -> Result a
withCliPure String
progName [Modifier]
modifiers [String]
args function
function = forall a. Result a -> Result a
sanitize forall a b. (a -> b) -> a -> b
$ do
  Modifiers
modifiers <- [Modifier] -> Result Modifiers
mkModifiers [Modifier]
modifiers
  forall function output input.
WithCliPure function output =>
String
-> Modifiers
-> Result (Parser Unnormalized input)
-> (input -> function)
-> [String]
-> Result output
run String
progName Modifiers
modifiers (forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a phase. a -> Parser phase a
emptyParser ()) (\ () -> function
function) [String]
args