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 Paths_hablo as Hablo (version)
|
||||
import System.Directory (doesDirectoryExist, doesFileExist, makeAbsolute)
|
||||
import System.Exit (die, exitSuccess)
|
||||
import System.Exit (die)
|
||||
import System.FilePath ((</>), dropTrailingPathSeparator, isValid)
|
||||
|
||||
data Arguments = BlogConfig {
|
||||
|
@ -118,10 +118,8 @@ checkAndMakeAbsolute aBlogConfig = do
|
|||
|
||||
get :: IO Arguments
|
||||
get = do
|
||||
args <- execParser $
|
||||
info
|
||||
(arguments <**> helper)
|
||||
(fullDesc <> header ("Hablo v" ++ showVersion Hablo.version))
|
||||
case args of
|
||||
Version -> (putStrLn $ showVersion Hablo.version) >> exitSuccess
|
||||
BlogConfig {} -> checkAndMakeAbsolute args
|
||||
checkAndMakeAbsolute =<< (execParser $
|
||||
info
|
||||
(arguments <**> helper)
|
||||
(fullDesc <> header ("Hablo v" ++ showVersion Hablo.version))
|
||||
)
|
||||
|
|
19
src/Main.hs
19
src/Main.hs
|
@ -1,16 +1,21 @@
|
|||
module Main where
|
||||
|
||||
import Arguments (Arguments(..))
|
||||
import qualified Arguments (get)
|
||||
import qualified Blog (build)
|
||||
import Control.Monad.Reader (runReaderT)
|
||||
import Data.Version (showVersion)
|
||||
import qualified HTML (generate)
|
||||
import qualified JS (generate)
|
||||
import Control.Monad.Reader (runReaderT)
|
||||
import qualified Paths_hablo as Hablo (version)
|
||||
import System.Exit (exitSuccess)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
Arguments.get
|
||||
>>= Blog.build
|
||||
>>= runReaderT (do
|
||||
HTML.generate
|
||||
JS.generate
|
||||
)
|
||||
arguments <- Arguments.get
|
||||
case arguments of
|
||||
Version -> (putStrLn $ showVersion Hablo.version) >> exitSuccess
|
||||
config@(BlogConfig {}) -> Blog.build config >>= runReaderT (do
|
||||
HTML.generate
|
||||
JS.generate
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue