cmdargs 0.4 → 0.5
raw patch · 7 files changed
+52/−17 lines, 7 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- System/Console/CmdArgs/Explicit/Help.hs +1/−1
- System/Console/CmdArgs/Explicit/Type.hs +9/−9
- System/Console/CmdArgs/Implicit/Global.hs +1/−2
- System/Console/CmdArgs/Implicit/Local.hs +1/−0
- System/Console/CmdArgs/Test/Implicit/Tests.hs +38/−3
- System/Console/CmdArgs/Text.hs +1/−1
- cmdargs.cabal +1/−1
System/Console/CmdArgs/Explicit/Help.hs view
@@ -120,7 +120,7 @@ [Line $ " " ++ modeHelp x | not $ null $ modeHelp x] suf = space ([Line "Flags:" | mixedGroup flags] ++- (helpGroup helpFlag $ modeGroupFlags x)) +++ helpGroup helpFlag (modeGroupFlags x)) ++ space (map Line $ modeHelpSuffix x)
System/Console/CmdArgs/Explicit/Type.hs view
@@ -148,17 +148,17 @@ -- | Check that a mode is well formed. checkMode :: Mode a -> Maybe String-checkMode x =- (checkNames "modes" $ concatMap modeNames $ modeModes x) `mplus`- msum (map checkMode $ modeModes x) `mplus`- (checkGroup $ modeGroupModes x) `mplus`- (checkGroup $ modeGroupFlags x) `mplus`- (checkNames "flag names" $ concatMap flagNames $ modeFlags x)+checkMode x = msum+ [checkNames "modes" $ concatMap modeNames $ modeModes x+ ,msum $ map checkMode $ modeModes x+ ,checkGroup $ modeGroupModes x+ ,checkGroup $ modeGroupFlags x+ ,checkNames "flag names" $ concatMap flagNames $ modeFlags x] where checkGroup :: Group a -> Maybe String- checkGroup x =- (check "Empty group name" $ all (not . null . fst) $ groupNamed x) `mplus`- (check "Empty group contents" $ all (not . null . snd) $ groupNamed x)+ checkGroup x = msum+ [check "Empty group name" $ all (not . null . fst) $ groupNamed x+ ,check "Empty group contents" $ all (not . null . snd) $ groupNamed x] checkNames :: String -> [Name] -> Maybe String checkNames msg xs = check "Empty names" (all (not . null) xs) `mplus` do
System/Console/CmdArgs/Implicit/Global.hs view
@@ -144,7 +144,6 @@ --------------------------------------------------------------------- -- ADD EXTRA PIECES - extraFlags :: Prog_ -> Prog_ extraFlags p = p{progModes = map f $ progModes p} where f m = m{modeFlags_ = modeFlags_ m ++ map (\x -> def{flagFlag=x, flagExplicit=True, flagGroup=grp}) flags}@@ -178,7 +177,7 @@ assignNames :: Prog_ -> Prog_ assignNames x = x{progModes = map f $ namesOn fromMode toMode $ progModes x} where- fromMode x = Names (modeNames $ modeMode x) [asName $ ctor $ cmdArgsValue $ modeValue $ modeMode x]+ fromMode x = Names (modeNames $ modeMode x) [asName $ ctor $ cmdArgsValue $ modeValue $ modeMode x | not $ modeExplicit x] toMode xs x = x{modeMode = (modeMode x){modeNames=["["++head xs++"]" | modeDefault x] ++ xs}} fromFlagLong x = Names (flagNames $ flagFlag x) [asName $ fromMaybe (flagField x) (flagEnum x) | not $ flagExplicit x]
System/Console/CmdArgs/Implicit/Local.hs view
@@ -138,6 +138,7 @@ modeAnn ModeDefault x = x{modeDefault=True} modeAnn (GroupName a) x = x{modeGroup=Just a} modeAnn Explicit x = x{modeExplicit=True}+modeAnn (Name a) x = withMode x $ \x -> x{modeNames=a:modeNames x} modeAnn a x = err "mode" $ show a
System/Console/CmdArgs/Test/Implicit/Tests.hs view
@@ -8,10 +8,12 @@ import System.Console.CmdArgs.Test.Implicit.Util -test = test1 >> test2 >> test3 >> test4 >> test5 >> test6 >> test7 >> test8 >> test9 >> test10 >> test11+test = test1 >> test2 >> test3 >> test4 >> test5 >> test6 >> test7 >> test8 >> test9 >> test10 >>+ test11 >> test12 >> test13 demos = zipWith f [1..] [toDemo mode1, toDemo mode2, toDemo mode3, toDemo mode4, toDemo mode5, toDemo mode6- ,toDemo mode7, toDemo mode8, toDemo mode9, toDemo mode10, toDemo mode11]+ ,toDemo mode7, toDemo mode8, toDemo mode9, toDemo mode10, toDemo mode11, toDemo mode12+ ,toDemo mode13] where f i x = x{modeHelp = "Testing various corner cases (" ++ show i ++ ")"} @@ -22,7 +24,7 @@ deriving (Show,Eq,Data,Typeable) def1 = Test1 def def def (def &= args) def def def-mode1 = cmdArgsMode $ def1+mode1 = cmdArgsMode def1 test1 = do let Tester{..} = tester "Test1" mode1@@ -72,6 +74,7 @@ ["a","1"] === Test3 [1] ["foo"] ["a"] ["a","1","c"] === Test3 [1] ["c"] ["a"] ["a","1","c","d"] === Test3 [1] ["c"] ["a","d"]+ invalid $ \_ -> Test3 def def (def &= help "help" &= args) -- from bug #222@@ -202,3 +205,35 @@ fails [] ["test11a","test"] === Test11A "test" ["test11b","test"] === Test11B "test"+++-- #351, check you can add name annotations to modes+data Test12 = Test12A | Test12B deriving (Eq,Show,Data,Typeable)++mode12 = cmdArgsMode $ modes [Test12A &= name "check", Test12B]+mode12_ = cmdArgsMode $ modes [Test12A &= name "check" &= explicit, Test12B]++test12 = do+ let Tester{..} = tester "Test12" mode12+ fails []+ ["test12a"] === Test12A+ ["check"] === Test12A+ ["test12b"] === Test12B+ fails ["t"]+ let Tester{..} = tester "Test12" mode12_+ fails []+ fails ["test12a"]+ ["check"] === Test12A+ ["test12b"] === Test12B+ ["t"] === Test12B++-- #350, check help gets attached to modes properly+data Test13 = Test13A | Test13B deriving (Eq,Show,Data,Typeable)++mode13 = cmdArgsMode_ $ modes_ [record Test13A [] += help "foo", record Test13B [] += help "bar"]+ += help "all"++test13 = do+ let Tester{..} = tester "Test13" mode13+ fails []+ ["test13a"] === Test13A
System/Console/CmdArgs/Text.hs view
@@ -96,7 +96,7 @@ f (Line x) = map (a++) $ wrap1 (width - length a) b where (a,b) = span isSpace x - f (Cols xs) = (concat $ zipWith pad ys xs ++ [z1]) : map (replicate n ' '++) zs+ f (Cols xs) = concat (zipWith pad ys xs ++ [z1]) : map (replicate n ' '++) zs where ys = fromJust $ lookup (length xs) cs n = sum ys + length (takeWhile isSpace $ last xs) z1:zs = wrap1 (width - n) (last xs)
cmdargs.cabal view
@@ -1,7 +1,7 @@ cabal-version: >= 1.6 build-type: Simple name: cmdargs-version: 0.4+version: 0.5 license: BSD3 license-file: LICENSE category: Console