cmdargs 0.9.2 → 0.9.3
raw patch · 4 files changed
+37/−6 lines, 4 filesdep +filepathPVP ok
version bump matches the API change (PVP)
Dependencies added: filepath
API changes (from Hackage documentation)
+ System.Console.CmdArgs.Explicit: expandArgsAt :: [String] -> IO [String]
Files
- System/Console/CmdArgs/Explicit.hs +6/−4
- System/Console/CmdArgs/Explicit/ExpandArgsAt.hs +27/−0
- System/Console/CmdArgs/Explicit/Process.hs +1/−1
- cmdargs.cabal +3/−1
System/Console/CmdArgs/Explicit.hs view
@@ -59,7 +59,8 @@ flagHelpSimple, flagHelpFormat, flagVersion, flagsVerbosity, -- * Displaying help module System.Console.CmdArgs.Explicit.Help,- -- * Utilities for working with command line+ -- * Utilities for working with command lines+ module System.Console.CmdArgs.Explicit.ExpandArgsAt, module System.Console.CmdArgs.Explicit.SplitJoin, Complete(..), complete ) where@@ -67,6 +68,7 @@ import System.Console.CmdArgs.Explicit.Type import System.Console.CmdArgs.Explicit.Process import System.Console.CmdArgs.Explicit.Help+import System.Console.CmdArgs.Explicit.ExpandArgsAt import System.Console.CmdArgs.Explicit.SplitJoin import System.Console.CmdArgs.Explicit.Complete import System.Console.CmdArgs.Default@@ -82,7 +84,7 @@ import System.IO --- | Process the flags obtained by @'getArgs'@ with a mode. Displays+-- | Process the flags obtained by @'getArgs'@ and @'expandArgsAt'@ with a mode. Displays -- an error and exits with failure if the command line fails to parse, or returns -- the associated value. Implemented in terms of 'process'. This function makes -- use of the following environment variables:@@ -110,7 +112,7 @@ let var = mplus (lookup ("CMDARGS_HELPER_" ++ show (map toUpper $ head $ modeNames m ++ [nam])) env) (lookup "CMDARGS_HELPER" env) case var of- Nothing -> run =<< getArgs+ Nothing -> run =<< expandArgsAt =<< getArgs Just cmd -> do res <- execute cmd m [] case res of@@ -131,7 +133,7 @@ _ -> Nothing --- | Process a list of flags (usually obtained from @getArgs@) with a mode. Displays+-- | Process a list of flags (usually obtained from @'getArgs'@ and @'expandArgsAt'@) with a mode. Displays -- an error and exits with failure if the command line fails to parse, or returns -- the associated value. Implemeneted in terms of 'process'. This function -- does not take account of any environment variables that may be set
+ System/Console/CmdArgs/Explicit/ExpandArgsAt.hs view
@@ -0,0 +1,27 @@+{-# LANGUAGE RecordWildCards #-}+module System.Console.CmdArgs.Explicit.ExpandArgsAt(expandArgsAt) where++import System.FilePath+++-- | Expand @\@@ directives in a list of arguments, usually obtained from 'getArgs'.+-- As an example, given the file @test.txt@ with the lines @hello@ and @world@:+--+-- > expandArgsAt ["@test.txt","!"] == ["hello","world","!"]+--+-- Any @\@@ directives in the files will be recursively expanded (raising an error+-- if there is infinite recursion).+expandArgsAt :: [String] -> IO [String]+expandArgsAt = fmap concat . mapM (f [] ".")+ where+ f seen dir ('@':x)+ | x `elem` seen = error $ unlines $+ "System.Console.CmdArgs.Explicit.expandArgsAt, recursion in @ directives:" :+ map (" "++) (reverse $ x:seen)+ | length seen > 15 = error $ unlines $+ "System.Console.CmdArgs.Explicit.expandArgsAt, over 15 @ directives deep:" :+ map (" "++) (reverse seen)+ | otherwise = do+ src <- readFile $ dir </> x+ fmap concat $ mapM (f (x:seen) (takeDirectory x)) $ lines src+ f _ _ x = return [x]
System/Console/CmdArgs/Explicit/Process.hs view
@@ -7,7 +7,7 @@ import Data.Maybe --- | Process a list of flags (usually obtained from @getArgs@) with a mode. Returns+-- | Process a list of flags (usually obtained from @getArgs@/@expandArgsAt@) with a mode. Returns -- @Left@ and an error message if the command line fails to parse, or @Right@ and -- the associated value. process :: Mode a -> [String] -> Either String a
cmdargs.cabal view
@@ -1,7 +1,7 @@ cabal-version: >= 1.6 build-type: Simple name: cmdargs-version: 0.9.2+version: 0.9.3 license: BSD3 license-file: LICENSE category: Console@@ -48,6 +48,7 @@ library build-depends: base == 4.*,+ filepath, transformers == 0.2.*, process >= 1.0 && < 1.2 @@ -70,6 +71,7 @@ Data.Generics.Any Data.Generics.Any.Prelude System.Console.CmdArgs.Explicit.Complete+ System.Console.CmdArgs.Explicit.ExpandArgsAt System.Console.CmdArgs.Explicit.Help System.Console.CmdArgs.Explicit.Process System.Console.CmdArgs.Explicit.SplitJoin