aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Oliver <contact@pauloliver.dev>2025-09-05 00:13:52 +0000
committerPaul Oliver <contact@pauloliver.dev>2025-09-05 00:32:06 +0000
commit8f9eceffae1d0e4eb0b2fbcb22b70730bb75bd5e (patch)
tree3d2b1c487a9d547c34bdf7afea72e73d92c78584
parentcd217ecf5bc7a04c9d594876f753916a098bf3b7 (diff)
Adds optparse helper to `hsm-core`
-rw-r--r--hsm-core/Hsm/Core/Options.hs8
-rw-r--r--hsm-core/hsm-core.cabal2
-rw-r--r--hsm-web/Main.hs5
-rw-r--r--hsm-web/hsm-web.cabal3
4 files changed, 14 insertions, 4 deletions
diff --git a/hsm-core/Hsm/Core/Options.hs b/hsm-core/Hsm/Core/Options.hs
new file mode 100644
index 0000000..eeeee97
--- /dev/null
+++ b/hsm-core/Hsm/Core/Options.hs
@@ -0,0 +1,8 @@
+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 67a63e2..e435f19 100644
--- a/hsm-core/hsm-core.cabal
+++ b/hsm-core/hsm-core.cabal
@@ -7,6 +7,7 @@ library
build-depends:
, base
, effectful-core
+ , optparse-applicative
, template-haskell
, transformers
@@ -14,5 +15,6 @@ library
exposed-modules:
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 d1a9da3..2661370 100644
--- a/hsm-web/Main.hs
+++ b/hsm-web/Main.hs
@@ -2,6 +2,7 @@
import Effectful (runEff)
import Hsm.Cam (runCam)
+import Hsm.Core.Options (getOptions)
import Hsm.Log (Severity(Info), runLogsOpt)
import Hsm.Log.Options (makeLoggerOptionParser)
import Hsm.Web (runServer, runWeb)
@@ -15,6 +16,4 @@ type Loggers = '[ "cam", "libcamera", "scotty", "web"]
$(makeLoggerOptionParser @Loggers "Options" "parser" 'Info)
main :: IO ()
-main = do
- opt <- execParser . info (parser <**> helper) $ fullDesc <> progDesc "Launch HsMouse Web Server"
- runEff . runLogsOpt @Options @Loggers opt . runCam . runWeb $ runServer
+main = getOptions parser "Launch HsMouse Web Server" >>= \opts -> runEff . runLogsOpt @Options @Loggers opts . runCam . runWeb $ runServer
diff --git a/hsm-web/hsm-web.cabal b/hsm-web/hsm-web.cabal
index 0e7bf02..ca631b4 100644
--- a/hsm-web/hsm-web.cabal
+++ b/hsm-web/hsm-web.cabal
@@ -28,6 +28,7 @@ executable hsm-web
, effectful-core
, effectful-plugin
, hsm-cam
+ , hsm-core
, hsm-log
, optparse-applicative
, scotty
@@ -35,7 +36,7 @@ executable hsm-web
default-language: GHC2024
ghc-options:
- -O2 -threaded -Wall -Werror -Wno-star-is-type -Wunused-packages
+ -O2 -threaded -Wall -Werror -Wno-star-is-type -Wunused-packages -Wno-unused-imports
-ddump-splices -fplugin=Effectful.Plugin
if !arch(x86_64)