diff options
author | pacien | 2019-12-27 14:44:07 +0100 |
---|---|---|
committer | pacien | 2019-12-27 14:44:07 +0100 |
commit | 45df822904cd1759ea4be4bf0c125d8fb6542479 (patch) | |
tree | ab923e173f4e660982f1f882b10ffd626a869e0a /compiler/app/Main.hs | |
parent | 1e57d76eadb2192be2b3d9343d4ddfeccc996bcb (diff) | |
download | ldgallery-45df822904cd1759ea4be4bf0c125d8fb6542479.tar.gz |
compiler: switch to cmdargs
Diffstat (limited to 'compiler/app/Main.hs')
-rw-r--r-- | compiler/app/Main.hs | 60 |
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 | ||
24 | module Main where | 23 | module Main where |
25 | 24 | ||
26 | import Options.Applicative | 25 | import Paths_ldgallery_compiler (version) |
27 | import Data.Semigroup ((<>)) | 26 | import Data.Version (showVersion) |
27 | import System.Console.CmdArgs | ||
28 | import Compiler | 28 | import Compiler |
29 | 29 | ||
30 | data Args = Args | 30 | |
31 | data 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 | |||
37 | options = 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 | ||
35 | args :: Parser Args | ||
36 | args = 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 | ||
56 | main :: IO () | 54 | main :: IO () |
57 | main = | 55 | main = |
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" ) | ||