Sha256: f57f450751bf0b0fa74ed953c320e612a52f472cdc335a55380803312c25e81f
Contents?: true
Size: 1.11 KB
Versions: 5
Compression:
Stored size: 1.11 KB
Contents
class CommandInterfaceHandler def run_command(cld, command, args) cr = CloudThrift::CloudResponse.new cr.name = cld.name cr.command = command resp = begin the_cloud = clouds[cld.name] if the_cloud if command.include?(".") command.split(".").inject(the_cloud) do |curr_cloud, cmd| if cmd.match(/\((.*)\)/) args = $1 new_cmd = cmd.gsub(args, '').gsub(/\(\)/, '') curr_cloud = curr_cloud.send(new_cmd.to_sym, *args) else curr_cloud = curr_cloud.send(cmd) end end else the_cloud.send(command.to_sym, *args) end else "Cloud not found: #{cld.name}" end rescue Exception => e cr.response = "Error: #{e.inspect}" end cr.response = format_response(resp) return cr end private def format_response(resp) case resp when Array resp.join(",") when Hash resp.map {|k,v| "#{k}:#{format_response(v.empty? ? "null" : v)}" } else [resp] end.map {|ele| ele.to_s } end end
Version data entries
5 entries across 5 versions & 2 rubygems