0
我想运行在某个目录功能的仙丹功能,所以我有这样的代码:如何传递IO到传递到另一个函数
def main(args) do
args |> directory |> File.cd!(&Cli.run/0) |> IO.puts
end
def directory([]) do
"."
end
def directory(args) do
hd(args)
end
我现在想IO传递到CLI的.run,以便我可以测试它 - 目前IO只是直接用于Cli.run。
我该如何传递它?
我不完全知道你在做什么在这里。如果你想传递一些东西(IO)到Cli.run,你需要将它添加到主'def main(args,io \\ IO)do ...'的参数中,然后加到Cli.run' fn - > Cli.run(io)end' 如果你想检查测试中的IO,有http://elixir-lang.org/docs/stable/ex_unit/ExUnit.CaptureIO.html#capture_io/1 – manukall
是,通过匿名函数'fn - > Cli.run(io)end'到'File.cd!'中工作,谢谢。 – user2355213
您应该发布正确的解决方案作为答案,以便搜索此问题的其他人可以轻松找到答案。 –