2118f5911ec2c533128f5a5c41530348ca10c362
[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 -- | Description of the 'NS' mode.
34 ns_description :: String
35 ns_description =
36 "Confirm delegation of NS records. " ++
37 "This is the default mode."
38
39 -- | Description of the 'MX' mode.
40 mx_description :: String
41 mx_description = "Confirm delegation of MX records."
42
43 program_name :: String
44 program_name = "haeredes"
45
46 my_summary :: String
47 my_summary = program_name ++ "-" ++ (showVersion version)
48
49 no_append_root_help :: String
50 no_append_root_help =
51 "Don't append a trailing dot to DNS names"
52
53 -- | Help string for the --server flag.
54 server_help :: String
55 server_help =
56 "IP address or hostname of server to query " ++
57 "(will use resolv.conf if not specified)"
58
59 -- | The Args type represents the possible command-line options. The
60 -- duplication here seems necessary; CmdArgs' magic requires us to
61 -- define some things explicitly.
62 data Args =
63 NS { no_append_root :: Bool,
64 server :: Maybe String,
65 delegates :: [String] } |
66 MX { no_append_root :: Bool,
67 server :: Maybe String,
68 delegates :: [String] }
69 deriving (Data, Show, Typeable)
70
71 arg_spec :: Args
72 arg_spec =
73 modes [ns &= auto, mx]
74 &= program program_name
75 &= summary my_summary
76 &= helpArg [explicit,
77 name "help",
78 name "h",
79 groupname "Common flags"]
80 &= versionArg [explicit,
81 name "version",
82 name "v",
83 groupname "Common flags"]
84 where
85 -- The repetition here is necessary, some CmdArgs magic going on.
86 ns :: Args
87 ns = NS {
88 no_append_root = def
89 &= groupname "Common flags"
90 &= help no_append_root_help,
91
92 server = def
93 &= groupname "Common flags"
94 &= typ "HOST"
95 &= help server_help,
96
97 delegates = def
98 &= args
99 &= typ "DELEGATES" }
100
101 &= details [ns_description]
102
103 mx :: Args
104 mx = MX {
105 no_append_root = def
106 &= groupname "Common flags"
107 &= help no_append_root_help,
108
109 server = def
110 &= groupname "Common flags"
111 &= typ "IP"
112 &= help server_help,
113
114 delegates = def
115 &= args
116 &= typ "DELEGATES" }
117
118 &= details [mx_description]
119
120 get_args :: IO Args
121 get_args = cmdArgs arg_spec