papa-0.7.0: src/Papa/Filepath/System/FilePath.hs
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -Wall #-}
-- | Paths ("System.FilePath"): the functions of the @filepath@ package, at
-- 'FilePath' ('Data.String.String'), for the platform's paths.
--
-- They are all total. Two names differ from @filepath@'s:
--
-- * @(\<.\>)@ is left out, because its name is lens's indexed composition,
-- which "Papa" exports: use 'addExtension' (or '-<.>' to replace the
-- extension).
-- * 'getSearchPath', which reads the environment variable @PATH@, returns its
-- failure in 'IOExcept'.
--
-- ==== __Examples__
--
-- >>> "dir" </> "file" -<.> "txt"
-- "dir/file.txt"
--
-- >>> addExtension "file" "txt"
-- "file.txt"
--
-- >>> (splitExtension "dir/file.tar.gz", splitExtensions "dir/file.tar.gz")
-- (("dir/file.tar",".gz"),("dir/file",".tar.gz"))
--
-- >>> (takeDirectory "/a/b/c", takeFileName "/a/b/c", takeBaseName "/a/b/c.d", takeExtension "/a/b/c.d")
-- ("/a/b","c","c",".d")
--
-- >>> (splitDirectories "/a/b/c", joinPath ["a", "b"], normalise "/a/./b//c")
-- (["/","a","b","c"],"a/b","/a/b/c")
--
-- >>> (isAbsolute "/a", isRelative "a", makeRelative "/a" "/a/b", stripExtension "gz" "x.gz")
-- (True,True,"b",Just "x")
--
-- The functions are total, at every 'Data.String.String':
--
-- >>> check $ property $ do { p <- forAll (Gen.string (Range.linear 0 20) (Gen.element "/.a\0 ")); length (splitPath p <> splitDirectories p <> [normalise p, takeDirectory p, takeFileName p, dropExtension p, makeValid p]) === length (splitPath p) + length (splitDirectories p) + 5 }
-- ...passed 100 tests.
-- True
--
-- @since 0.7.0
module Papa.Filepath.System.FilePath (
module P,
getSearchPath,
) where
import Papa.Base.System.IO.Except (IOExcept, exceptIO)
import System.FilePath as P hiding (getSearchPath, (<.>))
import qualified System.FilePath as F
-- $setup
-- >>> :set -XNoImplicitPrelude
-- >>> import Papa
-- >>> import Hedgehog
-- >>> import qualified Hedgehog.Gen as Gen
-- >>> import qualified Hedgehog.Range as Range
-- | The directories of the environment variable @PATH@. A @PATH@ that is not
-- set is a failure.
--
-- ==== __Examples__
--
-- >>> isRight <$> runExceptT getSearchPath
-- True
--
-- @since 0.7.0
getSearchPath :: IOExcept [FilePath]
getSearchPath =
exceptIO F.getSearchPath
{-# INLINE getSearchPath #-}