diff --git a/app/Main.hs b/app/Main.hs index 1e999c1..2c66e55 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,7 +1,6 @@ module Main where import Control.Monad (unless, when) -import Data.List (isPrefixOf) import Data.Maybe (isJust) import qualified Data.Text as T import qualified Data.Text.IO as TIO @@ -25,20 +24,8 @@ import ScriptHs.Version ( tagStyleFor, tagVersion, ) - --- | Parsed command-line options. -data Args = Args - { argScript :: Maybe FilePath - , argOutput :: Maybe FilePath - , argPackages :: [FilePath] - , argNoLocalProject :: Bool - , argInPlace :: Bool - , argHelp :: Bool - , argVersion :: Bool - } - -emptyArgs :: Args -emptyArgs = Args Nothing Nothing [] False False False False +import ScriptHs.CLI.Types +import ScriptHs.Markdown main :: IO () main = do @@ -61,7 +48,7 @@ main = do { roPackages = pkgs , roEnclosingProject = not (argNoLocalProject a) } - dispatch opts path outPath + dispatch (argOutputStyle a) (argCodeStyle a) opts path outPath {- | Resolve the output destination, honouring @--in-place@: write back over the notebook itself. In-place is only meaningful for notebooks (the @.ghci@\/@.hs@ @@ -80,43 +67,16 @@ resolveOutput a path isNotebook :: FilePath -> Bool isNotebook path = takeExtension path `elem` [".md", ".markdown"] -dispatch :: RunOptions -> FilePath -> Maybe FilePath -> IO () -dispatch opts path outputPath = +dispatch :: OutputStyle -> CodeStyle -> RunOptions -> FilePath -> Maybe FilePath -> IO () +dispatch outputStyle codeStyle opts path outputPath = case takeExtension path of - ".md" -> runNotebook opts path outputPath - ".markdown" -> runNotebook opts path outputPath + ".md" -> runNotebook outputStyle codeStyle opts path outputPath + ".markdown" -> runNotebook outputStyle codeStyle opts path outputPath _ -> do contents <- TIO.readFile path let sf = parseScript contents runScript opts path sf -{- | Parse args: @[-o FILE | --output=FILE] [-i | --in-place] [--package DIR | --p DIR | --package=DIR]... [--no-local-project] [-h | --help]