module CommandLine (
- apply_args,
- show_help
- )
+ get_args,
+ show_help)
where
-import System.Console.CmdArgs
-import System.Console.CmdArgs.Explicit (process)
-import System.Environment (getArgs, withArgs)
-import System.Exit (ExitCode(..), exitWith)
-import System.IO (hPutStrLn, stderr)
+import System.Console.CmdArgs (
+ (&=),
+ args,
+ cmdArgs,
+ def,
+ details,
+ groupname,
+ help,
+ helpArg,
+ program,
+ summary,
+ typ,
+ versionArg)
+import System.Environment (withArgs)
-- Get the version from Cabal.
import Paths_halcyon (version)
import Data.Version (showVersion)
-import ExitCodes
import OptionalConfiguration
description :: String
verbose_help :: String
verbose_help = "Be verbose about stuff"
-arg_spec :: Mode (CmdArgs OptionalCfg)
+arg_spec :: OptionalCfg
arg_spec =
- cmdArgsMode $
- OptionalCfg {
- consumer_key =
- def &= typ "KEY"
- &= groupname "Twitter API"
- &= help consumer_key_help,
-
- consumer_secret =
- def &= typ "SECRET"
- &= groupname "Twitter API"
- &= help consumer_secret_help,
-
- access_token =
- def &= typ "TOKEN"
- &= groupname "Twitter API"
- &= help access_token_help,
-
- access_secret =
- def &= typ "SECRET"
- &= groupname "Twitter API"
- &= help access_secret_help,
-
- heartbeat =
- def &= groupname "Miscellaneous"
- &= help heartbeat_help,
-
- ignore_replies =
- def &= groupname "Miscellaneous"
- &= help ignore_replies_help,
-
- ignore_retweets =
- def &= groupname "Miscellaneous"
- &= help ignore_retweets_help,
-
- verbose =
- def &= groupname "Miscellaneous"
- &= help verbose_help,
-
- sendmail_path =
- def &= typ "PATH"
- &= groupname "Mail Options"
- &= help sendmail_path_help,
-
- from_address =
- def &= typ "ADDRESS"
- &= groupname "Mail Options"
- &= help from_address_help,
-
- to_address =
- def &= typ "ADDRESS"
- &= groupname "Mail Options"
- &= help to_address_help,
-
- usernames =
- def &= args
- &= typ "USERNAMES" }
-
- &= program program_name
- &= summary my_summary
- &= details [description]
- &= helpArg [groupname "Common flags"]
- &= versionArg [groupname "Common flags"]
+ OptionalCfg {
+ consumer_key =
+ def &= typ "KEY"
+ &= groupname "Twitter API"
+ &= help consumer_key_help,
+
+ consumer_secret =
+ def &= typ "SECRET"
+ &= groupname "Twitter API"
+ &= help consumer_secret_help,
+
+ access_token =
+ def &= typ "TOKEN"
+ &= groupname "Twitter API"
+ &= help access_token_help,
+
+ access_secret =
+ def &= typ "SECRET"
+ &= groupname "Twitter API"
+ &= help access_secret_help,
+
+ heartbeat =
+ def &= groupname "Miscellaneous"
+ &= help heartbeat_help,
+
+ ignore_replies =
+ def &= groupname "Miscellaneous"
+ &= help ignore_replies_help,
+
+ ignore_retweets =
+ def &= groupname "Miscellaneous"
+ &= help ignore_retweets_help,
+
+ verbose =
+ def &= groupname "Miscellaneous"
+ &= help verbose_help,
+
+ sendmail_path =
+ def &= typ "PATH"
+ &= groupname "Mail Options"
+ &= help sendmail_path_help,
+
+ from_address =
+ def &= typ "ADDRESS"
+ &= groupname "Mail Options"
+ &= help from_address_help,
+
+ to_address =
+ def &= typ "ADDRESS"
+ &= groupname "Mail Options"
+ &= help to_address_help,
+
+ usernames =
+ def &= args
+ &= typ "USERNAMES" }
+
+ &= program program_name
+ &= summary my_summary
+ &= details [description]
+ &= helpArg [groupname "Common flags"]
+ &= versionArg [groupname "Common flags"]
show_help :: IO OptionalCfg
-show_help = withArgs ["--help"] parse_args >>= cmdArgsApply
+show_help = withArgs ["--help"] get_args
-
-parse_args :: IO (CmdArgs OptionalCfg)
-parse_args = do
- x <- getArgs
- let y = process arg_spec x
- case y of
- Right result -> return result
- Left err -> do
- hPutStrLn stderr err
- exitWith (ExitFailure exit_args_parse_failed)
-
-
--- | Really get the command-line arguments. This calls 'parse_args'
--- first to replace the default "wrong number of arguments" error,
--- and then runs 'cmdArgsApply' on the result to do what the
--- 'cmdArgs' function usually does.
-apply_args :: IO OptionalCfg
-apply_args =
- parse_args >>= cmdArgsApply
+get_args :: IO OptionalCfg
+get_args = cmdArgs arg_spec
import qualified Data.ByteString.Lazy as B
import qualified Data.ByteString.Char8 as BC
-import qualified Data.Conduit as C
-import Data.Conduit.Binary (sinkLbs)
-import Network.HTTP.Conduit
+import Network.HTTP.Client (
+ httpLbs,
+ newManager,
+ parseUrl,
+ responseBody)
+import Network.HTTP.Client.TLS (
+ tlsManagerSettings)
import Web.Authenticate.OAuth (
OAuth(..),
Credential,
-- | Retrieve a URL, or crash.
http_get :: Cfg -> String -> IO B.ByteString
http_get cfg url = do
- manager <- newManager def
+ manager <- newManager tlsManagerSettings
request <- parseUrl url
-
- C.runResourceT $ do
- signed_request <- signOAuth oauth credential request
- response <- http signed_request manager
- responseBody response C.$$+- sinkLbs
+ signed_request <- signOAuth oauth credential request
+ response <- httpLbs signed_request manager
+ return $ responseBody response
where
consumer_key' = BC.pack (consumer_key cfg)