]> git.immae.eu Git - github/fretlink/edi-parser.git/blob - specification/app/Main.hs
Release code as open source
[github/fretlink/edi-parser.git] / specification / app / Main.hs
1 module Main
2 ( main
3 ) where
4
5 import Text.Edifact.Common (parseFull)
6 import Text.Edifact.D96A (messageIFCSUM, messageDESADV)
7 import Text.Edifact.Inspect (inspect)
8 import Text.Edifact.Types (Value)
9
10 import Control.Monad ((>=>))
11 import qualified Data.Text.IO as TIO (putStrLn, readFile)
12 import System.Environment (getArgs)
13
14 main :: IO ()
15 main = getArgs >>= dispatch
16
17 dispatch :: [String] -> IO ()
18 dispatch ("ifcsum" : filename : _) = readIFCSUM filename
19 dispatch ("desadv" : filename : _) = readDESADV filename
20 dispatch _ = help
21
22 readIFCSUM :: FilePath -> IO ()
23 readIFCSUM =
24 let display = either print (TIO.putStrLn . inspect)
25 in TIO.readFile >=> display . parseFull messageIFCSUM
26
27 readDESADV :: FilePath -> IO ()
28 readDESADV =
29 let display = either print (TIO.putStrLn . inspect)
30 in TIO.readFile >=> display . parseFull messageDESADV
31
32 help :: IO ()
33 help = do
34 putStrLn "ifcsum <file> : inspect IFCSUM file for revision D96A"
35 putStrLn "desadv <file> : inspect DESADV file for revision D96A"
36 putStrLn "-h|--help : this message"