是否可以调试 Turtle 脚本(相当于 bash 中的“-x”标志)?

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

我最近开始使用 Haskell Turtle 库来替换我的一些 shell 脚本。

有没有办法以某种方式在 bash 脚本中启用内置 Turtle 命令(如 cd)ala set -x 的回显?我发现在执行许多命令并且其中一个命令因异常而失败的情况下调试 Turtle 脚本非常有问题(例如 cp 命令和 Exception:openBinaryFile: does not exist)。或者,对于如何快速隔离此类问题,您是否有一些建议,这样我就不必在整个脚本中穿插 puStrLn/echo 命令?

遗憾的是,这是不可能的,因为 turtle 不提供跟踪。例如,mv 仅使用 Haskell 函数定义(没有 shell 调用),因此当 运行:

时无法打印任何内容
mv :: MonadIO io => FilePath -> FilePath -> io ()
mv oldPath newPath = liftIO (Filesystem.rename oldPath newPath)

文档中提到了这个限制,作者建议看一下Shelly,它类似但提供了额外的功能:

turtle is designed to be beginner-friendly, but as a result lacks certain features, like tracing commands. If you feel comfortable using turtle then you should also check out the Shelly library which provides similar functionality.