Support hostnames as --server arguments.
[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 Data,
11 Typeable,
12 (&=),
13 args,
14 auto,
15 cmdArgs,
16 def,
17 details,
18 explicit,
19 groupname,
20 help,
21 helpArg,
22 modes,
23 name,
24 program,
25 summary,
26 typ,
27 versionArg )
28
29 -- Get the version from Cabal.
30 import Paths_haeredes (version)
31 import Data.Version (showVersion)
32
33 ns_description :: String
34 ns_description =
35 "Confirm delegation of NS records. " ++
36 "This is the default mode."
37
38 mx_description :: String
39 mx_description = "Confirm delegation of MX records."
40
41 program_name :: String
42 program_name = "haeredes"
43
44 my_summary :: String
45 my_summary = program_name ++ "-" ++ (showVersion version)
46
47 server_help :: String
48 server_help =
49 "IP address of server to query " ++
50 "(will use resolv.conf if not specified)"
51
52 data Args =
53 NS { server :: Maybe String, delegates :: [String] } |
54 MX { server :: Maybe String, delegates :: [String] }
55 deriving (Data, Show, Typeable)
56
57 arg_spec :: Args
58 arg_spec =
59 modes [ns &= auto, mx]
60 &= program program_name
61 &= summary my_summary
62 &= helpArg [explicit,
63 name "help",
64 name "h",
65 groupname "Common flags"]
66 &= versionArg [explicit,
67 name "version",
68 name "v",
69 groupname "Common flags"]
70 where
71 -- The repetition here is necessary, some Template Haskell magic
72 -- going on.
73 ns :: Args
74 ns = NS {
75 server = def
76 &= groupname "Common flags"
77 &= typ "IP"
78 &= help server_help,
79
80 delegates = def
81 &= args
82 &= typ "DELEGATES" }
83
84 &= details [ns_description]
85
86 mx :: Args
87 mx = MX {
88 server = def
89 &= groupname "Common flags"
90 &= typ "IP"
91 &= help server_help,
92
93 delegates = def
94 &= args
95 &= typ "DELEGATES" }
96
97 &= details [mx_description]
98
99 get_args :: IO Args
100 get_args = cmdArgs arg_spec