require 'rubygems' require 'cli/command' module Factor module CLI class ServerTask < Command desc "start", "start the server" method_option :tags, :alias=>"-t", :type=>:hash, :desc=>"Optional tags to identify from workflow" method_option :channels, :type=>:array, :desc=>"Optional channel ruby file list for development" method_option :verbose, :type=>:boolean, :desc=>"Display everything" def start engine = Factor::Runtime::Engine.new(get_config[:email],get_config[:token]) options.tags.each {|tag,value| engine.tag(tag,value)} if options.tags? # load channels from server say "loading channels from server" if options.verbose? engine = @client.load_channels(engine) do |message| say " #{message}" if options.verbose? end # load channels from files if options.channels? options.channels.each do |file| full_file=File.expand_path(file) say " loading '#{full_file}'" if options.verbose? engine.load_channel(full_file) say " loaded '#{full_file}'" if options.verbose? end end say "loading channels complete" if options.verbose? # load workflows from server say "loading workflows from server" if options.verbose? engine = @client.load_workflows(engine) do |message| say " #{message}" if options.verbose? end say "loading workflows complete" if options.verbose? say "loading credentials from server" if options.verbose? engine = @client.load_credentials(engine) do |message| say " #{message}" if options.verbose? end say "loading credentials complete" if options.verbose? say "starting the server...", :green message = engine.start if message.is_a?(Exception) say "[Unknown exception]", :red say " message:#{message}", :red say " backtrace:", :red message.backtrace.each {|line| say " #{line}", :red} else say "disconnecting...", :green end end desc "list", "list all the running servers" def list say "listing all servers" end desc "logs", "listen to incoming logs" def logs engine = Factor::Runtime::Engine.new(get_config[:email],get_config[:token]) say "Listening...", :green engine.logs do |message| say "[#{message.route}] #{JSON.pretty_generate(message.body)}" end end end end end