packages feed

cli-arguments 0.2.0.0 → 0.3.0.0

raw patch · 3 files changed

+172/−36 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ CLI.Arguments: args2Args1 :: (Char, Char) -> CLSpecifications -> [String] -> Args
+ CLI.Arguments: args2Args3'1 :: (Char, Char) -> (Args, Args, Args) -> CLSpecifications -> [String] -> (Args, Args, Args)
+ CLI.Arguments: args2Args31 :: (Char, Char) -> CLSpecifications -> [String] -> (Args, Args, Args)
+ CLI.Arguments: args2ArgsFilteredG :: (Arguments -> Bool) -> CLSpecifications -> [String] -> Args
+ CLI.Arguments: args2ArgsFilteredG1 :: (Char, Char) -> (Arguments -> Bool) -> CLSpecifications -> [String] -> Args
+ CLI.Arguments: takeArgs1SortedBy :: (Char, Char) -> (Arguments -> Bool) -> (Arguments -> Arguments -> Ordering) -> CLSpecifications -> [String] -> Args
+ CLI.Arguments: takeArgsSortedBy :: (Arguments -> Bool) -> (Arguments -> Arguments -> Ordering) -> CLSpecifications -> [String] -> Args
+ CLI.Arguments: takeCs1 :: (Char, Char) -> CLSpecifications -> [String] -> Args
+ CLI.Arguments: takeCs1Arr :: (Char, Char) -> CLSpecifications -> [String] -> Array Int Arguments
+ CLI.Arguments: takeCs1ArrSortedBy :: (Char, Char) -> (Arguments -> Arguments -> Ordering) -> CLSpecifications -> [String] -> Array Int Arguments
+ CLI.Arguments: takeCs1SortedBy :: (Char, Char) -> (Arguments -> Arguments -> Ordering) -> CLSpecifications -> [String] -> Args
- CLI.Arguments: B :: Int -> String -> [String] -> Arguments
+ CLI.Arguments: B :: GQtyArgs -> Delimiter -> [String] -> Arguments
- CLI.Arguments: C :: String -> [String] -> Arguments
+ CLI.Arguments: C :: Delimiter -> [String] -> Arguments

Files

CHANGELOG.md view
@@ -10,5 +10,10 @@  ## 0.2.0.0 -- 2021-12-28 -* Second version. Fixed issues with the partially defined function. Added new -functionality related to sorting and arrays. +* Second version. Fixed issues with the partially defined function. Added new+functionality related to sorting and arrays.++## 0.3.0.0 -- 2021-12-29++* Third version. Added new functions with the 1 in their names to deal with apropos (in some way) framed by two delimiters+variants of the groups. Some code improvements, reduced duplications, changed pragmas INLINE to INLINABLE.
CLI/Arguments.hs view
@@ -17,8 +17,8 @@  data Arguments =   A String-  | B Int String [String]-  | C String [String]+  | B GQtyArgs Delimiter [String]+  | C Delimiter [String]       deriving Eq  type Args = [Arguments]@@ -105,63 +105,166 @@   -> [String]   -> (Args,Args,Args) args2Args3 = args2Args3' ([],[],[])-{-# INLINE args2Args3 #-}+{-# INLINABLE args2Args3 #-} --- | This function can actually parse the command line arguments being the ['String'] so that some of them will disappear--- because of the 'CLSpecifications' provided and the order of the arguments.+------------------------------------------------++args2Args1+  :: (Char,Char) -- ^ A pair of the first characters of the starting group delimiter (the same for all 'String's in the all 'CLSpecifications') and the probable its modification (the first character of the last delimiter).+  -> CLSpecifications+  -> [String]+  ->  Args+args2Args1 (x1,x2) (t@(xs@(k:ks),n):ts) xss@(js:jss)+  | n < 0 = C xs qss:args2Args1 (x1,x2) ts (kss `mappend` rss)+  | n == 0 = A js:args2Args1 (x1,x2) ts jss+  | otherwise = B n xs vss:args2Args1(x1,x2) ts (kss `mappend` zss)+      where (kss,uss) = break (== xs) xss+            wss = drop 1 uss+            (qss,pss) = break (\rs -> rs == xs || (k == x1 && rs == (x2:ks))) wss+            rss = drop 1 pss+            (vss,zss) = splitAt n wss+args2Args1 (x1,x2) (t@([],n):ts) xss = args2Args1 (x1,x2) ts xss+args2Args1 _ [] xss = map A xss+args2Args1 _ _ [] = []++args2Args3'1+  :: (Char,Char) -- ^ A pair of the first characters of the starting group delimiter (the same for all 'String's in the all 'CLSpecifications') and the probable its modification (the first character of the last delimiter).+  -> (Args,Args,Args)+  -> CLSpecifications+  -> [String]+  ->  (Args,Args,Args)+args2Args3'1 (x1,x2) (w1,w2,w3) (t@(xs@(k:ks),n):ts) xss@(js:jss)+  | n < 0 = args2Args3'1 (x1,x2) (w1,w2,C xs qss:w3) ts (kss `mappend` rss)+  | n == 0 = args2Args3'1 (x1,x2) (A js:w1,w2,w3) ts jss+  | otherwise = args2Args3'1 (x1,x2) (w1,B n xs vss:w2,w3) ts (kss `mappend` zss)+      where (kss,uss) = break (== xs) xss+            wss = drop 1 uss+            (qss,pss) = break (\rs -> rs == xs || (k == x1 && rs == (x2:ks))) wss+            rss = drop 1 pss+            (vss,zss) = splitAt n wss+args2Args3'1 (x1,x2) (w1,w2,w3) (t@([],n):ts) xss = args2Args3'1 (x1,x2) (w1,w2,w3) ts xss+args2Args3'1 _ (w1,w2,w3) [] xss = (map A xss `mappend` w1,w2,w3)+args2Args3'1 _ (w1,w2,w3) _ [] = (w1,w2,w3)++args2Args31+  :: (Char,Char) -- ^ A pair of the first characters of the starting group delimiter (the same for all 'String's in the all 'CLSpecifications') and the probable its modification (the first character of the last delimiter).+  -> CLSpecifications+  -> [String]+  -> (Args,Args,Args)+args2Args31 (x1,x2) = args2Args3'1 (x1,x2) ([],[],[])+{-# INLINABLE args2Args31 #-}++------------------------------------------++-- | This function can actually parse the command line arguments being the ['String'].+args2ArgsFilteredG+  :: (Arguments -> Bool) -- ^ A predicate to check which 'Arguments' must be kept in the result.+  -> CLSpecifications+  -> [String]+  -> Args+args2ArgsFilteredG f ts = filter f . map b1Args2AArgs . args2Args ts+{-# INLINABLE args2ArgsFilteredG #-}++-- | This function can actually parse the command line arguments being the ['String'].+args2ArgsFilteredG1+  :: (Char,Char) -- ^ A pair of the first characters of the starting group delimiter (the same for all 'String's in the all 'CLSpecifications') and the probable its modification (the first character of the last delimiter).+  -> (Arguments -> Bool) -- ^ A predicate to check which 'Arguments' must be kept in the result.+  -> CLSpecifications+  -> [String]+  -> Args+args2ArgsFilteredG1 (x1,x2) f ts = filter f . map b1Args2AArgs . args2Args1 (x1,x2) ts+{-# INLINABLE args2ArgsFilteredG1 #-}++-- | This function can actually parse the command line arguments being the ['String']. args2ArgsFiltered   :: CLSpecifications   -> [String]   -> Args-args2ArgsFiltered ts = filter notNullArguments . map b1Args2AArgs . args2Args ts-{-# INLINE args2ArgsFiltered #-}+args2ArgsFiltered = args2ArgsFilteredG notNullArguments+{-# INLINABLE args2ArgsFiltered #-}  takeCs   :: CLSpecifications   -> [String]   -> Args-takeCs ts = filter (\x -> notNullArguments x && isC x) . map b1Args2AArgs . args2Args ts-{-# INLINE takeCs #-}+takeCs = args2ArgsFilteredG (\x -> notNullArguments x && isC x)+{-# INLINABLE takeCs #-} +takeCs1+  :: (Char,Char) -- ^ A pair of the first characters of the starting group delimiter (the same for all 'String's in the all 'CLSpecifications') and the probable its modification (the first character of the last delimiter).+  -> CLSpecifications+  -> [String]+  -> Args+takeCs1 (x1,x2) = args2ArgsFilteredG1 (x1,x2) (\x -> notNullArguments x && isC x)+{-# INLINABLE takeCs1 #-}+ takeBs   :: CLSpecifications   -> [String]   -> Args-takeBs ts = filter (\x -> notNullArguments x && isB x) . map b1Args2AArgs . args2Args ts-{-# INLINE takeBs #-}+takeBs = args2ArgsFilteredG (\x -> notNullArguments x && isB x)+{-# INLINABLE takeBs #-}  takeAs   :: CLSpecifications   -> [String]   -> Args-takeAs ts = filter (\x -> notNullArguments x && isA x) . map b1Args2AArgs . args2Args ts-{-# INLINE takeAs #-}+takeAs = args2ArgsFilteredG (\x -> notNullArguments x && isA x)+{-# INLINABLE takeAs #-}  ------------------------------------------------------ +takeArgsSortedBy+  :: (Arguments -> Bool) -- ^ A predicate to check which 'Arguments' must be kept in the result.+  -> (Arguments -> Arguments -> Ordering) -- ^ A 'compare'-like implementation for 'Arguments'. If needed you can implement your own 'Ord' instance for 'Arguments' and use it here. Here can be partial, just for 'C's.+  -> CLSpecifications+  -> [String]+  -> Args+takeArgsSortedBy g f ts = sortBy f . args2ArgsFilteredG g ts+{-# INLINABLE takeArgsSortedBy #-}++takeArgs1SortedBy+  :: (Char,Char) -- ^ A pair of the first characters of the starting group delimiter (the same for all 'String's in the all 'CLSpecifications') and the probable its modification (the first character of the last delimiter).+  -> (Arguments -> Bool) -- ^ A predicate to check which 'Arguments' must be kept in the result.+  -> (Arguments -> Arguments -> Ordering) -- ^ A 'compare'-like implementation for 'Arguments'. If needed you can implement your own 'Ord' instance for 'Arguments' and use it here. Here can be partial, just for 'C's.+  -> CLSpecifications+  -> [String]+  -> Args+takeArgs1SortedBy (x1,x2) g f ts = sortBy f . args2ArgsFilteredG1 (x1,x2) g ts+{-# INLINABLE takeArgs1SortedBy #-}+ takeCsSortedBy   :: (Arguments -> Arguments -> Ordering) -- ^ A 'compare'-like implementation for 'Arguments'. If needed you can implement your own 'Ord' instance for 'Arguments' and use it here. Here can be partial, just for 'C's.   -> CLSpecifications   -> [String]   -> Args-takeCsSortedBy f ts = sortBy f . filter (\x -> notNullArguments x && isC x) . map b1Args2AArgs . args2Args ts-{-# INLINE takeCsSortedBy #-}+takeCsSortedBy = takeArgsSortedBy (\x -> notNullArguments x && isC x)+{-# INLINABLE takeCsSortedBy #-} +takeCs1SortedBy+  :: (Char,Char) -- ^ A pair of the first characters of the starting group delimiter (the same for all 'String's in the all 'CLSpecifications') and the probable its modification (the first character of the last delimiter).+  -> (Arguments -> Arguments -> Ordering) -- ^ A 'compare'-like implementation for 'Arguments'. If needed you can implement your own 'Ord' instance for 'Arguments' and use it here. Here can be partial, just for 'C's.+  -> CLSpecifications+  -> [String]+  -> Args+takeCs1SortedBy (x1,x2) = takeArgs1SortedBy (x1,x2) (\x -> notNullArguments x && isC x)+{-# INLINABLE takeCs1SortedBy #-}+ takeBsSortedBy   :: (Arguments -> Arguments -> Ordering) -- ^ A 'compare'-like implementation for 'Arguments'. If needed you can implement your own 'Ord' instance for 'Arguments' and use it here. Here can be partial, just for 'B's.   -> CLSpecifications   -> [String]   -> Args-takeBsSortedBy f ts = sortBy f . filter (\x -> notNullArguments x && isB x) . map b1Args2AArgs . args2Args ts-{-# INLINE takeBsSortedBy #-}+takeBsSortedBy = takeArgsSortedBy (\x -> notNullArguments x && isB x)+{-# INLINABLE takeBsSortedBy #-}  takeAsSortedBy   :: (Arguments -> Arguments -> Ordering) -- ^ A 'compare'-like implementation for 'Arguments'. If needed you can implement your own 'Ord' instance for 'Arguments' and use it here. Here can be partial, just for 'A's.   -> CLSpecifications   -> [String]   -> Args-takeAsSortedBy f ts = sortBy f . filter (\x -> notNullArguments x && isA x) . map b1Args2AArgs . args2Args ts-{-# INLINE takeAsSortedBy #-}+takeAsSortedBy = takeArgsSortedBy (\x -> notNullArguments x && isA x)+{-# INLINABLE takeAsSortedBy #-}  ------------------------------------------------------ @@ -172,10 +275,22 @@ takeCsArr ts xss  | null xss = error "CLI.Arguments.takeCsArr: Empty list of 'String's."  | otherwise = listArray (0,l-1) js-     where js = filter (\x -> notNullArguments x && isC x) . map b1Args2AArgs . args2Args ts $ xss+     where js = takeCs ts xss            l = length js-{-# INLINE takeCsArr #-}+{-# INLINABLE takeCsArr #-} +takeCs1Arr+  :: (Char,Char) -- ^ A pair of the first characters of the starting group delimiter (the same for all 'String's in the all 'CLSpecifications') and the probable its modification (the first character of the last delimiter).+  -> CLSpecifications+  -> [String]+  -> Array Int Arguments+takeCs1Arr (x1,x2) ts xss+ | null xss = error "CLI.Arguments.takeCs1Arr: Empty list of 'String's."+ | otherwise = listArray (0,l-1) js+     where js = takeCs1 (x1,x2) ts xss+           l = length js+{-# INLINABLE takeCs1Arr #-}+ takeBsArr   :: CLSpecifications   -> [String]@@ -183,20 +298,20 @@ takeBsArr ts xss  | null xss = error "CLI.Arguments.takeBsArr: Empty list of 'String's."  | otherwise = listArray (0,l-1) js-     where js = filter (\x -> notNullArguments x && isB x) . map b1Args2AArgs . args2Args ts $ xss+     where js = takeBs ts xss            l = length js-{-# INLINE takeBsArr #-}+{-# INLINABLE takeBsArr #-}  takeAsArr   :: CLSpecifications   -> [String]   -> Array Int Arguments takeAsArr ts xss- | null xss = error "CLI.Arguments.takeBsArr: Empty list of 'String's."+ | null xss = error "CLI.Arguments.takeAsArr: Empty list of 'String's."  | otherwise = listArray (0,l-1) js-     where js = filter (\x -> notNullArguments x && isA x) . map b1Args2AArgs . args2Args ts $ xss+     where js = takeAs ts xss            l = length js-{-# INLINE takeAsArr #-}+{-# INLINABLE takeAsArr #-}  --------------------------------------------------- @@ -208,10 +323,23 @@ takeCsArrSortedBy f ts xss  | null xss = error "CLI.Arguments.takeCsArrSortedBy: Empty list of 'String's."  | otherwise = listArray (0,l-1) js-     where js = sortBy f . filter (\x -> notNullArguments x && isC x) . map b1Args2AArgs . args2Args ts $ xss+     where js = takeArgsSortedBy (\x -> notNullArguments x && isC x) f  ts xss            l = length js-{-# INLINE takeCsArrSortedBy #-}+{-# INLINABLE takeCsArrSortedBy #-} +takeCs1ArrSortedBy+  :: (Char,Char) -- ^ A pair of the first characters of the starting group delimiter (the same for all 'String's in the all 'CLSpecifications') and the probable its modification being also the first character.+  -> (Arguments -> Arguments -> Ordering) -- ^ A 'compare'-like implementation for 'Arguments'. If needed you can implement your own 'Ord' instance for 'Arguments' and use it here. Here can be partial, just for 'C's.+  -> CLSpecifications+  -> [String]+  -> Array Int Arguments+takeCs1ArrSortedBy (x1,x2) f ts xss+ | null xss = error "CLI.Arguments.takeCs1ArrSortedBy: Empty list of 'String's."+ | otherwise = listArray (0,l-1) js+     where js = takeArgs1SortedBy (x1,x2) (\x -> notNullArguments x && isC x) f  ts xss+           l = length js+{-# INLINABLE takeCs1ArrSortedBy #-}+ takeBsArrSortedBy   :: (Arguments -> Arguments -> Ordering) -- ^ A 'compare'-like implementation for 'Arguments'. If needed you can implement your own 'Ord' instance for 'Arguments' and use it here. Here can be partial, just for 'B's.   -> CLSpecifications@@ -220,9 +348,9 @@ takeBsArrSortedBy f ts xss  | null xss = error "CLI.Arguments.takeBsArrSortedBy: Empty list of 'String's."  | otherwise = listArray (0,l-1) js-     where js = sortBy f . filter (\x -> notNullArguments x && isB x) . map b1Args2AArgs . args2Args ts $ xss+     where js = takeArgsSortedBy (\x -> notNullArguments x && isB x) f  ts xss            l = length js-{-# INLINE takeBsArrSortedBy #-}+{-# INLINABLE takeBsArrSortedBy #-}  takeAsArrSortedBy   :: (Arguments -> Arguments -> Ordering) -- ^ A 'compare'-like implementation for 'Arguments'. If needed you can implement your own 'Ord' instance for 'Arguments' and use it here. Here can be partial, just for 'A's.@@ -230,8 +358,11 @@   -> [String]   -> Array Int Arguments takeAsArrSortedBy f ts xss- | null xss = error "CLI.Arguments.takeBsArrSortedBy: Empty list of 'String's."+ | null xss = error "CLI.Arguments.takeAsArrSortedBy: Empty list of 'String's."  | otherwise = listArray (0,l-1) js-     where js = sortBy f . filter (\x -> notNullArguments x && isA x) . map b1Args2AArgs . args2Args ts $ xss+     where js = takeArgsSortedBy (\x -> notNullArguments x && isA x) f  ts xss            l = length js-{-# INLINE takeAsArrSortedBy #-}+{-# INLINABLE takeAsArrSortedBy #-}++------------------------------------------------------+
cli-arguments.cabal view
@@ -4,7 +4,7 @@ -- http://haskell.org/cabal/users-guide/  name:                cli-arguments-version:             0.2.0.0+version:             0.3.0.0 synopsis:            A library to process command line arguments in some more convenient way. description:         Uses three types of the command line arguments and order of their parsing. Usually firstly the framed by some string delimiter (the different ones) are parsed, then the groups of arguments and then the rest single-field arguments. All these groups must be not nested one into the others. -- bug-reports: