Using a command line parser
gives a string containing a filename argument, which in this case is "../somedir". How to convert this string into a typesafe Path Rel Dir
from Path
to combine later with the current directory?
relDir1 <- parseRelDir fp
throws an error (as indicated in the description, because it "contains a .. path component representing the parent directory")
Trying to combine the currentDir with the String from the command line first, as in
relDir2 <- parseRelDir (currDir </> fp)
returns the same error.
I found a "hack", using collapse
from FileSystem.Path, which requires an decodeString
and a encodeString
to convert from String (aka FilePath) to the special FilePath
used:
combPath = toFilePath currDir </> (locationDir $ flags) :: FilePath
collPath = collapse . decodeString $ combPath
absdir = makeAbsDir . encodeString $ collPath :: Path Abs Dir
but assume there is somewhere a better approach to this common task?