blob: f29704a8e13a07bacf74fd1351509882ea396dc8 (
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
46
47
48
49
50
51
52
53
|
module CliOptions
( Options(..)
, lang
, 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." )
-- | A convenience function to get the configured locale.
lang :: IO Locale
lang = do
opts <- parseOptions
return $ language opts
|