1 {-# LANGUAGE DeriveDataTypeable #-}
8 import System.Console.CmdArgs (
30 -- Get the version from Cabal.
31 import Paths_haeredes (version)
32 import Data.Version (showVersion)
34 import Timeout (Timeout(seconds))
37 -- | Description of the 'NS' mode.
39 ns_description :: String
41 "Confirm delegation of NS records. " ++
42 "This is the default mode."
45 -- | Description of the 'MX' mode.
47 mx_description :: String
48 mx_description = "Confirm delegation of MX records."
51 -- | The name of the program, appears in the \"help\" output.
53 program_name :: String
54 program_name = "haeredes"
57 -- | A short summary (program name and version) that are output
58 -- as part of the help.
61 my_summary = program_name ++ "-" ++ (showVersion version)
64 -- | Description of the --no-append-root flag.
66 no_append_root_help :: String
68 "Don't append a trailing dot to DNS names"
71 -- | Description of the --server flag.
75 "IP address or hostname of server to query " ++
76 "(will use resolv.conf if not specified)"
79 -- | Description of the --timeout flag.
81 timeout_help :: String
83 "Query timeout, in seconds (default: " ++ defstr ++ ")"
85 defstr = show $ seconds (def :: Timeout)
88 -- | The 'Args' type represents the possible command-line options. The
89 -- duplication here seems necessary; CmdArgs's magic requires us to
90 -- define some things explicitly.
93 NS { no_append_root :: Bool,
94 server :: Maybe String,
96 delegates :: [String] } |
97 MX { no_append_root :: Bool,
98 server :: Maybe String,
100 delegates :: [String] }
101 deriving (Data, Show)
105 -- | The big argument specification. We use explicit annotation here
106 -- because otherwise there's come CmdArgs magic going on that
107 -- requires us to specify /all/ of the arguments for /each/ mode;
108 -- i.e. we have to duplicate all of them for both 'NS' and 'MX.
110 -- This is slightly arcane but at least it doesn't repeat yoself.
112 arg_spec :: Annotate Ann
114 modes_ [ns += auto, mx]
115 += program program_name
116 += summary my_summary
117 += helpArg [explicit,
120 groupname "Common flags"]
121 += versionArg [explicit,
124 groupname "Common flags"]
126 -- | Create a mode, adding all of the common flags to it
127 -- automatically. The big ugly type of the first argument is
128 -- simply the type of our NS/MX constructors.
130 make_mode :: (Bool -> Maybe String -> Timeout -> [String] -> Args)
133 make_mode ctor desc =
134 record (ctor def def def def) [
135 no_append_root := def
136 += groupname "Common flags"
137 += help no_append_root_help,
140 += groupname "Common flags"
145 += groupname "Common flags"
147 += help timeout_help,
152 += details [" " ++ desc]
155 -- Here we just create the NS/MX modes using our make_mode from above.
156 ns = make_mode NS ns_description
157 mx = make_mode MX mx_description
161 -- | This is the public interface; i.e. what 'main' should use to get
162 -- the command-line arguments.
165 get_args = cmdArgs_ arg_spec