Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/Streamly/Coreutils/Ln.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Streamly.Coreutils.Ln
( ln

-- * Options
, Ln
, LnOptions
, force
, symbolic
)
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/Streamly/Coreutils/Ls.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Streamly.Coreutils.Ls
ls

-- * Options
, Ls
, LsOptions
, recursive
)
where
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/Streamly/Coreutils/Mv.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Streamly.Coreutils.Mv
mv

-- * Options
, Mv
, MvOptions
, force
)
where
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/Streamly/Coreutils/Stat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Streamly.Coreutils.Stat
stat

-- * Options
, Stat
, StatOptions
, followLinks
) where

Expand All @@ -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
Expand Down
20 changes: 10 additions & 10 deletions src/Streamly/Coreutils/Tail.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Streamly.Coreutils.Tail
tail

-- * Options
, Tail
, TailOptions
, follow
, lines
, bytes
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions src/Streamly/Coreutils/Touch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading