From cc639b06c7126fac7b445d8f778455620d7f8f50 Mon Sep 17 00:00:00 2001 From: Paul Oliver Date: Sun, 29 Dec 2024 17:05:34 +0000 Subject: Initial --- hsm-core/Hsm/Core/Options.hs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 hsm-core/Hsm/Core/Options.hs (limited to 'hsm-core/Hsm/Core/Options.hs') 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") -- cgit v1.2.1