aboutsummaryrefslogtreecommitdiffhomepage
path: root/scaffolder/app
diff options
context:
space:
mode:
authorFrédéric Menou <frederic.menou@fretlink.com>2016-12-08 10:19:15 +0200
committerIsmaël Bouya <ismael.bouya@fretlink.com>2022-05-17 18:01:51 +0200
commita9d77a20008efe82862cc1adbfa7a6d4f09f8ff7 (patch)
treeadf3186fdccaeef19151026cdfbd38a530cf9ecb /scaffolder/app
downloadedi-parser-a9d77a20008efe82862cc1adbfa7a6d4f09f8ff7.tar.gz
edi-parser-a9d77a20008efe82862cc1adbfa7a6d4f09f8ff7.tar.zst
edi-parser-a9d77a20008efe82862cc1adbfa7a6d4f09f8ff7.zip
Release code as open sourceHEADmaster
Diffstat (limited to 'scaffolder/app')
-rw-r--r--scaffolder/app/Main.hs90
1 files changed, 90 insertions, 0 deletions
diff --git a/scaffolder/app/Main.hs b/scaffolder/app/Main.hs
new file mode 100644
index 0000000..646756e
--- /dev/null
+++ b/scaffolder/app/Main.hs
@@ -0,0 +1,90 @@
1{-# LANGUAGE OverloadedStrings #-}
2
3module Main where
4
5import Text.Edifact.BundleReader (BundleReaderEnv (..), readBundle)
6import Text.Edifact.Fetcher (FetchingEnv (..), fetch,
7 readSelectMessages)
8import Text.Edifact.Scaffolder (ScaffoldingEnv (..), scaffold)
9
10import Data.String (fromString)
11import Options.Applicative
12
13main :: IO ()
14main = execParser argumentsParser >>= run
15
16data Command = ScaffoldCommand ScaffoldingEnv
17 | FetchCommand FetchingEnv
18 | BundleReaderCommand BundleReaderEnv
19
20commandParser :: Parser Command
21commandParser =
22 let mkCommand cmd = command (commandName cmd) (info (commandArgumentsParser cmd) (describe cmd))
23 in subparser (foldMap mkCommand [ Scaffold, Fetch, ReadBundle ])
24
25data CommandType = Scaffold | Fetch | ReadBundle
26
27run :: Command -> IO ()
28run (ScaffoldCommand env) = scaffold env
29run (FetchCommand env) = fetch env
30run (BundleReaderCommand env) = readBundle env
31
32commandName :: CommandType -> String
33commandName Scaffold = "scaffold"
34commandName Fetch = "fetch"
35commandName ReadBundle = "read-bundle"
36
37commandArgumentsParser :: CommandType -> Parser Command
38commandArgumentsParser Scaffold =
39 let revisionArg = strOption (long "revision" <> metavar "REVISION")
40 moduleNameArg = strOption (long "module-name" <> metavar "MODULE_NAME" <> value "Text.Edifact")
41 specificationArg = strOption (long "specification" <> metavar "SPECIFICATION" <> value "./specification")
42 srcArg = strOption (long "src" <> metavar "SOURCES" <> value "./src")
43 debugParsingArg = flag False True (long "debug-parsing")
44 arguments = ScaffoldingEnv <$> revisionArg
45 <*> (fromString <$> moduleNameArg)
46 <*> specificationArg
47 <*> srcArg
48 <*> debugParsingArg
49 in ScaffoldCommand <$> arguments
50commandArgumentsParser Fetch =
51 let revisionArg = strOption (long "revision" <> metavar "REVISION")
52 specificationArg = strOption (long "specification" <> metavar "SPECIFICATION" <> value "./specification")
53 selectedMessagesArg = readSelectMessages <$>
54 optional (strOption (long "messages" <> metavar "MESSAGES"))
55 arguments = FetchingEnv <$> revisionArg
56 <*> specificationArg
57 <*> selectedMessagesArg
58 in FetchCommand <$> arguments
59commandArgumentsParser ReadBundle =
60 let revisionArg = strOption (long "revision" <> metavar "REVISION")
61 specificationArg = strOption (long "specification" <> metavar "SPECIFICATION" <> value "./specification")
62 bundle = many (strOption (long "bundle" <> metavar "BUNDLE"))
63 messagesFiles = many (strOption (long "message-file" <> metavar "MESSAGE_FILE"))
64 selectedMessages = many (strOption (long "message" <> metavar "MESSAGE"))
65 segmentsFiles = many (strOption (long "segment-file" <> metavar "SEGMENT_FILE"))
66 compositeFiles = many (strOption (long "composite-file" <> metavar "COMPOSITE_FILE"))
67 simpleFiles = many (strOption (long "simple-file" <> metavar "SIMPLE_FILE"))
68 codedSimpleFiles = many (strOption (long "coded-simple-file" <> metavar "CODED_SIMPLE_FILE"))
69 arguments = BundleReaderEnv <$> revisionArg
70 <*> specificationArg
71 <*> bundle
72 <*> selectedMessages
73 <*> messagesFiles
74 <*> segmentsFiles
75 <*> compositeFiles
76 <*> simpleFiles
77 <*> codedSimpleFiles
78 in BundleReaderCommand <$> arguments
79
80describe :: CommandType -> InfoMod a
81describe Scaffold = progDesc "Scaffold parsers from specification previously fetched"
82describe Fetch = progDesc "Fetch specification from UN website (Deprecated! Use read-bundle instead)"
83describe ReadBundle = progDesc "Read specification bundle downloaded from UN website"
84
85argumentsParser :: ParserInfo Command
86argumentsParser = info (commandParser <**> helper) cliDesc
87
88cliDesc :: InfoMod a
89cliDesc = fullDesc
90 <> header "Let you scaffold parsers from an Edifact specification"