Put a little responsability back into Main to avoid Arguments having control on main flow
This commit is contained in:
parent
cf1c93fd1e
commit
c0b7285b2f
2 changed files with 18 additions and 15 deletions
|
@ -10,7 +10,7 @@ import Options.Applicative (Parser, ReadM, argument, auto, eitherReader, execPar
|
||||||
import qualified Options.Applicative as Optparse (option)
|
import qualified Options.Applicative as Optparse (option)
|
||||||
import qualified Paths_hablo as Hablo (version)
|
import qualified Paths_hablo as Hablo (version)
|
||||||
import System.Directory (doesDirectoryExist, doesFileExist, makeAbsolute)
|
import System.Directory (doesDirectoryExist, doesFileExist, makeAbsolute)
|
||||||
import System.Exit (die, exitSuccess)
|
import System.Exit (die)
|
||||||
import System.FilePath ((</>), dropTrailingPathSeparator, isValid)
|
import System.FilePath ((</>), dropTrailingPathSeparator, isValid)
|
||||||
|
|
||||||
data Arguments = BlogConfig {
|
data Arguments = BlogConfig {
|
||||||
|
@ -118,10 +118,8 @@ checkAndMakeAbsolute aBlogConfig = do
|
||||||
|
|
||||||
get :: IO Arguments
|
get :: IO Arguments
|
||||||
get = do
|
get = do
|
||||||
args <- execParser $
|
checkAndMakeAbsolute =<< (execParser $
|
||||||
info
|
info
|
||||||
(arguments <**> helper)
|
(arguments <**> helper)
|
||||||
(fullDesc <> header ("Hablo v" ++ showVersion Hablo.version))
|
(fullDesc <> header ("Hablo v" ++ showVersion Hablo.version))
|
||||||
case args of
|
)
|
||||||
Version -> (putStrLn $ showVersion Hablo.version) >> exitSuccess
|
|
||||||
BlogConfig {} -> checkAndMakeAbsolute args
|
|
||||||
|
|
19
src/Main.hs
19
src/Main.hs
|
@ -1,16 +1,21 @@
|
||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
|
import Arguments (Arguments(..))
|
||||||
import qualified Arguments (get)
|
import qualified Arguments (get)
|
||||||
import qualified Blog (build)
|
import qualified Blog (build)
|
||||||
|
import Control.Monad.Reader (runReaderT)
|
||||||
|
import Data.Version (showVersion)
|
||||||
import qualified HTML (generate)
|
import qualified HTML (generate)
|
||||||
import qualified JS (generate)
|
import qualified JS (generate)
|
||||||
import Control.Monad.Reader (runReaderT)
|
import qualified Paths_hablo as Hablo (version)
|
||||||
|
import System.Exit (exitSuccess)
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
Arguments.get
|
arguments <- Arguments.get
|
||||||
>>= Blog.build
|
case arguments of
|
||||||
>>= runReaderT (do
|
Version -> (putStrLn $ showVersion Hablo.version) >> exitSuccess
|
||||||
HTML.generate
|
config@(BlogConfig {}) -> Blog.build config >>= runReaderT (do
|
||||||
JS.generate
|
HTML.generate
|
||||||
)
|
JS.generate
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue