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_twat (version)
-import Data.Version (showVersion)
+import Paths_halcyon ( version )
+import Data.Version ( showVersion )
-import OptionalConfiguration
-import ExitCodes
+import OptionalConfiguration ( OptionalCfg(..) )
+
+-- | The description of the program, displayed as part of the help.
+--
description :: String
-description = "Twat twats tweets so you don't have to twitter."
+description =
+ "Monitor a list of Twitter accounts and display or email any new tweets."
+
+-- | The name of this program.
+--
program_name :: String
-program_name = "twat"
+program_name = "halcyon"
+
+-- | A summary string output as part of the help.
+--
my_summary :: String
my_summary = program_name ++ "-" ++ (showVersion version)
+
+-- | Help string for the \"consumer_key\" option.
+--
consumer_key_help :: String
consumer_key_help = "Your Twitter API consumer key"
+
+-- | Help string for the \"consumer_secret\" option.
+--
consumer_secret_help :: String
consumer_secret_help = "Your Twitter API consumer secret"
+
+-- | Help string for the \"access_token\" option
+--
access_token_help :: String
access_token_help = "Your Twitter API access token"
+
+-- | Help string for the \"access_secret\" option.
+--
access_secret_help :: String
access_secret_help = "Your Twitter API access secret"
+
+-- | Help string for the \"heartbeat\" option.
+--
heartbeat_help :: String
heartbeat_help = "How many seconds to wait between polling"
+
+-- | Help string for the \"to_address\" option.
+--
to_address_help :: String
to_address_help = "Send tweets to ADDRESS"
+
+-- | Help string for the \"from_address\" option.
+--
from_address_help :: String
from_address_help = "Send tweets from ADDRESS"
+
+-- | Help string for the \"sendmail_path\" option.
+--
sendmail_path_help :: String
sendmail_path_help = "Use PATH to send mail"
+
+-- | Help string for the \"ignore_replies\" option.
+--
ignore_replies_help :: String
ignore_replies_help = "Ignore replies to other tweets"
+
+-- | Help string for the \"ignore_retweets\" option.
+--
ignore_retweets_help :: String
ignore_retweets_help = "Ignore retweets from other users"
+
+-- | Help string for the \"verbose\" option.
+--
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"]
-
-show_help :: IO (CmdArgs OptionalCfg)
-show_help = withArgs ["--help"] parse_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
+ 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"] get_args
+
+
+get_args :: IO OptionalCfg
+get_args = cmdArgs arg_spec