Sha256: 5d9e0fa2a9bce7fe75e124f889b82c0024f7e95b53ba453de5a54806c355ba97
Contents?: true
Size: 1.83 KB
Versions: 3
Compression:
Stored size: 1.83 KB
Contents
module ChainReactor lib_dir = File.dirname(__FILE__) $:.unshift lib_dir require 'version' require 'rubygems' require 'main' Main do input :data do optional end option :address do argument_required required cast :string description 'Chain reactor server address' end option :port do argument_required required cast :int description 'Chain reactor server port number' defaults 1987 end # Connect to a running chain reactor server and send data. def run require 'client' begin client = Client.new params[:address].value, params[:port].value puts "Connected to Chain Reactor server, version #{client.version}" data_input = params[:data].value if data_input client.send(data_input.gets.strip) else client.send_as_json(get_hash_from_stdin) client.close() end exit_status exit_success rescue ClientError => e STDERR.puts e.message exit_status exit_failure rescue SystemExit, Interrupt STDERR.puts "Caught exit signal" exit_status exit_failure rescue Exception => e STDERR.puts "An error occured {#{e.class.name}}: #{e.message}" exit_status exit_failure end end # Ask the user for key value pairs, and return as a hash. def get_hash_from_stdin STDOUT.sync = true hash_to_send = {} puts "No data supplied, what do you want to send? (Leave key blank to end)" incr = 1 loop do print "Key ##{incr}: " key = STDIN.gets.chomp if key == "" break end print "Value ##{incr}: " value = STDIN.gets.chomp hash_to_send[key] = value incr += 1 end hash_to_send end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
chain-reactor-0.2.2 | lib/chain-reactor/chain_reactor_client.rb |
chain-reactor-0.2.1 | lib/chain-reactor/chain_reactor_client.rb |
chain-reactor-0.2.0 | lib/chain-reactor/chain_reactor_client.rb |