module TeutonClient

This module main methods to run Teuton Client

Public Class Methods

init() click to toggle source

Create default configuration file 'teuton-client.yaml'. @return [Exit status]

# File lib/teuton-client.rb, line 46
def self.init
  src = File.join(File.dirname(__FILE__), 'teuton-client', 'files',
        Application::CONFIGFILE)
  dest = File.join(Application::CONFIGFILE)
  if File.exists? dest
    puts "teuton-client => " + Rainbow("File \'#{dest}\' exists!").red
    exit 1
  end
  FileUtils.cp(src, dest)
  puts "teuton-client => " + Rainbow("Init \'#{dest}\' done!").yellow
  exit 0
end
run(args) click to toggle source

Run Teuton Client @param args [Array] Input arguments @return [Exit status]

# File lib/teuton-client.rb, line 14
def self.run(args)
  hostname, port = InputLoader.read_configuration(args)
  connect_to_server(hostname, port)
  exit 0
end
show_help() click to toggle source

Show TeutonClient help. @return [Exit status]

# File lib/teuton-client.rb, line 23
def self.show_help
  puts "Usage:"
  puts "    teuton-client [help|version] [IP PORT]"
  puts "Params:"
  puts "    help    , Show this help"
  puts "    init    , Create \'#{Application::CONFIGFILE}\' config file"
  puts "    IP PORT , Teuton server IP and/or PORT"
  puts "    version , Show current version"
  exit 0
end
show_version() click to toggle source

Show TeutonClient version @return [Exit status]

# File lib/teuton-client.rb, line 37
def self.show_version
  puts "teuton-client => " +
       Rainbow("version #{Application::VERSION}").cyan
  exit 0
end

Private Class Methods

connect_to_server(hostname='localhost', port=16000) click to toggle source

Connect client to server and display server response. @param hostname [String] Server hostname or IP @param port [Integer] Server listening port

# File lib/teuton-client.rb, line 63
                     def self.connect_to_server(hostname='localhost', port=16000)
  puts Rainbow("teuton-client => Waiting...   " +
               "#{hostname}:#{port} (teuton-server)").bright
  begin
    s = TCPSocket.open(hostname, port)
  rescue
    puts Rainbow("teuton-client => " +
                 "ERROR        teuton-server not found!" +
                 " [#{hostname}:#{port}]").bright.red
    exit 1
  end
  while line = s.gets    # Read lines from the socket
    puts "              => #{line.chop}"
  end
  s.close                # Close the socket when done
end