{-# 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")