packages feed

simple-get-opt 0.1.0.0 → 0.2.0

raw patch · 2 files changed

+25/−8 lines, 2 filesdep ~basePVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base

API changes (from Hackage documentation)

- SimpleGetOpt: optArgument :: OptDescr a -> ArgDescr a
- SimpleGetOpt: optDescription :: OptDescr a -> String
- SimpleGetOpt: optLongFlags :: OptDescr a -> [String]
- SimpleGetOpt: optShortFlags :: OptDescr a -> [Char]
- SimpleGetOpt: progDefaults :: OptSpec a -> a
- SimpleGetOpt: progOptions :: OptSpec a -> [OptDescr a]
- SimpleGetOpt: progParamDocs :: OptSpec a -> [(String, String)]
- SimpleGetOpt: progParams :: OptSpec a -> String -> OptSetter a
+ SimpleGetOpt: GetOptException :: [String] -> GetOptException
+ SimpleGetOpt: [optArgument] :: OptDescr a -> ArgDescr a
+ SimpleGetOpt: [optDescription] :: OptDescr a -> String
+ SimpleGetOpt: [optLongFlags] :: OptDescr a -> [String]
+ SimpleGetOpt: [optShortFlags] :: OptDescr a -> [Char]
+ SimpleGetOpt: [progDefaults] :: OptSpec a -> a
+ SimpleGetOpt: [progOptions] :: OptSpec a -> [OptDescr a]
+ SimpleGetOpt: [progParamDocs] :: OptSpec a -> [(String, String)]
+ SimpleGetOpt: [progParams] :: OptSpec a -> String -> OptSetter a
+ SimpleGetOpt: data GetOptException
+ SimpleGetOpt: getOptsX :: OptSpec a -> IO a
+ SimpleGetOpt: instance GHC.Exception.Type.Exception SimpleGetOpt.GetOptException
+ SimpleGetOpt: instance GHC.Show.Show SimpleGetOpt.GetOptException
- SimpleGetOpt: NoArg :: (OptSetter a) -> ArgDescr a
+ SimpleGetOpt: NoArg :: OptSetter a -> ArgDescr a

Files

simple-get-opt.cabal view
@@ -1,5 +1,5 @@ name:                simple-get-opt-version:             0.1.0.0+version:             0.2.0 synopsis:            A simple library for processing command-line options. description:   A simple library for processing command-line options.@@ -17,7 +17,7 @@ library   hs-source-dirs:      src   exposed-modules:     SimpleGetOpt-  build-depends:       base < 10+  build-depends:       base < 5   default-language:    Haskell2010  source-repository head
src/SimpleGetOpt.hs view
@@ -48,10 +48,12 @@ module SimpleGetOpt   ( -- * Basic functionality     getOpts+  , getOptsX   , OptSpec(..)   , OptDescr(..)   , OptSetter   , ArgDescr(..)+  , GetOptException(..)    -- * Information and error reporting.   , dumpUsage@@ -65,6 +67,7 @@ import System.Environment(getArgs)  import Control.Monad(unless)+import Control.Exception(Exception,throwIO,catch)   @@ -140,18 +143,28 @@  -- | Get the command-line options and process them according to the given spec. -- The options will be permuted to get flags.-getOpts :: OptSpec a -> IO a-getOpts os =+-- Throws a 'GetOptException' if some problems are found.+getOptsX :: OptSpec a -> IO a+getOptsX os =   do as <- getArgs      let (funs,files,errs) = GetOpt.getOpt GetOpt.Permute (opts os) as-     unless (null errs) $ reportUsageError os errs+     unless (null errs) $ throwIO (GetOptException errs)      let (a, errs1) = foldl addOpt (progDefaults os,[]) funs-     unless (null errs1) $ reportUsageError os errs1+     unless (null errs1) $ throwIO (GetOptException errs1)      let (b, errs2) = foldl (addFile (progParams os)) (a,[]) files-     unless (null errs2) $ reportUsageError os errs2+     unless (null errs2) $ throwIO (GetOptException errs2)      return b --- | Print the given messages on 'stderr' and show the program's usage info.++-- | Get the command-line options and process them according to the given spec.+-- The options will be permuted to get flags.+-- On failure, print an error message on standard error and exit.+getOpts :: OptSpec a -> IO a+getOpts os =+  getOptsX os `catch` \(GetOptException errs) -> reportUsageError os errs++-- | Print the given messages on 'stderr' and show the program's usage info,+-- then exit. reportUsageError :: OptSpec a -> [String] -> IO b reportUsageError os es =   do hPutStrLn stderr "Invalid command line options:"@@ -173,6 +186,10 @@              ps -> "Parameters:\n" ++ ps ++ "\n"    ppParam (x,y) = "  " ++ x ++ "    " ++ y ++ "\n"++data GetOptException = GetOptException [String] deriving Show++instance Exception GetOptException