class Sanford::CLI
Public Class Methods
new(kernel = nil)
click to toggle source
# File lib/sanford/cli.rb, line 15 def initialize(kernel = nil) @kernel = kernel || Kernel @cli = CLIRB.new end
run(args)
click to toggle source
# File lib/sanford/cli.rb, line 11 def self.run(args) self.new.run(*args) end
Public Instance Methods
run(*args)
click to toggle source
# File lib/sanford/cli.rb, line 20 def run(*args) begin run!(*args) rescue CLIRB::HelpExit @kernel.puts help rescue CLIRB::VersionExit @kernel.puts Sanford::VERSION rescue CLIRB::Error, Sanford::ConfigFile::InvalidError => exception @kernel.puts "#{exception.message}\n\n" @kernel.puts help @kernel.exit 1 rescue StandardError => exception @kernel.puts "#{exception.class}: #{exception.message}" @kernel.puts exception.backtrace.join("\n") @kernel.exit 1 end @kernel.exit 0 end
Private Instance Methods
help()
click to toggle source
# File lib/sanford/cli.rb, line 61 def help "Usage: sanford [CONFIG_FILE] [COMMAND] [options]\n\n" \ "Commands: run, start, stop, restart\n" \ "Options: #{@cli}" end
run!(*args)
click to toggle source
# File lib/sanford/cli.rb, line 41 def run!(*args) @cli.parse!(args) config_file_path, command = @cli.args config_file_path ||= 'config.sanford' command ||= 'run' server = Sanford::ConfigFile.new(config_file_path).server case(command) when 'run' Sanford::Process.new(server, :daemonize => false).run when 'start' Sanford::Process.new(server, :daemonize => true).run when 'stop' Sanford::ProcessSignal.new(server, 'TERM').send when 'restart' Sanford::ProcessSignal.new(server, 'USR2').send else raise CLIRB::Error, "#{command.inspect} is not a valid command" end end