aboutsummaryrefslogtreecommitdiff
path: root/hsm-core
diff options
context:
space:
mode:
Diffstat (limited to 'hsm-core')
-rw-r--r--hsm-core/Hsm/Core/App.hs20
-rw-r--r--hsm-core/Hsm/Core/Bracket.hs5
-rw-r--r--hsm-core/Hsm/Core/Options.hs8
-rw-r--r--hsm-core/Hsm/Core/Serial.hs21
-rw-r--r--hsm-core/hsm-core.cabal4
5 files changed, 37 insertions, 21 deletions
diff --git a/hsm-core/Hsm/Core/App.hs b/hsm-core/Hsm/Core/App.hs
new file mode 100644
index 0000000..88dabb2
--- /dev/null
+++ b/hsm-core/Hsm/Core/App.hs
@@ -0,0 +1,20 @@
+-- Provides combinators for bootstrapping applications with:
+-- - Automated command-line parsing
+-- - Help text generation
+module Hsm.Core.App
+ ( bootstrapApp
+ , bootstrapAppNoEcho
+ )
+where
+
+import Data.Composition ((.:.))
+import Options.Applicative (Parser, execParser, fullDesc, helper, info, progDesc, (<**>))
+import System.IO.Echo (withoutInputEcho)
+
+-- Launches a console application with input echo enabled
+bootstrapApp :: Parser o -> String -> (o -> IO a) -> IO a
+bootstrapApp parser desc app = execParser (info (parser <**> helper) $ fullDesc <> progDesc desc) >>= app
+
+-- Launches an application with hidden input echo
+bootstrapAppNoEcho :: Parser o -> String -> (o -> IO a) -> IO a
+bootstrapAppNoEcho = withoutInputEcho .:. bootstrapApp
diff --git a/hsm-core/Hsm/Core/Bracket.hs b/hsm-core/Hsm/Core/Bracket.hs
index f666d86..92428de 100644
--- a/hsm-core/Hsm/Core/Bracket.hs
+++ b/hsm-core/Hsm/Core/Bracket.hs
@@ -4,10 +4,11 @@ module Hsm.Core.Bracket
( bracketConst
, bracketCont
, bracketLiftIO_
- ) where
+ )
+where
import Control.Monad.Trans.Cont (Cont, cont)
-import Effectful (Eff, IOE, (:>), liftIO)
+import Effectful (Eff, IOE, liftIO, (:>))
import Effectful.Exception (bracket, bracket_)
-- Ignores allocated resource in the action
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/Serial.hs b/hsm-core/Hsm/Core/Serial.hs
index 9a4d2b7..7c607ff 100644
--- a/hsm-core/Hsm/Core/Serial.hs
+++ b/hsm-core/Hsm/Core/Serial.hs
@@ -2,21 +2,22 @@
module Hsm.Core.Serial
( makeSerial
- ) where
+ )
+where
import GHC.Num (integerFromInt)
import Language.Haskell.TH
- ( Body(NormalB)
- , Clause(Clause)
- , Con(NormalC)
- , Dec(DataD, FunD, SigD)
- , DerivClause(DerivClause)
- , Exp(LitE)
- , Lit(IntegerL)
+ ( Body (NormalB)
+ , Clause (Clause)
+ , Con (NormalC)
+ , Dec (DataD, FunD, SigD)
+ , DerivClause (DerivClause)
+ , Exp (LitE)
+ , Lit (IntegerL)
, Name
- , Pat(ConP)
+ , Pat (ConP)
, Q
- , Type(AppT, ArrowT, ConT)
+ , Type (AppT, ArrowT, ConT)
, mkName
)
diff --git a/hsm-core/hsm-core.cabal b/hsm-core/hsm-core.cabal
index e435f19..6a0efff 100644
--- a/hsm-core/hsm-core.cabal
+++ b/hsm-core/hsm-core.cabal
@@ -6,6 +6,8 @@ version: 0.1.0.0
library
build-depends:
, base
+ , composition
+ , echo
, effectful-core
, optparse-applicative
, template-haskell
@@ -13,8 +15,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