Sha256: a479a5269ddb86d5e06f63139ffe7c9c31c5afea27cdda99f2d56cd61babb29c

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

require 'thread'
require 'mixlib/cli'
require 'daemons/daemonize'
require 'spanx/logger'
require 'spanx/api/machine'

class Spanx::CLI::Api < Spanx::CLI

  banner 'Usage: spanx api [options]'
  description 'Start HTTP server for controlling Spanx (experimental)'

  option :daemonize,
         :short => '-d',
         :long => '--daemonize',
         :boolean => true,
         :default => false

  option :config_file,
         :short => '-c CONFIG',
         :long => '--config CONFIG',
         :description => 'Path to config file (YML)',
         :required => true

  option :debug,
         :short => '-g',
         :long => '--debug',
         :description => 'Log status to STDOUT',
         :boolean => true,
         :required => false,
         :default => false

  option :host,
         :short => '-h HOST',
         :long  => '--host HOST',
         :description => 'Host for the api to listen on.',
         :default => '127.0.0.1',
         :required => false

  option :port,
         :short => '-p PORT',
         :long  => '--port PORT',
         :description => "Port for the api to listen on.",
         :default => 6060,
         :required => false

  option :help,
         :short => "-h",
         :long => "--help",
         :description => "Show this message",
         :on => :tail,
         :boolean => true,
         :show_options => true,
         :exit => 0

  def run(argv = ARGV)
    generate_config(argv)

    puts "Starting Spanx API on #{config[:host]}:#{config[:port]}.."

    Daemonize.daemonize if config[:daemonize]

    Spanx::API::Machine.configure do |c|
      c.port = config[:port]
      c.ip = config[:host]
    end

    Spanx::API::Machine.run
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spanx-0.3.0 lib/spanx/cli/api.rb