diff options
author | Paul Oliver <contact@pauloliver.dev> | 2024-12-29 17:05:34 +0000 |
---|---|---|
committer | Paul Oliver <contact@pauloliver.dev> | 2025-01-16 18:30:09 -0800 |
commit | cc639b06c7126fac7b445d8f778455620d7f8f50 (patch) | |
tree | a4c5c7c0b0a9cdb5bea0891e198003035065e57d /hsm-core/Hsm/Core/Options.hs |
Initial
Diffstat (limited to 'hsm-core/Hsm/Core/Options.hs')
-rw-r--r-- | hsm-core/Hsm/Core/Options.hs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/hsm-core/Hsm/Core/Options.hs b/hsm-core/Hsm/Core/Options.hs new file mode 100644 index 0000000..29e40a4 --- /dev/null +++ b/hsm-core/Hsm/Core/Options.hs @@ -0,0 +1,40 @@ +{-# LANGUAGE OverloadedStrings #-} + +module Hsm.Core.Options + ( Options(Options) + , options + ) where + +import Control.Applicative ((<**>)) +import Data.Text (Text, pack, unpack) +import Effectful.Log (LogLevel(LogInfo), readLogLevelEither, showLogLevel) +import Options.Applicative qualified as P +import Options.Applicative.Text qualified as P + +data Options = + Options Text LogLevel + +parser :: P.Parser Options +parser = + Options + <$> P.textOption + (P.help "Path to services config file" + <> P.short 'c' + <> P.long "config" + <> P.metavar "PATH" + <> P.value "servconf.yaml" + <> P.showDefault) + <*> P.option + (P.eitherReader $ readLogLevelEither . pack) + (P.help "Log level" + <> P.short 'l' + <> P.long "log-level" + <> P.metavar "LEVEL" + <> P.value LogInfo + <> P.showDefaultWith (unpack . showLogLevel)) + +options :: Text -> IO Options +options name = + P.customExecParser (P.prefs $ P.columns 100) + $ P.info (parser <**> P.helper) + $ P.fullDesc <> P.progDesc ("Launch " <> unpack name <> " service") |