module System.Console.Internal where
import Control.Exception (Exception)
import Data.Map (Map)
import Data.Typeable (Typeable)
import qualified System.Console.GetOpt as GetOpt
type UserCommand = [String]
data Action m
= Action
{
run :: [String] -> Settings -> m ()
, nonOptions :: [String]
, options :: [((Identifier,[OptionName]),GetOpt.OptDescr CanonicalSetting)]
, ignoringOptions :: [GetOpt.OptDescr CanonicalSetting]
}
data Option a = Option
[OptionName]
(GetOpt.OptDescr (Identifier,Maybe String))
a
(Maybe String -> Either String a)
data OptionName
= Short Char
| Long String
deriving (Eq,Ord)
instance Show OptionName where
show (Short c) = '-' : c : []
show (Long i) = "--" ++ i
newtype Identifier
= Id OptionName
deriving (Eq,Ord)
type Setting
= (OptionName,Maybe String)
type CanonicalSetting
= (Identifier,Maybe String)
type Settings
= Map Identifier (Maybe String)
identify :: [OptionName] -> Identifier
identify (n : _) = Id n
identify _ = error "System.Console.Internal.identify: option without option names."
data Command m
= Command
{
name :: String
, description :: String
, action :: Action m
, shorten :: Bool
}
data ConsoleProgramException
= UnknownCommand String
deriving (Typeable)
instance Show ConsoleProgramException where
show (UnknownCommand c) = "Error: unused non-option or unrecognised command: " ++ c
instance Exception ConsoleProgramException