X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FCommandLine.hs;h=787cc1992f3d0a1c8099a8048d833396698e76af;hb=6b199442fa5a94cd41c2e708a8338e2da0516fc8;hp=405ded8ef9597cb181e986b4d31240a6594a9e9e;hpb=d9cf306292f2bfaa00b4773737b67de7f4ecf983;p=email-validator.git diff --git a/src/CommandLine.hs b/src/CommandLine.hs index 405ded8..787cc19 100644 --- a/src/CommandLine.hs +++ b/src/CommandLine.hs @@ -1,19 +1,26 @@ {-# LANGUAGE DeriveDataTypeable #-} -module CommandLine +module CommandLine ( + Args(..), + get_args ) where -import System.Console.CmdArgs -import System.Console.CmdArgs.Explicit (process) -import System.Environment (getArgs, withArgs) -import System.Exit (ExitCode(..), exitWith) -import System.IO (hPutStrLn, stderr) +import System.Console.CmdArgs ( + Data, + (&=), + cmdArgs, + def, + details, + help, + program, + summary, + typFile ) + -- Get the version from Cabal. -import Paths_email_validator (version) -import Data.Version (showVersion) +import Paths_email_validator ( version ) +import Data.Version ( showVersion ) -import ExitCodes -- We optionally accept input/output files to use instead of -- stdin/stdout. @@ -21,7 +28,7 @@ data Args = Args { accept_a :: Bool, input_file :: Maybe FilePath, output_file :: Maybe FilePath, rfc5322 :: Bool } - deriving (Show, Data, Typeable) + deriving (Show, Data) description :: String description = "Perform naive validation of email addresses." @@ -48,9 +55,8 @@ rfc5322_help :: String rfc5322_help = "Validate according to RFC 5322 (incredibly lenient)." -arg_spec :: Mode (CmdArgs Args) +arg_spec :: Args arg_spec = - cmdArgsMode $ Args { accept_a = def &= help accept_a_help, input_file = def &= typFile &= help input_file_help, output_file = def &= typFile &= help output_file_help, @@ -59,26 +65,7 @@ arg_spec = &= summary my_summary &= details [description] -show_help :: IO (CmdArgs Args) -show_help = withArgs ["--help"] parse_args - - - -parse_args :: IO (CmdArgs Args) -parse_args = do - x <- getArgs - let y = process arg_spec x - case y of - Right result -> return result - Left err -> do - hPutStrLn stderr err - exitWith (ExitFailure exit_args_parse_failed) --- | Really get the command-line arguments. This calls 'parse_args' --- first to replace the default "wrong number of arguments" error, --- and then runs 'cmdArgsApply' on the result to do what the --- 'cmdArgs' function usually does. -apply_args :: IO Args -apply_args = - parse_args >>= cmdArgsApply +get_args :: IO Args +get_args = cmdArgs arg_spec