diff options
author | Teddy Wing | 2017-08-19 18:44:56 +0200 |
---|---|---|
committer | Teddy Wing | 2017-08-19 18:50:54 +0200 |
commit | 1884f2e54097bdce9a4a011065a89044c86a8ebf (patch) | |
tree | 5f378ce3e6ccc929837bc1e99c35cc88804fedb9 | |
parent | 54f23f1d77a3623d6e18c0a55b622d4cfab60406 (diff) | |
download | sorbot-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.
-rw-r--r-- | sorbot.cabal | 2 | ||||
-rw-r--r-- | src/CliOptions.hs | 28 | ||||
-rw-r--r-- | src/Lib.hs | 4 |
3 files changed, 33 insertions, 1 deletions
diff --git a/sorbot.cabal b/sorbot.cabal index c79d2a1..69ef437 100644 --- a/sorbot.cabal +++ b/sorbot.cabal @@ -16,6 +16,7 @@ cabal-version: >=1.10 library hs-source-dirs: src exposed-modules: Lib + , CliOptions , I18n , IRC , Message @@ -26,6 +27,7 @@ library build-depends: base >= 4.7 && < 5 , bytestring , irc-client + , optparse-applicative , regex-tdfa , sqlite-simple , text 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." ) @@ -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 |