aboutsummaryrefslogtreecommitdiff
path: root/compiler/app/Main.hs
diff options
context:
space:
mode:
authorpacien2019-12-27 14:44:07 +0100
committerpacien2019-12-27 14:44:07 +0100
commit45df822904cd1759ea4be4bf0c125d8fb6542479 (patch)
treeab923e173f4e660982f1f882b10ffd626a869e0a /compiler/app/Main.hs
parent1e57d76eadb2192be2b3d9343d4ddfeccc996bcb (diff)
downloadldgallery-45df822904cd1759ea4be4bf0c125d8fb6542479.tar.gz
compiler: switch to cmdargs
Diffstat (limited to 'compiler/app/Main.hs')
-rw-r--r--compiler/app/Main.hs60
1 files changed, 26 insertions, 34 deletions
diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs
index d9b019a..1773073 100644
--- a/compiler/app/Main.hs
+++ b/compiler/app/Main.hs
@@ -17,50 +17,42 @@
17-- along with this program. If not, see <https://www.gnu.org/licenses/>. 17-- along with this program. If not, see <https://www.gnu.org/licenses/>.
18 18
19{-# LANGUAGE 19{-# LANGUAGE
20 RecordWildCards 20 DeriveDataTypeable
21 , ApplicativeDo
22#-} 21#-}
23 22
24module Main where 23module Main where
25 24
26import Options.Applicative 25import Paths_ldgallery_compiler (version)
27import Data.Semigroup ((<>)) 26import Data.Version (showVersion)
27import System.Console.CmdArgs
28import Compiler 28import Compiler
29 29
30data Args = Args 30
31data Options = Options
31 { inputDir :: String 32 { inputDir :: String
32 , outputDir :: String 33 , outputDir :: String
33 , rebuild :: Bool } 34 , rebuild :: Bool
35 } deriving (Show, Data, Typeable)
36
37options = Options
38 { inputDir = "./"
39 &= typDir
40 &= help "Gallery source directory (default=./)"
41 , outputDir = "./out"
42 &= typDir
43 &= help "Generated gallery output path (default=./out)"
44 , rebuild = False
45 &= help "Invalidate cache and recompile everything"
46 }
47 &= summary ("ldgallery v" ++ (showVersion version) ++ " - a static gallery generator with tags")
48 &= program "ldgallery"
49 &= help "Compile a gallery"
50 &= helpArg [explicit, name "h", name "help"]
51 &= versionArg [explicit, name "v", name "version"]
34 52
35args :: Parser Args
36args = Args
37 <$> strOption
38 ( long "input"
39 <> short 'i'
40 <> metavar "SOURCE DIR"
41 <> value "./"
42 <> showDefault
43 <> help "Gallery source directory" )
44 <*> strOption
45 ( long "output"
46 <> short 'o'
47 <> metavar "OUTPUT DIR"
48 <> value "./out"
49 <> showDefault
50 <> help "Generated gallery output path" )
51 <*> switch
52 ( long "rebuild"
53 <> short 'r'
54 <> help "Invalidate cache and recompile everything" )
55 53
56main :: IO () 54main :: IO ()
57main = 55main =
58 do 56 do
59 options <- execParser opts 57 opts <- cmdArgs options
60 compileGallery (inputDir options) (outputDir options) (rebuild options) 58 compileGallery (inputDir opts) (outputDir opts) (rebuild opts)
61
62 where
63 opts = info (args <**> helper)
64 ( fullDesc
65 <> progDesc "Compile a gallery"
66 <> header "ldgallery - a static gallery generator with tags" )