class Invoker::CLI

Public Class Methods

start(*args) click to toggle source
Calls superclass method
# File lib/invoker/cli.rb, line 6
def self.start(*args)
  cli_args = args.flatten
  # If it is not a valid task, it is probably file argument
  if default_start_command?(cli_args)
    args = [cli_args.unshift("start")]
  end
  super(*args)
end

Private Class Methods

default_start_command?(args) click to toggle source
# File lib/invoker/cli.rb, line 100
def self.default_start_command?(args)
  command_name = args.first
  command_name &&
    !command_name.match(/^-/) &&
    !valid_tasks.include?(command_name)
end
valid_tasks() click to toggle source
# File lib/invoker/cli.rb, line 107
def self.valid_tasks
  tasks.keys + ["help"]
end

Public Instance Methods

add(name) click to toggle source
# File lib/invoker/cli.rb, line 53
def add(name)
  unix_socket.send_command('add', process_name: name)
end
add_http(name, port, ip = nil) click to toggle source
# File lib/invoker/cli.rb, line 58
def add_http(name, port, ip = nil)
  unix_socket.send_command('add_http', process_name: name, port: port, ip: ip)
end
list() click to toggle source
# File lib/invoker/cli.rb, line 78
def list
  unix_socket.send_command('list') do |response_object|
    Invoker::ProcessPrinter.new(response_object).tap { |printer| printer.print_table }
  end
end
reload(name) click to toggle source
# File lib/invoker/cli.rb, line 72
def reload(name)
  signal = options[:signal] || 'INT'
  unix_socket.send_command('reload', process_name: name, signal: signal)
end
remove(name) click to toggle source
# File lib/invoker/cli.rb, line 88
def remove(name)
  signal = options[:signal] || 'INT'
  unix_socket.send_command('remove', process_name: name, signal: signal)
end
setup() click to toggle source
# File lib/invoker/cli.rb, line 19
def setup
  Invoker::Power::Setup.install(get_tld(options))
end
start(file = nil) click to toggle source
# File lib/invoker/cli.rb, line 40
def start(file = nil)
  Invoker.setup_config_location
  port = options[:port] || 9000
  Invoker.daemonize = options[:daemon]
  Invoker.load_invoker_config(file, port)
  warn_about_notification
  warn_about_old_configuration
  pinger = Invoker::CLI::Pinger.new(unix_socket)
  abort("Invoker is already running".color(:red)) if pinger.invoker_running?
  Invoker.commander.start_manager
end
stop() click to toggle source
# File lib/invoker/cli.rb, line 94
def stop
  Invoker.daemon.stop
end
tail(*names) click to toggle source
# File lib/invoker/cli.rb, line 63
def tail(*names)
  tailer = Invoker::CLI::Tail.new(names)
  tailer.run
end
uninstall() click to toggle source
# File lib/invoker/cli.rb, line 30
def uninstall
  Invoker::Power::Setup.uninstall
end
version() click to toggle source
# File lib/invoker/cli.rb, line 24
def version
  Invoker::Logger.puts Invoker::VERSION
end

Private Instance Methods

get_tld(options) click to toggle source
# File lib/invoker/cli.rb, line 111
def get_tld(options)
  if options[:tld] && !options[:tld].empty?
    options[:tld]
  else
    'dev'
  end
end
unix_socket() click to toggle source
# File lib/invoker/cli.rb, line 119
def unix_socket
  Invoker::IPC::UnixClient.new
end
warn_about_libnotify() click to toggle source
# File lib/invoker/cli.rb, line 131
def warn_about_libnotify
  require "libnotify"
rescue LoadError
  Invoker::Logger.puts "You can install libnotify gem for Invoker notifications "\
    "via system tray".color(:red)
end
warn_about_notification() click to toggle source
# File lib/invoker/cli.rb, line 123
def warn_about_notification
  if Invoker.darwin?
    warn_about_terminal_notifier
  else
    warn_about_libnotify
  end
end
warn_about_old_configuration() click to toggle source
# File lib/invoker/cli.rb, line 148
def warn_about_old_configuration
  Invoker::Power::PfMigrate.new.tap do |pf_migrator|
    pf_migrator.migrate
  end
end
warn_about_terminal_notifier() click to toggle source
# File lib/invoker/cli.rb, line 138
def warn_about_terminal_notifier
  if Invoker.darwin?
    command_path = `which terminal-notifier`
    if !command_path || command_path.empty?
      Invoker::Logger.puts "You can enable OSX notification for processes "\
        "by installing terminal-notifier gem".color(:red)
    end
  end
end