+fs = require 'fs'
+url = require 'url'
+path = require 'path'
 ssh2 = require 'ssh2'
+logmisth = require 'logsmith'
 
 # ---
 


# ---

exports.Target = class Target extends helpers.Target
	create_exec_handler: (callback, failproof_or_handler) ->
		(err, stream) ->
			return callback err if err

					return callback null if callback
					
	do_exec: (command, callback) ->
		@ssh2.exec command, (err, stream) ->
			return callback err if err
			
			shell_stream = new helpers.Stream
			
			stream.on 'data', (data, extended) ->
				switch
					when extended == 'stdout' then shell_stream.emit_data_for_stdout data
					when extended == 'stderr' then shell_stream.emit_data_for_stderr data
					else shell_stream.emit_data_for_stdout data
					
			stream.on 'error', (error) -> shell_stream.emit_error error
			stream.on 'exit', (code) -> shell_stream.emit_exit code
			
			return callback null, shell_stream if callback
			
	do_spawn: (command, args, callback) ->
		args = (args or []).map (arg) -> helpers.quote arg
		command += ' ' + args.join ' '
		
		@ssh2.exec command, (err, stream) ->
			return callback err if err
			
			shell_stream = new helpers.Stream
			
			stream.on 'data', (data, extended) ->
				switch
					when extended == 'stdout' then shell_stream.emit_data_for_stdout data
					when extended == 'stderr' then shell_stream.emit_data_for_stderr data
					else shell_stream.emit_data_for_stdout data
					
			stream.on 'error', (error) -> shell_stream.emit_error error
			stream.on 'exit', (code) -> shell_stream.emit_exit code
			
			return callback null, shell_stream if callback
			
	exec: (command, failproof_or_handler) ->
		task =
			desc: command
