blob: 29e40a4ad61c3b7066827ca2d5d0351f56cde67a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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")
|