summaryrefslogtreecommitdiff
path: root/lib/Language/Elna/Driver.hs
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2024-12-20 15:32:20 +0100
committerEugen Wissner <belka@caraus.de>2024-12-20 15:32:20 +0100
commita1c99103003bfd466c77a369fb3312f922f336d0 (patch)
tree42dc2946a4183f63c90400b71d973023a5fe13aa /lib/Language/Elna/Driver.hs
parentfbd08f27078f2e86c7e0ae65fd8d89658c0c34bd (diff)
downloadelna-a1c99103003bfd466c77a369fb3312f922f336d0.tar.gz
Add stage options
Diffstat (limited to 'lib/Language/Elna/Driver.hs')
-rw-r--r--lib/Language/Elna/Driver.hs37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/Language/Elna/Driver.hs b/lib/Language/Elna/Driver.hs
new file mode 100644
index 0000000..9d13f59
--- /dev/null
+++ b/lib/Language/Elna/Driver.hs
@@ -0,0 +1,37 @@
+{- This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/. -}
+
+module Language.Elna.Driver
+ ( Driver(..)
+ , IntermediateStage(..)
+ , drive
+ , execParser
+ ) where
+
+import Data.Maybe (fromMaybe)
+import Language.Elna.Driver.CommandLine
+ ( CommandLine(..)
+ , IntermediateStage(..)
+ , commandLine
+ )
+import Options.Applicative (execParser)
+import System.FilePath (replaceExtension, takeFileName)
+
+data Driver = Driver
+ { input :: FilePath
+ , output :: FilePath
+ , intermediateStage :: Maybe IntermediateStage
+ } deriving (Eq, Show)
+
+drive :: IO Driver
+drive = rewrite <$> execParser commandLine
+ where
+ rewrite CommandLine{..} =
+ let defaultOutputName = replaceExtension (takeFileName input) "o"
+ outputName = fromMaybe defaultOutputName output
+ in Driver
+ { input = input
+ , output = outputName
+ , intermediateStage = intermediateStage
+ }