diff --git a/src/Streamly/Coreutils/Ln.hs b/src/Streamly/Coreutils/Ln.hs index d1d87e4..d29a462 100644 --- a/src/Streamly/Coreutils/Ln.hs +++ b/src/Streamly/Coreutils/Ln.hs @@ -12,7 +12,7 @@ module Streamly.Coreutils.Ln ( ln -- * Options - , Ln + , LnOptions , force , symbolic ) @@ -25,21 +25,21 @@ import qualified System.PosixCompat.Files as Posix import Streamly.FileSystem.Path (Path) import qualified Streamly.FileSystem.Path as Path -data Ln = Ln +data LnOptions = LnOptions { lnForce :: Bool , lnSymbolic :: Bool } -defaultConfig :: Ln -defaultConfig = Ln False False +defaultConfig :: LnOptions +defaultConfig = LnOptions False False -force :: Bool -> Ln -> Ln +force :: Bool -> LnOptions -> LnOptions force opt cfg = cfg {lnForce = opt} -symbolic :: Bool -> Ln -> Ln +symbolic :: Bool -> LnOptions -> LnOptions symbolic opt cfg = cfg {lnSymbolic = opt} -ln :: (Ln -> Ln) -> Path -> Path -> IO () +ln :: (LnOptions -> LnOptions) -> Path -> Path -> IO () ln f src tgt = do let opt = f defaultConfig when (lnForce opt == False) $ do diff --git a/src/Streamly/Coreutils/Ls.hs b/src/Streamly/Coreutils/Ls.hs index 013ed16..5275858 100644 --- a/src/Streamly/Coreutils/Ls.hs +++ b/src/Streamly/Coreutils/Ls.hs @@ -13,7 +13,7 @@ module Streamly.Coreutils.Ls ls -- * Options - , Ls + , LsOptions , recursive ) where @@ -33,15 +33,15 @@ import qualified Streamly.Internal.FileSystem.DirIO as Dir -- with newlines and short or long info in this API which are directly -- printable. In the "find" API we can return Path and structured Stat data -- instead for programmatic control. -newtype Ls = Ls {lsRecursive :: Bool} +newtype LsOptions = LsOptions {lsRecursive :: Bool} -defaultConfig :: Ls -defaultConfig = Ls False +defaultConfig :: LsOptions +defaultConfig = LsOptions False -recursive :: Bool -> Ls -> Ls +recursive :: Bool -> LsOptions -> LsOptions recursive opt cfg = cfg {lsRecursive = opt} -ls :: (Ls -> Ls) -> Path -> Stream IO (Either Path Path) +ls :: (LsOptions -> LsOptions) -> Path -> Stream IO (Either Path Path) ls f dir = do case lsRecursive (f defaultConfig) of False -> Dir.readEitherPaths id dir diff --git a/src/Streamly/Coreutils/Mv.hs b/src/Streamly/Coreutils/Mv.hs index f5f2140..7b3166f 100644 --- a/src/Streamly/Coreutils/Mv.hs +++ b/src/Streamly/Coreutils/Mv.hs @@ -13,7 +13,7 @@ module Streamly.Coreutils.Mv mv -- * Options - , Mv + , MvOptions , force ) where @@ -23,15 +23,15 @@ import System.Directory (doesPathExist, renamePath) import Streamly.FileSystem.Path (Path) import qualified Streamly.FileSystem.Path as Path -newtype Mv = Mv {mvForce :: Bool} +newtype MvOptions = MvOptions {mvForce :: Bool} -defaultConfig :: Mv -defaultConfig = Mv False +defaultConfig :: MvOptions +defaultConfig = MvOptions False -force :: Bool -> Mv -> Mv +force :: Bool -> MvOptions -> MvOptions force opt cfg = cfg {mvForce = opt} -mv :: (Mv -> Mv) -> Path -> Path -> IO () +mv :: (MvOptions -> MvOptions) -> Path -> Path -> IO () mv f old new = do let opt = f defaultConfig oldStr = Path.toString old diff --git a/src/Streamly/Coreutils/Stat.hs b/src/Streamly/Coreutils/Stat.hs index dacbe51..338f4b5 100644 --- a/src/Streamly/Coreutils/Stat.hs +++ b/src/Streamly/Coreutils/Stat.hs @@ -16,7 +16,7 @@ module Streamly.Coreutils.Stat stat -- * Options - , Stat + , StatOptions , followLinks ) where @@ -27,15 +27,15 @@ import Streamly.FileSystem.Path (Path) import qualified Streamly.FileSystem.Path as Path import qualified System.PosixCompat.Files as Files -newtype Stat = Stat {deRef :: Bool} +newtype StatOptions = StatOptions {deRef :: Bool} -defaultConfig :: Stat -defaultConfig = Stat True +defaultConfig :: StatOptions +defaultConfig = StatOptions True -followLinks :: Bool -> Stat -> Stat +followLinks :: Bool -> StatOptions -> StatOptions followLinks opt cfg = cfg {deRef = opt} -stat :: (Stat -> Stat) -> Path -> IO FileStatus +stat :: (StatOptions -> StatOptions) -> Path -> IO FileStatus stat f path = do let opt = f defaultConfig case deRef opt of diff --git a/src/Streamly/Coreutils/Tail.hs b/src/Streamly/Coreutils/Tail.hs index e0dd665..c9c7438 100644 --- a/src/Streamly/Coreutils/Tail.hs +++ b/src/Streamly/Coreutils/Tail.hs @@ -17,7 +17,7 @@ module Streamly.Coreutils.Tail tail -- * Options - , Tail + , TailOptions , follow , lines , bytes @@ -38,14 +38,14 @@ import qualified Streamly.System.Command as Command import Prelude hiding (tail, lines) -data Tail = Tail +data TailOptions = TailOptions { _follow :: Bool , _offset :: Either Int Int -- Left = lines, Right = bytes , _reverse :: Bool } -defaultConfig :: Tail -defaultConfig = Tail +defaultConfig :: TailOptions +defaultConfig = TailOptions { _follow = False , _offset = Left 10 , _reverse = False -- False means default i.e. from the end @@ -54,7 +54,7 @@ defaultConfig = Tail -- | Run forever following any appends to the file. -- -- Same as @--follow@ flag in the standard tail command. -follow :: Bool -> Tail -> Tail +follow :: Bool -> TailOptions -> TailOptions follow opt cfg = cfg {_follow = opt} -- Note we could have used negative offset to indicate from the end and @@ -63,20 +63,20 @@ follow opt cfg = cfg {_follow = opt} -- | Read the specified number of lines at the end of the file. -- -lines :: Int -> Tail -> Tail +lines :: Int -> TailOptions -> TailOptions lines x cfg = cfg {_offset = Left x, _reverse = False} -- | Read the specified number of bytes at the end of the file. -- -bytes :: Int -> Tail -> Tail +bytes :: Int -> TailOptions -> TailOptions bytes x cfg = cfg {_offset = Right x, _reverse = False} -- | Read from the specified line number up to the end of file. -fromLine :: Int -> Tail -> Tail +fromLine :: Int -> TailOptions -> TailOptions fromLine x cfg = cfg {_offset = Left x, _reverse = True} -- | Read from the specified byte count up to the end of file. -fromByte :: Int -> Tail -> Tail +fromByte :: Int -> TailOptions -> TailOptions fromByte x cfg = cfg {_offset = Right x, _reverse = True} -- XXX Replace the "tail" shell command with Haskell native implementation. A @@ -92,7 +92,7 @@ fromByte x cfg = cfg {_offset = Right x, _reverse = True} -- -- Note: currently this function depends on the @tail@ executable being -- installed in the PATH. -tail :: (Tail -> Tail) -> Path -> Stream IO (Array Word8) +tail :: (TailOptions -> TailOptions) -> Path -> Stream IO (Array Word8) tail modifier path = let p = Path.toString path cfg = modifier defaultConfig diff --git a/src/Streamly/Coreutils/Touch.hs b/src/Streamly/Coreutils/Touch.hs index 93649d9..7bcf3fd 100644 --- a/src/Streamly/Coreutils/Touch.hs +++ b/src/Streamly/Coreutils/Touch.hs @@ -13,7 +13,7 @@ module Streamly.Coreutils.Touch touch -- * Options - , Touch + , TouchOptions , create -- XXX rename for conflicts , followLinks -- XXX this is a common option in multiple commands ) @@ -30,21 +30,21 @@ import qualified System.Posix.Files as Posix (touchSymbolicLink) #endif import qualified System.PosixCompat.Files as Posix -data Touch = Touch +data TouchOptions = TouchOptions { createNew :: Bool , deRef :: Bool -- touch the referenced file for symbolic link } -defaultConfig :: Touch -defaultConfig = Touch True True +defaultConfig :: TouchOptions +defaultConfig = TouchOptions True True -- | Default is 'True'. -followLinks :: Bool -> Touch -> Touch +followLinks :: Bool -> TouchOptions -> TouchOptions followLinks opt cfg = cfg {deRef = opt} -- | Default is 'True'. -create :: Bool -> Touch -> Touch +create :: Bool -> TouchOptions -> TouchOptions create opt cfg = cfg {createNew = opt} -- | If the file does not exist create it only if both followLinks and create @@ -62,7 +62,7 @@ create opt cfg = cfg {createNew = opt} -- * create True -- * followLinks True -- -touch :: (Touch -> Touch) -> Path -> IO () +touch :: (TouchOptions -> TouchOptions) -> Path -> IO () touch f path = do let opt = f defaultConfig pathStr = Path.toString path