packages feed

cli-arguments 0.5.0.0 → 0.6.0.0

raw patch · 5 files changed

+88/−207 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- CLI.Arguments: args2Args :: CLSpecifications -> [String] -> Args
- CLI.Arguments: args2Args1 :: FirstChars -> CLSpecifications -> [String] -> Args
- CLI.Arguments: args2Args3 :: CLSpecifications -> [String] -> (Args, Args, Args)
- CLI.Arguments: args2Args3' :: (Args, Args, Args) -> CLSpecifications -> [String] -> (Args, Args, Args)
- CLI.Arguments: args2Args3'1 :: FirstChars -> (Args, Args, Args) -> CLSpecifications -> [String] -> (Args, Args, Args)
- CLI.Arguments: args2Args31 :: FirstChars -> CLSpecifications -> [String] -> (Args, Args, Args)
- CLI.Arguments: args2ArgsFiltered :: CLSpecifications -> [String] -> Args
- CLI.Arguments: args2ArgsFilteredG :: (Arguments -> Bool) -> CLSpecifications -> [String] -> Args
- CLI.Arguments: args2ArgsFilteredG1 :: FirstChars -> (Arguments -> Bool) -> CLSpecifications -> [String] -> Args
- CLI.Arguments: takeArgs1SortedBy :: FirstChars -> (Arguments -> Bool) -> (Arguments -> Arguments -> Ordering) -> CLSpecifications -> [String] -> Args
- CLI.Arguments: takeArgsSortedBy :: (Arguments -> Bool) -> (Arguments -> Arguments -> Ordering) -> CLSpecifications -> [String] -> Args
- CLI.Arguments: takeAs :: CLSpecifications -> [String] -> Args
- CLI.Arguments: takeAsSortedBy :: (Arguments -> Arguments -> Ordering) -> CLSpecifications -> [String] -> Args
- CLI.Arguments: takeBs :: CLSpecifications -> [String] -> Args
- CLI.Arguments: takeBsSortedBy :: (Arguments -> Arguments -> Ordering) -> CLSpecifications -> [String] -> Args
- CLI.Arguments: takeCs :: CLSpecifications -> [String] -> Args
- CLI.Arguments: takeCs1 :: FirstChars -> CLSpecifications -> [String] -> Args
- CLI.Arguments: takeCs1SortedBy :: FirstChars -> (Arguments -> Arguments -> Ordering) -> CLSpecifications -> [String] -> Args
- CLI.Arguments: takeCsSortedBy :: (Arguments -> Arguments -> Ordering) -> CLSpecifications -> [String] -> Args
+ CLI.Arguments.Sorted: takeArgs1SortedBy :: FirstChars -> (Arguments -> Bool) -> (Arguments -> Arguments -> Ordering) -> CLSpecifications -> [String] -> Args
+ CLI.Arguments.Sorted: takeArgsSortedBy :: (Arguments -> Bool) -> (Arguments -> Arguments -> Ordering) -> CLSpecifications -> [String] -> Args
+ CLI.Arguments.Sorted: takeAsSortedBy :: (Arguments -> Arguments -> Ordering) -> CLSpecifications -> [String] -> Args
+ CLI.Arguments.Sorted: takeBsSortedBy :: (Arguments -> Arguments -> Ordering) -> CLSpecifications -> [String] -> Args
+ CLI.Arguments.Sorted: takeCs1SortedBy :: FirstChars -> (Arguments -> Arguments -> Ordering) -> CLSpecifications -> [String] -> Args
+ CLI.Arguments.Sorted: takeCsSortedBy :: (Arguments -> Arguments -> Ordering) -> CLSpecifications -> [String] -> Args

Files

CHANGELOG.md view
@@ -31,3 +31,12 @@  * Fifth version. Added 3 new modules CLI.Arguments.Parsing, CLI.Arguments.Arr, CLI.Arguments.Get and the new functionality to the first one, splitted the previous one between the last two. This should improve importing opportunities.++## 0.6.0.0 -- 2022-01-12++* Sixth version. Removed the functionality from the CLI.Arguments module that +has a bug in it and non-consistent logics. Splitted the functionality between +modules further, added a new module CLI.Arguments.Sorted with the corresponding+functionality. Please, use the CLI.Arguments.Parsing module as logic and +consistent one.+
CLI/Arguments.hs view
@@ -12,8 +12,6 @@ module CLI.Arguments where  import Data.Monoid (mappend)-import Data.Maybe (fromJust)-import Data.List (sortBy)  data Arguments =   A String@@ -71,201 +69,3 @@  | otherwise = b b1Args2AArgs x = x -args2Args-  :: CLSpecifications-  -> [String]-  ->  Args-args2Args (t@(xs,n):ts) xss@(js:jss)-  | n < 0 = C xs qss:args2Args ts (kss `mappend` rss)-  | n == 0 = A js:args2Args ts jss-  | otherwise = B n xs vss:args2Args ts (kss `mappend` zss)-      where (kss,uss) = break (== xs) xss-            wss = drop 1 uss-            (qss,pss) = break (== xs) wss-            rss = drop 1 pss-            (vss,zss) = splitAt n wss-args2Args [] xss = map A xss-args2Args _ [] = []--args2Args3'-  :: (Args,Args,Args)-  -> CLSpecifications-  -> [String]-  ->  (Args,Args,Args)-args2Args3' (w1,w2,w3) (t@(xs,n):ts) xss@(js:jss)-  | n < 0 = args2Args3' (w1,w2,C xs qss:w3) ts (kss `mappend` rss)-  | n == 0 = args2Args3' (A js:w1,w2,w3) ts jss-  | otherwise = args2Args3' (w1,B n xs vss:w2,w3) ts (kss `mappend` zss)-      where (kss,uss) = break (== xs) xss-            wss = drop 1 uss-            (qss,pss) = break (== xs) wss-            rss = drop 1 pss-            (vss,zss) = splitAt n wss-args2Args3' (w1,w2,w3) [] xss = (map A xss `mappend` w1,w2,w3)-args2Args3' (w1,w2,w3) _ [] = (w1,w2,w3)--args2Args3-  :: CLSpecifications-  -> [String]-  -> (Args,Args,Args)-args2Args3 = args2Args3' ([],[],[])-{-# INLINABLE args2Args3 #-}----------------------------------------------------args2Args1-  :: FirstChars -- ^ 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-  :: FirstChars -- ^ 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-  :: FirstChars -- ^ 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-  :: FirstChars -- ^ 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 = args2ArgsFilteredG notNullArguments-{-# INLINABLE args2ArgsFiltered #-}--takeCs-  :: CLSpecifications-  -> [String]-  -> Args-takeCs = args2ArgsFilteredG (\x -> notNullArguments x && isC x)-{-# INLINABLE takeCs #-}--takeCs1-  :: FirstChars -- ^ 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 = args2ArgsFilteredG (\x -> notNullArguments x && isB x)-{-# INLINABLE takeBs #-}--takeAs-  :: CLSpecifications-  -> [String]-  -> Args-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-  :: FirstChars -- ^ 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 = takeArgsSortedBy (\x -> notNullArguments x && isC x)-{-# INLINABLE takeCsSortedBy #-}--takeCs1SortedBy-  :: FirstChars -- ^ 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 = 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 = takeArgsSortedBy (\x -> notNullArguments x && isA x)-{-# INLINABLE takeAsSortedBy #-}
CLI/Arguments/Arr.hs view
@@ -14,6 +14,8 @@ import GHC.Arr import Data.List (sortBy) import CLI.Arguments+import CLI.Arguments.Parsing+import CLI.Arguments.Sorted  -- | For empty list of 'String's returns empty array that has no elements. Trying to index it always returns error and can cause -- segmentation fault in the running program or interpreter (GHCi).@@ -33,7 +35,7 @@   :: CLSpecifications   -> [String]   -> Array Int Arguments-takeCsArr = takeABCsArr takeCs+takeCsArr = takeABCsArr (\us zss -> fst . takeCsR us $ zss) {-# INLINABLE takeCsArr #-}  -- | For empty list of 'String's returns empty array that has no elements. Trying to index it always returns error and can cause@@ -43,7 +45,7 @@   -> CLSpecifications   -> [String]   -> Array Int Arguments-takeCs1Arr (x1,x2) = takeABCsArr (takeCs1 (x1,x2))+takeCs1Arr (x1,x2) = takeABCsArr (\us zss -> fst . takeCs1R (x1,x2) us $ zss) {-# INLINABLE takeCs1Arr #-}  -- | For empty list of 'String's returns empty array that has no elements. Trying to index it always returns error and can cause@@ -52,7 +54,7 @@   :: CLSpecifications   -> [String]   -> Array Int Arguments-takeBsArr = takeABCsArr takeBs+takeBsArr = takeABCsArr (\us zss -> fst . takeBsR us $ zss) {-# INLINABLE takeBsArr #-}  -- | For empty list of 'String's returns empty array that has no elements. Trying to index it always returns error and can cause@@ -61,7 +63,7 @@   :: CLSpecifications   -> [String]   -> Array Int Arguments-takeAsArr  = takeABCsArr takeAs+takeAsArr  = takeABCsArr (\us zss -> fst . takeAsR us $ zss) {-# INLINABLE takeAsArr #-}  ---------------------------------------------------
+ CLI/Arguments/Sorted.hs view
@@ -0,0 +1,70 @@+{-# OPTIONS_HADDOCK show-extensions #-}++-- |+-- Module      :  CLI.Arguments.Sorted+-- Copyright   :  (c) OleksandrZhabenko 2021-2022+-- License     :  MIT+-- Stability   :  Experimental+-- Maintainer  :  olexandr543@yahoo.com+--+-- A library to process command line arguments in some more convenient way.++module CLI.Arguments.Sorted where++import Data.Monoid (mappend)+import Data.Maybe (fromJust)+import Data.List (sortBy)+import CLI.Arguments+import CLI.Arguments.Parsing++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 yss = sortBy f . fst . args2ArgsFilteredGR g ts $ ([],yss)+{-# INLINABLE takeArgsSortedBy #-}++takeArgs1SortedBy+  :: FirstChars -- ^ 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 yss = sortBy f . fst . args2ArgsFilteredG1R (x1,x2) g ts $ ([],yss)+{-# 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 = takeArgsSortedBy (\x -> notNullArguments x && isC x)+{-# INLINABLE takeCsSortedBy #-}++takeCs1SortedBy+  :: FirstChars -- ^ 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 = 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 = takeArgsSortedBy (\x -> notNullArguments x && isA x)+{-# INLINABLE takeAsSortedBy #-}
cli-arguments.cabal view
@@ -4,9 +4,9 @@ -- http://haskell.org/cabal/users-guide/  name:                cli-arguments-version:             0.5.0.0+version:             0.6.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.+description:         Uses three types of the command line arguments and order of their parsing. All groups usually are not nested one into the others (but using the sequence of parsing functions, you can parse also nested structures as well). -- bug-reports: license:             MIT license-file:        LICENSE@@ -18,7 +18,7 @@ extra-source-files:  CHANGELOG.md  library-  exposed-modules:     CLI.Arguments, CLI.Arguments.Parsing, CLI.Arguments.Arr, CLI.Arguments.Get+  exposed-modules:     CLI.Arguments, CLI.Arguments.Parsing, CLI.Arguments.Arr, CLI.Arguments.Get, CLI.Arguments.Sorted   -- other-modules:   -- other-extensions:   build-depends:       base >=4.8 && <5