packages feed

console-program 0.4.1.0 → 0.4.2.0

raw patch · 4 files changed

+47/−10 lines, 4 filesdep ~parsec-extradep ~transformers

Dependency ranges changed: parsec-extra, transformers

Files

CHANGELOG.md view
@@ -1,5 +1,9 @@ # Changelog +### 0.4.2.0++* Add `withNonOptions` function to consume any number of non-option arguments.+ ### 0.4.1.0  * Add the possibility to customize the prompt in interactive mode.
console-program.cabal view
@@ -1,11 +1,11 @@ name:            console-program-version:         0.4.1.0+version:         0.4.2.0 cabal-Version:   >= 1.6 license:         BSD3 author:          Arie Peterson maintainer:      ariep@xs4all.nl category:        Console-synopsis:        Interpret the command line and settings in a config file as commands and options+synopsis:        Interpret the command line and a config file as commands and options description:   This library provides a framework to build command line programs.   .@@ -48,11 +48,11 @@     ansi-wl-pprint >= 0.5 && < 0.7,     ansi-terminal >= 0.5 && < 0.7,     haskeline == 0.7.*,-    transformers >= 0.2 && < 0.5,+    transformers >= 0.2 && < 0.6,     utility-ht == 0.0.*,     split == 0.2.*,     parsec == 3.1.*,-    parsec-extra == 0.1.*+    parsec-extra == 0.2.*   if !os(windows)     build-depends:       unix >= 2.7 && < 2.8
src/System/Console/Argument.hs view
@@ -22,10 +22,11 @@  import System.Console.Internal hiding (name) -import           Data.Char        (toLower)-import           Data.List.HT     (viewR)+import           Data.Char          (toLower)+import           Data.List.HT       (viewR) import qualified Data.Map              as Map import qualified System.Console.GetOpt as GetOpt+import           Text.Parsec.String (Parser) import qualified Text.Parsec.Extra     as P  @@ -91,8 +92,7 @@ -- | A boolean. Argument can be \"1\",\"0\",\"true\",\"false\",\"on\",\"off\",\"yes\",\"no\". boolean :: Type Bool boolean = Type-  {-    name    = "BOOL"+  { name    = "BOOL"   , parser  = \ y -> maybe (e y) Right . flip Map.lookup m . map toLower $ y   , defaultValue = Just True   }@@ -102,11 +102,19 @@  -- | A natural number (in decimal). natural :: Type Integer-natural = Type { name = "INT (natural)", parser = P.parseM P.natural "", defaultValue = Nothing }+natural = Type+  { name = "INT (nonnegative)"+  , parser = parseEither P.natural ""+  , defaultValue = Nothing+  }  -- | An integer number (in decimal). integer :: Type Integer-integer = Type { name = "INT", parser = P.parseM P.integer "", defaultValue = Nothing }+integer = Type+  { name = "INT"+  , parser = parseEither P.integer ""+  , defaultValue = Nothing+  }  -- | A directory path. A trailing slash is stripped, if present. directory :: Type FilePath@@ -125,3 +133,8 @@ -- | A device path. device :: Type FilePath device = string { name = "DEVICE" }++-- Helper functions++parseEither :: Parser a -> String -> String -> Either String a+parseEither = P.parseM show
src/System/Console/Command.hs view
@@ -16,6 +16,7 @@   , Action   , io   , withNonOption+  , withNonOptions   , withOption   , ignoreOption   ) where@@ -74,6 +75,25 @@   , options = options (f undefined)   , ignoringOptions = ignoringOptions (f undefined)   }++-- | Create an action that takes all remaining non-option arguments.+--+--  The type of arguments is specified by the first parameter; such  values can+--  be obtained from the module "System.Console.Argument".+withNonOptions :: (MonadIO m) => Argument.Type x -> ([x] -> Action m) -> Action m+withNonOptions argumentType f = Action+   {+     run = \ nonOpts opts -> let runWithArgs args [] = run (f $ reverse args) [] opts+                                 runWithArgs args (x:xs) = case Argument.parser argumentType x of+                                   Left e -> liftIO $ do+                                     putStrLn e+                                     exitFailure+                                   Right y -> runWithArgs (y:args) xs+                             in runWithArgs [] nonOpts+   , nonOptions = ("[" ++ Argument.name argumentType ++ "...]") : nonOptions (f [])+   , options = options (f [])+   , ignoringOptions = ignoringOptions (f [])+   }  -- | Create an action that takes an option. --