packages feed

cli-arguments (empty) → 0.1.0.0

raw patch · 5 files changed

+142/−0 lines, 5 filesdep +basesetup-changed

Dependencies added: base

Files

+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# Revision history for cli-arguments++## 0.1.0.0 -- 2021-12-27++* First version. Released on an unsuspecting world.
+ CLI/Arguments.hs view
@@ -0,0 +1,89 @@+{-# OPTIONS_HADDOCK show-extensions #-}++-- |+-- Module      :  CLI.Arguments+-- Copyright   :  (c) OleksandrZhabenko 2021+-- License     :  MIT+-- Stability   :  Experimental+-- Maintainer  :  olexandr543@yahoo.com+--+-- A library to process command line arguments in some more convenient way.++module CLI.Arguments where++import Data.Monoid (mappend)++data Arguments =+  A String+  | B Int String [String]+  | C String [String]+      deriving Eq++type Args = [Arguments]++type Specification = (Delimiter,GQtyArgs)++type CLSpecifications = [Specification]++type Delimiter = String++type GQtyArgs = Int++instance Show Arguments where+  show (A xs) = xs+  show (B n ys yss) = ' ':ys `mappend` concatMap (\xs ->' ':show xs) (take n yss)+  show (C xs xss) = ' ':xs `mappend` concatMap (\ys ->' ':show ys) xss `mappend` (' ':xs)++isA :: Arguments -> Bool+isA (A _) = True+isA _ = False++isB :: Arguments -> Bool+isB (B _ _ _) = True+isB _ = False++isC :: Arguments -> Bool+isC (C _ _) = True+isC _ = False++nullArguments :: Arguments -> Bool+nullArguments (A xs) = null xs+nullArguments (B n ys yss) = n /= length yss || null ys  || null yss+nullArguments (C xs xss) = null xs || null xss++notNullArguments :: Arguments -> Bool+notNullArguments (A (_:_)) =  True+notNullArguments (A _) = False+notNullArguments (B n (_:_) yss@(_:_:_)) = n == length yss+notNullArguments (B _ _ _) = False+notNullArguments (C (_:_) (_:_)) = True+notNullArguments _ = False++b1Args2AArgs :: Arguments -> Arguments+b1Args2AArgs b@(B n _ [ys])+ | n >= 1 = A ys+ | otherwise = b+b1Args2AArgs x = x++args2Args+  :: CLSpecifications+  -> [String]+  ->  Args+args2Args (t@(xs,n):ts) xss@(js:jss)+  | n < 1 = (C xs qss): args2Args ts (kss `mappend` rss)+  | n > 1 = (B n xs vss):args2Args ts (kss `mappend` zss)+  | otherwise = (A js):args2Args ts jss+      where (kss,uss) = break (== xs) xss+            wss = drop 1 uss+            (qss,pss) = break (== xs) wss+            rss = drop 1 pss+            (vss,zss) = splitAt n wss++-- | 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.+args2ArgsFiltered+  :: CLSpecifications+  -> [String]+  -> Args+args2ArgsFiltered ts = filter notNullArguments . map b1Args2AArgs . args2Args ts+{-# INLINE args2ArgsFiltered #-}
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2021 OleksandrZhabenko++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ cli-arguments.cabal view
@@ -0,0 +1,26 @@+cabal-version:       >=1.10+-- Initial package description 'cli-arguments.cabal' generated by 'cabal+-- init'.  For further documentation, see+-- http://haskell.org/cabal/users-guide/++name:                cli-arguments+version:             0.1.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 so that firstly the framed by some string delimiter is parsed, then the groups of arguments and then the rest single-field arguments.+-- bug-reports:+license:             MIT+license-file:        LICENSE+author:              OleksandrZhabenko+maintainer:          olexandr543@yahoo.com+copyright:           Oleksandr Zhabenko+category:            CLI+build-type:          Simple+extra-source-files:  CHANGELOG.md++library+  exposed-modules:     CLI.Arguments+  -- other-modules:+  -- other-extensions:+  build-depends:       base >=4.7 && <5+  -- hs-source-dirs:+  default-language:    Haskell2010