blob: 9d8baf60ddaf7c066a75a57e542cc4c8ae2b9d11 (
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
41
42
43
44
45
|
module CliOptions
( Options(..)
, parseOptions
) where
import Data.Semigroup ((<>))
import Options.Applicative
import I18n (Locale(EN, FR))
data Options = Options
{ slackApiToken :: String
, language :: Locale
}
-- | Parse the language command line option string into a `Locale` type
parseLanguage :: ReadM Locale
parseLanguage = eitherReader $ \s -> case s of
"en" -> Right EN
"fr" -> Right FR
_ -> Left "Unrecognised language code"
options :: Parser Options
options = Options
<$> strOption
( long "slack-token"
<> metavar "TOKEN"
<> value ""
<> help "Token to access Slack's real-time messaging API" )
<*> option parseLanguage
( long "language"
<> short 'l'
<> metavar "en"
<> value EN
<> help "Set the language Sorbot will speak in (en | fr)" )
parseOptions :: IO Options
parseOptions = do
execParser opts
where
opts = info (options <**> helper)
( fullDesc
<> progDesc "A chat bot with a plugin interface that does a bunch of \
\random things." )
|