class Sv::Cli::Server

Attributes

app_dir[R]
argv[R]

Public Class Methods

new(app_dir, argv: ARGV) click to toggle source
# File lib/sv/cli/server.rb, line 9
def initialize(app_dir, argv: ARGV)
  @app_dir = app_dir
  @argv = argv
end

Public Instance Methods

run() click to toggle source
# File lib/sv/cli/server.rb, line 14
def run
  opts.parse!(argv)
  command = argv.shift.to_sym
  case command
  when :start, :restart
    server.send command, auto_start: options[:auto_start], wait: options[:wait]
  when :'print-config'
    server.send :print_config
  when :rr
    server.send :rolling_restart
  when :stop, :status, :reopen_logs, :health_check
    server.send command
  when :help
    help argv.shift
  else
    raise ::Sv::Error, "no such command #{command}"
  end
end

Private Instance Methods

help(command) click to toggle source
# File lib/sv/cli/server.rb, line 35
def help(command)
  command = command.to_sym if command
  case command
  when :start, :restart
    banner = []
    banner << "sv [global options] #{command} [options]"
    banner = banner.join("\n")
    opts.banner = banner
    puts opts
  else
    puts "no help available for command: #{command}"
  end
end
options() click to toggle source
# File lib/sv/cli/server.rb, line 65
def options
  @options ||= {}
end
opts() click to toggle source
# File lib/sv/cli/server.rb, line 53
def opts
  @opts ||= OptionParser.new do |opts| 
    opts.on("-a", "--auto-start" , "auto start jobs") do
      options[:auto_start] = true
    end 

    opts.on("-w", "--wait" , "wait for jobs to start successfully") do
      options[:wait] = true
    end
  end
end
server() click to toggle source
# File lib/sv/cli/server.rb, line 49
def server
  @server ||= ::Sv::Server.new(app_dir)
end