diff options
author | Andor Penzes <andor.penzes@gmail.com> | 2016-06-25 23:30:55 +0200 |
---|---|---|
committer | Andor Penzes <andor.penzes@gmail.com> | 2016-06-25 23:30:55 +0200 |
commit | ac1bb0820fb3368bc902bf9d7b5d58ae0eeb2ec8 (patch) | |
tree | 0336a89d3c8d69ef19c89f4f6086f5e5acc5aa0d | |
parent | e73ad1cbaca363323879e25bf0462eff486d26ad (diff) |
Add '--version' argument.
The abortOption is used instead of the switch. The swtich is
always parsed blocking the compiler' option in the alternative
case. I did not want to do a serious refactor here.
-rw-r--r-- | tool/Compiler.hs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/tool/Compiler.hs b/tool/Compiler.hs index e3fdd7a3..20665ce7 100644 --- a/tool/Compiler.hs +++ b/tool/Compiler.hs | |||
@@ -11,7 +11,7 @@ import LambdaCube.Compiler | |||
11 | addInfo i p = info (helper <*> p) i | 11 | addInfo i p = info (helper <*> p) i |
12 | 12 | ||
13 | main :: IO () | 13 | main :: IO () |
14 | main = join $ execParser $ addInfo i $ subparser ( | 14 | main = join $ execParser $ addInfo i $ versionOption <*> subparser ( |
15 | command "compile" (addInfo (progDesc "compiles LambdaCube3D source to JSON IR") compile') | 15 | command "compile" (addInfo (progDesc "compiles LambdaCube3D source to JSON IR") compile') |
16 | <> command "parse" (addInfo (progDesc "parses LambdaCube3D source") $ parse | 16 | <> command "parse" (addInfo (progDesc "parses LambdaCube3D source") $ parse |
17 | <$> argument str (metavar "SOURCE_FILE") | 17 | <$> argument str (metavar "SOURCE_FILE") |
@@ -33,7 +33,17 @@ main = join $ execParser $ addInfo i $ subparser ( | |||
33 | 33 | ||
34 | i = fullDesc | 34 | i = fullDesc |
35 | <> progDesc "executes command (default to compile if no command is given)" | 35 | <> progDesc "executes command (default to compile if no command is given)" |
36 | <> header ("LambdaCube 3D compiler " ++ showVersion version) | 36 | <> header versionStr |
37 | |||
38 | versionStr :: String | ||
39 | versionStr = "LambdaCube 3D compiler " ++ showVersion version | ||
40 | |||
41 | versionOption :: Parser (a -> a) | ||
42 | versionOption = abortOption (InfoMsg versionStr) $ mconcat | ||
43 | [ long "version" | ||
44 | , short 'v' | ||
45 | , help "Print version." | ||
46 | ] | ||
37 | 47 | ||
38 | prettyPrint srcName output = do | 48 | prettyPrint srcName output = do |
39 | let baseName = dropExtension srcName | 49 | let baseName = dropExtension srcName |