{-# LANGUAGE DeriveDataTypeable #-} module CommandLine ( get_args ) where import System.Console.CmdArgs ( (&=), cmdArgs, def, details, help, program, summary ) -- Get the version from Cabal. import Paths_mailbox_count ( version ) import Data.Version ( showVersion ) import OptionalConfiguration ( OptionalConfiguration(..) ) description :: String description = "Count mailboxes in a SQL database." program_name :: String program_name = "mailbox-count" my_summary :: String my_summary = program_name ++ "-" ++ (showVersion version) both_help :: String both_help = "Produce both summary and detailed reports" database_help :: String database_help = "The name of the database to which we should connect" detail_help :: String detail_help = "Produce a detailed report listing all mailboxes by domain" host_help :: String host_help = "Hostname where the database is located" password_help :: String password_help = "Password used to connect to the database" port_help :: String port_help = "Port number used to connect to the database" username_help :: String username_help = "Username used to connect to the database" arg_spec :: OptionalConfiguration arg_spec = OptionalConfiguration { both = def &= help both_help, database = def &= help database_help, detail = def &= help detail_help, host = def &= help host_help, password = def &= help password_help, port = def &= help port_help, username = def &= help username_help } &= program program_name &= summary my_summary &= details [description] get_args :: IO OptionalConfiguration get_args = cmdArgs arg_spec