39470b23106af79e3b0c69070679971c4ef2cabc
[haeredes.git] / src / CommandLine.hs
1 {-# LANGUAGE DeriveDataTypeable #-}
2
3 module CommandLine (
4 Args(..),
5 get_args
6 )
7 where
8
9 import System.Console.CmdArgs
10
11 -- Get the version from Cabal.
12 import Paths_haeredes (version)
13 import Data.Version (showVersion)
14
15 ns_description :: String
16 ns_description =
17 "Confirm delegation of NS records. " ++
18 "This is the default mode."
19
20 mx_description :: String
21 mx_description = "Confirm delegation of MX records."
22
23 program_name :: String
24 program_name = "haeredes"
25
26 my_summary :: String
27 my_summary = program_name ++ "-" ++ (showVersion version)
28
29 server_help :: String
30 server_help =
31 "IP address of server to query " ++
32 "(will use resolv.conf if not specified)"
33
34 data Args =
35 NS { server :: Maybe String, delegates :: [String] } |
36 MX { server :: Maybe String, delegates :: [String] }
37 deriving (Data, Show, Typeable)
38
39 arg_spec :: Args
40 arg_spec =
41 modes [ns &= auto, mx]
42 &= program program_name
43 &= summary my_summary
44 &= helpArg [explicit,
45 name "help",
46 name "h",
47 groupname "Common flags"]
48 &= versionArg [explicit,
49 name "version",
50 name "v",
51 groupname "Common flags"]
52 where
53 -- The repetition here is necessary, some Template Haskell magic
54 -- going on.
55 ns :: Args
56 ns = NS {
57 server = def
58 &= groupname "Common flags"
59 &= typ "IP"
60 &= help server_help,
61
62 delegates = def
63 &= args
64 &= typ "DELEGATES" }
65
66 &= details [ns_description]
67
68 mx :: Args
69 mx = MX {
70 server = def
71 &= groupname "Common flags"
72 &= typ "IP"
73 &= help server_help,
74
75 delegates = def
76 &= args
77 &= typ "DELEGATES" }
78
79 &= details [mx_description]
80
81 get_args :: IO Args
82 get_args = cmdArgs arg_spec