{-# LANGUAGE DeriveGeneric #-} module Data.ItCli where import Control.Monad.Reader import Control.Monad.State import Control.Monad.Except import Control.Monad.Writer import Data.Time (UTCTime) import System.FilePath (hasExtension) import GHC.Generics import qualified Data.UUID as UUID data Config = Config { _itCliName :: Name } deriving (Show, Eq, Ord, Read) type Name = String type Logs = [String] type ItCliM = ReaderT Config (ExceptT String (WriterT Logs IO)) data CommentMessage = CommentMessage String | FileAttachment FilePath deriving (Show, Eq, Ord, Read, Generic) type IssueId = UUID.UUID type IssueIdArg = String type IssueTitle = String data IssueMeta = IssueMeta { _issueTitle :: IssueTitle , _issueClosed :: Bool , _issueDate :: UTCTime } deriving (Show, Eq, Ord, Read, Generic) data Comment = Comment { _commentDate :: UTCTime , _commentName :: Name , _commentMessage :: CommentMessage } deriving (Show, Eq, Ord, Read, Generic) newtype Comments = Comments {fromComments :: [Comment]} deriving (Show, Eq, Ord, Generic) type ListFilterArgs = Maybe Bool class Display a where display :: a -> String instance Display UUID.UUID where display = take 8 . UUID.toString instance Display Bool where display True = "c" display False = "o" commentMessageFromString :: String -> CommentMessage commentMessageFromString arg = case isFilePath (words arg) of True -> FileAttachment arg False -> CommentMessage arg where isFilePath [] = False isFilePath (x:[]) = hasExtension x isFilePath _ = False