@@ -46,12 +46,16 @@ defmodule SSHKit do
4646 # TODO: Separate options for open/exec/recv
4747 Stream . resource (
4848 fn ->
49- { :ok , chan } = Channel . open ( conn , options ) # TODO: handle {:error, reason} and raise custom error struct?
50- :success = Channel . exec ( chan , command ) # TODO: timeout?, TODO: Handle :failure and {:error, reason} and raise custom error struct?
49+ # TODO: handle {:error, reason} and raise custom error struct?
50+ { :ok , chan } = Channel . open ( conn , options )
51+
52+ # TODO: timeout?, TODO: Handle :failure and {:error, reason} and raise custom error struct?
53+ :success = Channel . exec ( chan , command )
5154 chan
5255 end ,
5356 fn chan ->
54- { :ok , msg } = Channel . recv ( chan ) # TODO: timeout?, TODO: handle {:error, reason} and raise custom error struct?
57+ # TODO: timeout?, TODO: handle {:error, reason} and raise custom error struct?
58+ { :ok , msg } = Channel . recv ( chan )
5559
5660 # TODO: Adjust channel window size?
5761
@@ -115,16 +119,18 @@ defmodule SSHKit do
115119 def run! ( conn , command , options \\ [ ] ) do
116120 stream = exec! ( conn , command , options )
117121
118- { status , output } = Enum . reduce ( stream , { nil , [ ] } , fn
119- { :stdout , _ , data } , { status , output } -> { status , [ { :stdout , data } | output ] }
120- { :stderr , _ , data } , { status , output } -> { status , [ { :stderr , data } | output ] }
121- { :exit , _ , status } , { _ , output } -> { status , output }
122- _ , acc -> acc
123- end )
122+ { status , output } =
123+ Enum . reduce ( stream , { nil , [ ] } , fn
124+ { :stdout , _ , data } , { status , output } -> { status , [ { :stdout , data } | output ] }
125+ { :stderr , _ , data } , { status , output } -> { status , [ { :stderr , data } | output ] }
126+ { :exit , _ , status } , { _ , output } -> { status , output }
127+ _ , acc -> acc
128+ end )
124129
125130 output = Enum . reverse ( output )
126131
127- if status != 0 , do: raise "Non-zero exit code: #{ status } " # TODO: Proper file struct?
132+ # TODO: Proper file struct?
133+ if status != 0 , do: raise ( "Non-zero exit code: #{ status } " )
128134
129135 output
130136 end
0 commit comments