]> gitweb.michael.orlitzky.com - email-validator.git/blob - src/CommandLine.hs
787cc1992f3d0a1c8099a8048d833396698e76af
[email-validator.git] / src / CommandLine.hs
1 {-# LANGUAGE DeriveDataTypeable #-}
2
3 module CommandLine (
4 Args(..),
5 get_args )
6 where
7
8 import System.Console.CmdArgs (
9 Data,
10 (&=),
11 cmdArgs,
12 def,
13 details,
14 help,
15 program,
16 summary,
17 typFile )
18
19
20 -- Get the version from Cabal.
21 import Paths_email_validator ( version )
22 import Data.Version ( showVersion )
23
24
25 -- We optionally accept input/output files to use instead of
26 -- stdin/stdout.
27 data Args = Args { accept_a :: Bool,
28 input_file :: Maybe FilePath,
29 output_file :: Maybe FilePath,
30 rfc5322 :: Bool }
31 deriving (Show, Data)
32
33 description :: String
34 description = "Perform naive validation of email addresses."
35
36 program_name :: String
37 program_name = "email-validator"
38
39 my_summary :: String
40 my_summary = program_name ++ "-" ++ (showVersion version)
41
42 accept_a_help :: String
43 accept_a_help =
44 "Accept an 'A' record for the domain instead of requiring an MX record."
45
46 input_file_help :: String
47 input_file_help =
48 "Path to the input file (default: stdin), one email address per line"
49
50 output_file_help :: String
51 output_file_help =
52 "Path to the output file (default: stdout)"
53
54 rfc5322_help :: String
55 rfc5322_help =
56 "Validate according to RFC 5322 (incredibly lenient)."
57
58 arg_spec :: Args
59 arg_spec =
60 Args { accept_a = def &= help accept_a_help,
61 input_file = def &= typFile &= help input_file_help,
62 output_file = def &= typFile &= help output_file_help,
63 rfc5322 = def &= help rfc5322_help }
64 &= program program_name
65 &= summary my_summary
66 &= details [description]
67
68
69
70 get_args :: IO Args
71 get_args = cmdArgs arg_spec