Sha256: b61d7f729479627ce47757cda794dc5e043ffa549b581f04d0969a1e69186f2e

Contents?: true

Size: 830 Bytes

Versions: 1

Compression:

Stored size: 830 Bytes

Contents

require 'rainbow'
require 'sshkit'
require 'gaptool_client/api'

module Gaptool
  class InteractionHandler
    attr_reader :host
    def initialize(host)
      @host = host
    end

    def on_data(_command, stream_name, data, _channel)
      case stream_name
      when :stdout
        puts "#{Rainbow("#{@host}").yellow}> #{data}"
      when :stderr
        STDERR.puts "#{Rainbow("#{@host}").red}> #{data}"
      end
    end
  end

  class Host < SSHKit::Host
    attr_reader :info

    def initialize(node)
      super(node['hostname'])
      @info = node
    end

    def method_missing(attr, *args, &_block)
      @info[attr] || super
    end

    def [](attr)
      @info[attr]
    end

    def name
      @name ||= Gaptool::API.get_host(@info)
    end

    def handler
      InteractionHandler.new(name)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gaptool-client-0.8.0.pre.alpha7 lib/gaptool_client/host.rb