aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Oliver <contact@pauloliver.dev>2025-09-07 13:43:15 +0000
committerPaul Oliver <contact@pauloliver.dev>2025-09-07 13:44:22 +0000
commitef0713cbd90d6b84da7ea67e6dfc1fe5ab5bff86 (patch)
treec4a6b48f498be3381a24a9c2183d3a50c0291a62
parentb401cfd4780882a01b3656da2aa244592cb1d242 (diff)
Adds generic app launcher helper function
-rw-r--r--hsm-core/Hsm/Core/App.hs9
-rw-r--r--hsm-core/Hsm/Core/Options.hs8
-rw-r--r--hsm-core/hsm-core.cabal2
-rw-r--r--hsm-web/Main.hs4
4 files changed, 12 insertions, 11 deletions
diff --git a/hsm-core/Hsm/Core/App.hs b/hsm-core/Hsm/Core/App.hs
new file mode 100644
index 0000000..12849d4
--- /dev/null
+++ b/hsm-core/Hsm/Core/App.hs
@@ -0,0 +1,9 @@
+module Hsm.Core.App
+ ( runApp
+ ) where
+
+import Effectful (Eff, IOE, runEff)
+import Options.Applicative (Parser, (<**>), execParser, fullDesc, helper, info, progDesc)
+
+runApp :: Parser o -> String -> (o -> Eff '[ IOE] a) -> IO a
+runApp parser desc app = execParser (info (parser <**> helper) $ fullDesc <> progDesc desc) >>= runEff . app
diff --git a/hsm-core/Hsm/Core/Options.hs b/hsm-core/Hsm/Core/Options.hs
deleted file mode 100644
index eeeee97..0000000
--- a/hsm-core/Hsm/Core/Options.hs
+++ /dev/null
@@ -1,8 +0,0 @@
-module Hsm.Core.Options
- ( getOptions
- ) where
-
-import Options.Applicative (Parser, (<**>), execParser, fullDesc, helper, info, progDesc)
-
-getOptions :: Parser a -> String -> IO a
-getOptions parser desc = execParser . info (parser <**> helper) $ fullDesc <> progDesc desc
diff --git a/hsm-core/hsm-core.cabal b/hsm-core/hsm-core.cabal
index e435f19..163e430 100644
--- a/hsm-core/hsm-core.cabal
+++ b/hsm-core/hsm-core.cabal
@@ -13,8 +13,8 @@ library
default-language: GHC2024
exposed-modules:
+ Hsm.Core.App
Hsm.Core.Bracket
Hsm.Core.Serial
- Hsm.Core.Options
ghc-options: -O2 -Wall -Werror -Wno-star-is-type -Wunused-packages
diff --git a/hsm-web/Main.hs b/hsm-web/Main.hs
index 2661370..2b6c44b 100644
--- a/hsm-web/Main.hs
+++ b/hsm-web/Main.hs
@@ -2,7 +2,7 @@
import Effectful (runEff)
import Hsm.Cam (runCam)
-import Hsm.Core.Options (getOptions)
+import Hsm.Core.App (runApp)
import Hsm.Log (Severity(Info), runLogsOpt)
import Hsm.Log.Options (makeLoggerOptionParser)
import Hsm.Web (runServer, runWeb)
@@ -16,4 +16,4 @@ type Loggers = '[ "cam", "libcamera", "scotty", "web"]
$(makeLoggerOptionParser @Loggers "Options" "parser" 'Info)
main :: IO ()
-main = getOptions parser "Launch HsMouse Web Server" >>= \opts -> runEff . runLogsOpt @Options @Loggers opts . runCam . runWeb $ runServer
+main = runApp parser "Launch HsMouse Web Server" $ \opts -> runLogsOpt @Options @Loggers opts . runCam . runWeb $ runServer