1 {-# LANGUAGE DeriveDataTypeable #-}
8 import System.Console.CmdArgs (
31 -- Get the version from Cabal.
32 import Paths_haeredes (version)
33 import Data.Version (showVersion)
35 import Timeout (Timeout(..))
38 -- | Description of the 'NS' mode.
40 ns_description :: String
42 "Confirm delegation of NS records. " ++
43 "This is the default mode."
46 -- | Description of the 'MX' mode.
48 mx_description :: String
49 mx_description = "Confirm delegation of MX records."
52 -- | The name of the program, appears in the \"help\" output.
54 program_name :: String
55 program_name = "haeredes"
58 -- | A short summary (program name and version) that are output
59 -- as part of the help.
62 my_summary = program_name ++ "-" ++ (showVersion version)
65 -- | Description of the --no-append-root flag.
67 no_append_root_help :: String
69 "Don't append a trailing dot to DNS names"
72 -- | Description of the --server flag.
76 "IP address or hostname of server to query " ++
77 "(will use resolv.conf if not specified)"
80 -- | Description of the --timeout flag.
82 timeout_help :: String
84 "Query timeout, in seconds (default: " ++ defstr ++ ")"
86 defstr = show $ seconds (def :: Timeout)
89 -- | The 'Args' type represents the possible command-line options. The
90 -- duplication here seems necessary; CmdArgs's magic requires us to
91 -- define some things explicitly.
94 NS { no_append_root :: Bool,
95 server :: Maybe String,
97 delegates :: [String] } |
98 MX { no_append_root :: Bool,
99 server :: Maybe String,
101 delegates :: [String] }
102 deriving (Data, Show, Typeable)
106 -- | The big argument specification. We use explicit annotation here
107 -- because otherwise there's come CmdArgs magic going on that
108 -- requires us to specify /all/ of the arguments for /each/ mode;
109 -- i.e. we have to duplicate all of them for both 'NS' and 'MX.
111 -- This is slightly arcane but at least it doesn't repeat yoself.
113 arg_spec :: Annotate Ann
115 modes_ [ns += auto, mx]
116 += program program_name
117 += summary my_summary
118 += helpArg [explicit,
121 groupname "Common flags"]
122 += versionArg [explicit,
125 groupname "Common flags"]
127 -- | Create a mode, adding all of the common flags to it
128 -- automatically. The big ugly type of the first argument is
129 -- simply the type of our NS/MX constructors.
131 make_mode :: (Bool -> Maybe String -> Timeout -> [String] -> Args)
134 make_mode ctor desc =
135 record (ctor def def def def) [
136 no_append_root := def
137 += groupname "Common flags"
138 += help no_append_root_help,
141 += groupname "Common flags"
146 += groupname "Common flags"
148 += help timeout_help,
153 += details [" " ++ desc]
156 -- Here we just create the NS/MX modes using our make_mode from above.
157 ns = make_mode NS ns_description
158 mx = make_mode MX mx_description
162 -- | This is the public interface; i.e. what 'main' should use to get
163 -- the command-line arguments.
166 get_args = cmdArgs_ arg_spec