Is it possible to debug Turtle scripts (the equivalent of the -x flag in bash)?

I recently started using the Haskell Turtle library to replace some of my shell scripts.

Is there a way to somehow enable the echo from Turtle's built-in commands (like cd) ala set -x in a bash script? I find it quite problematic to debug Turtle scripts in cases where many commands are executed and one of them fails (for example, the cp command with Exception:openBinaryFile: does not exist ). Alternatively, do you have a recommendation on how to quickly isolate such problems, so I don’t need to interleave the puStrLn/echo throughout my script?

+8
haskell haskell-turtle
source share
1 answer

Unfortunately, this is not possible because the turtle does not provide tracking. For example, mv is only defined using the Haskell function (without calling the shell), so there is no way to print anything at startup:

 mv :: MonadIO io => FilePath -> FilePath -> io () mv oldPath newPath = liftIO (Filesystem.rename oldPath newPath) 

This limitation is mentioned in the documentation, where the author recommends a look at Shelly , which seems to be, but provides additional features:

The tortoise is intended for beginners, but as a result of this, some features, such as trace commands, are missing. If you are comfortable using turtles, then you should also check out the Shelley library, which provides similar functionality.

+5
source share

All Articles