aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTeddy Wing2017-08-19 18:44:56 +0200
committerTeddy Wing2017-08-19 18:50:54 +0200
commit1884f2e54097bdce9a4a011065a89044c86a8ebf (patch)
tree5f378ce3e6ccc929837bc1e99c35cc88804fedb9 /src
parent54f23f1d77a3623d6e18c0a55b622d4cfab60406 (diff)
downloadsorbot-1884f2e54097bdce9a4a011065a89044c86a8ebf.tar.bz2
Add command line option handling
Use 'optparse-applicative' to parse command line options. Provide a `--slack-token` option that sets a Slack API token to enable access to the chat platform. More options will come as needed (including things like database name, language, possibly IRC configuration). Code is based on the example in https://hackage.haskell.org/package/optparse-applicative Pretty cool option parser.
Diffstat (limited to 'src')
-rw-r--r--src/CliOptions.hs28
-rw-r--r--src/Lib.hs4
2 files changed, 31 insertions, 1 deletions
diff --git a/src/CliOptions.hs b/src/CliOptions.hs
new file mode 100644
index 0000000..861f48e
--- /dev/null
+++ b/src/CliOptions.hs
@@ -0,0 +1,28 @@
+module CliOptions
+ ( parseOptions
+ ) where
+
+import Data.Semigroup ((<>))
+import Options.Applicative
+
+data Options = Options
+ { slackApiToken :: String
+ }
+
+options :: Parser Options
+options = Options
+ <$> strOption
+ ( long "slack-token"
+ <> metavar "TOKEN"
+ <> value ""
+ <> help "Token to access Slack's real-time messaging API" )
+
+parseOptions :: IO ()
+parseOptions = do
+ execParser opts
+ return ()
+ where
+ opts = info (options <**> helper)
+ ( fullDesc
+ <> progDesc "A chat bot with a plugin interface that does a bunch of \
+ \random things." )
diff --git a/src/Lib.hs b/src/Lib.hs
index 5ae6f9b..b34100e 100644
--- a/src/Lib.hs
+++ b/src/Lib.hs
@@ -6,10 +6,12 @@ module Lib
import Database.SQLite.Simple
+import CliOptions (parseOptions)
import IRC (connectIRC)
import Message
import Plugin
someFunc :: IO ()
someFunc = do
- connectIRC "irc.freenode.net" 6697 "test-bot-7890asdf"
+ -- connectIRC "irc.freenode.net" 6697 "test-bot-7890asdf"
+ parseOptions