module System.Console.Hawk.Args.Spec where
import Data.ByteString (ByteString)
data HawkSpec
= Help
| Version
| Eval ExprSpec OutputSpec
| Apply ExprSpec InputSpec OutputSpec
| Map ExprSpec InputSpec OutputSpec
deriving (Show, Eq)
data InputSpec = InputSpec
{ inputSource :: InputSource
, inputFormat :: InputFormat
}
deriving (Show, Eq)
data OutputSpec = OutputSpec
{ outputSink :: OutputSink
, outputFormat :: OutputFormat
}
deriving (Show, Eq)
data InputSource
= NoInput
| UseStdin
| InputFile FilePath
deriving (Show, Eq)
data OutputSink
= UseStdout
deriving (Show, Eq)
data InputFormat
= RawStream
| Records Separator RecordFormat
deriving (Show, Eq)
data RecordFormat
= RawRecord
| Fields Separator
deriving (Show, Eq)
data OutputFormat = OutputFormat
{ recordDelimiter :: Delimiter
, fieldDelimiter :: Delimiter
}
deriving (Show, Eq)
type Delimiter = ByteString
data Separator = Whitespace | Delimiter Delimiter
deriving (Show, Eq)
fromSeparator :: Separator -> Delimiter
fromSeparator Whitespace = " "
fromSeparator (Delimiter d) = d
data ExprSpec = ExprSpec
{ userContextDirectory :: FilePath
, userExpression :: String
}
deriving (Show, Eq)
defaultInputSpec, noInput :: InputSpec
defaultInputSpec = InputSpec UseStdin defaultInputFormat
noInput = InputSpec NoInput defaultInputFormat
defaultOutputSpec :: OutputSpec
defaultOutputSpec = OutputSpec UseStdout defaultOutputFormat
defaultInputFormat :: InputFormat
defaultInputFormat = Records defaultRecordSeparator
$ Fields defaultFieldSeparator
defaultOutputFormat :: OutputFormat
defaultOutputFormat = OutputFormat defaultRecordDelimiter defaultFieldDelimiter
defaultRecordSeparator, defaultFieldSeparator :: Separator
defaultRecordSeparator = Delimiter defaultRecordDelimiter
defaultFieldSeparator = Whitespace
defaultRecordDelimiter, defaultFieldDelimiter :: Delimiter
defaultRecordDelimiter = "\n"
defaultFieldDelimiter = " "