7 import System.Console.CmdArgs
8 import System.Console.CmdArgs.Explicit (process)
9 import System.Environment (getArgs, withArgs)
10 import System.Exit (ExitCode(..), exitWith)
11 import System.IO (hPutStrLn, stderr)
13 -- Get the version from Cabal.
14 import Paths_halcyon (version)
15 import Data.Version (showVersion)
18 import OptionalConfiguration
22 "Monitor a list of Twitter accounts and display or email any new tweets."
24 program_name :: String
25 program_name = "halcyon"
28 my_summary = program_name ++ "-" ++ (showVersion version)
30 consumer_key_help :: String
31 consumer_key_help = "Your Twitter API consumer key"
33 consumer_secret_help :: String
34 consumer_secret_help = "Your Twitter API consumer secret"
36 access_token_help :: String
37 access_token_help = "Your Twitter API access token"
39 access_secret_help :: String
40 access_secret_help = "Your Twitter API access secret"
42 heartbeat_help :: String
43 heartbeat_help = "How many seconds to wait between polling"
45 to_address_help :: String
46 to_address_help = "Send tweets to ADDRESS"
48 from_address_help :: String
49 from_address_help = "Send tweets from ADDRESS"
51 sendmail_path_help :: String
52 sendmail_path_help = "Use PATH to send mail"
54 ignore_replies_help :: String
55 ignore_replies_help = "Ignore replies to other tweets"
57 ignore_retweets_help :: String
58 ignore_retweets_help = "Ignore retweets from other users"
60 verbose_help :: String
61 verbose_help = "Be verbose about stuff"
63 arg_spec :: Mode (CmdArgs OptionalCfg)
69 &= groupname "Twitter API"
70 &= help consumer_key_help,
74 &= groupname "Twitter API"
75 &= help consumer_secret_help,
79 &= groupname "Twitter API"
80 &= help access_token_help,
84 &= groupname "Twitter API"
85 &= help access_secret_help,
88 def &= groupname "Miscellaneous"
89 &= help heartbeat_help,
92 def &= groupname "Miscellaneous"
93 &= help ignore_replies_help,
96 def &= groupname "Miscellaneous"
97 &= help ignore_retweets_help,
100 def &= groupname "Miscellaneous"
101 &= help verbose_help,
105 &= groupname "Mail Options"
106 &= help sendmail_path_help,
110 &= groupname "Mail Options"
111 &= help from_address_help,
115 &= groupname "Mail Options"
116 &= help to_address_help,
122 &= program program_name
123 &= summary my_summary
124 &= details [description]
125 &= helpArg [groupname "Common flags"]
126 &= versionArg [groupname "Common flags"]
128 show_help :: IO OptionalCfg
129 show_help = withArgs ["--help"] parse_args >>= cmdArgsApply
133 parse_args :: IO (CmdArgs OptionalCfg)
136 let y = process arg_spec x
138 Right result -> return result
141 exitWith (ExitFailure exit_args_parse_failed)
144 -- | Really get the command-line arguments. This calls 'parse_args'
145 -- first to replace the default "wrong number of arguments" error,
146 -- and then runs 'cmdArgsApply' on the result to do what the
147 -- 'cmdArgs' function usually does.
148 apply_args :: IO OptionalCfg
150 parse_args >>= cmdArgsApply