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_twat (version)
15 import Data.Version (showVersion)
18 import OptionalConfiguration
21 description = "Twat twats tweets so you don't have to twitter."
23 program_name :: String
27 my_summary = program_name ++ "-" ++ (showVersion version)
29 consumer_key_help :: String
30 consumer_key_help = "Your Twitter API consumer key"
32 consumer_secret_help :: String
33 consumer_secret_help = "Your Twitter API consumer secret"
35 access_token_help :: String
36 access_token_help = "Your Twitter API access token"
38 access_secret_help :: String
39 access_secret_help = "Your Twitter API access secret"
41 heartbeat_help :: String
42 heartbeat_help = "How many seconds to wait between polling"
44 to_address_help :: String
45 to_address_help = "Send tweets to ADDRESS"
47 from_address_help :: String
48 from_address_help = "Send tweets from ADDRESS"
50 sendmail_path_help :: String
51 sendmail_path_help = "Use PATH to send mail"
53 ignore_replies_help :: String
54 ignore_replies_help = "Ignore replies to other tweets"
56 ignore_retweets_help :: String
57 ignore_retweets_help = "Ignore retweets from other users"
59 verbose_help :: String
60 verbose_help = "Be verbose about stuff"
62 arg_spec :: Mode (CmdArgs OptionalCfg)
68 &= groupname "Twitter API"
69 &= help consumer_key_help,
73 &= groupname "Twitter API"
74 &= help consumer_secret_help,
78 &= groupname "Twitter API"
79 &= help access_token_help,
83 &= groupname "Twitter API"
84 &= help access_secret_help,
87 def &= groupname "Miscellaneous"
88 &= help heartbeat_help,
91 def &= groupname "Miscellaneous"
92 &= help ignore_replies_help,
95 def &= groupname "Miscellaneous"
96 &= help ignore_retweets_help,
99 def &= groupname "Miscellaneous"
100 &= help verbose_help,
104 &= groupname "Mail Options"
105 &= help sendmail_path_help,
109 &= groupname "Mail Options"
110 &= help from_address_help,
114 &= groupname "Mail Options"
115 &= help to_address_help,
121 &= program program_name
122 &= summary my_summary
123 &= details [description]
124 &= helpArg [groupname "Common flags"]
125 &= versionArg [groupname "Common flags"]
127 show_help :: IO OptionalCfg
128 show_help = withArgs ["--help"] parse_args >>= cmdArgsApply
132 parse_args :: IO (CmdArgs OptionalCfg)
135 let y = process arg_spec x
137 Right result -> return result
140 exitWith (ExitFailure exit_args_parse_failed)
143 -- | Really get the command-line arguments. This calls 'parse_args'
144 -- first to replace the default "wrong number of arguments" error,
145 -- and then runs 'cmdArgsApply' on the result to do what the
146 -- 'cmdArgs' function usually does.
147 apply_args :: IO OptionalCfg
149 parse_args >>= cmdArgsApply