2015-11-25 47 views
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。

我该如何传递它?

+0

我不完全知道你在做什么在这里。如果你想传递一些东西(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

+0

是,通过匿名函数'fn - > Cli.run(io)end'到'File.cd!'中工作,谢谢。 – user2355213

+0

您应该发布正确的解决方案作为答案,以便搜索此问题的其他人可以轻松找到答案。 –

回答

1

由于manukall,该解决方案是一个匿名函数传递给File.cd!这样的:

File.cd!(fn -> Openreevoo.Cli.run(IO) end)