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