Class: Padrino::Cli::Launcher

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/padrino-core/cli/launcher.rb

Direct Known Subclasses

Base

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/padrino-core/cli/launcher.rb', line 101

def self.exit_on_failure?
  true
end

Instance Method Details

#chdir(dir) ⇒ Object (protected)



90
91
92
93
94
95
96
97
98
99
# File 'lib/padrino-core/cli/launcher.rb', line 90

def chdir(dir)
  return unless dir
  begin
    Dir.chdir(dir.to_s)
  rescue Errno::ENOENT
    puts "=> Specified Padrino root '#{dir}' does not appear to exist!"
  rescue Errno::EACCES
    puts "=> Specified Padrino root '#{dir}' cannot be accessed by the current user!"
  end
end

#prepare(task) ⇒ Object (protected)



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/padrino-core/cli/launcher.rb', line 71

def prepare(task)
  if options.help?
    help(task.to_s)
    exit
  end

  if options.environment
    ENV['RACK_ENV'] = options.environment.to_s
  else
    ENV['RACK_ENV'] ||= 'development'
  end

  chdir(options.chdir)
  return if File.exist?('config/boot.rb')

  puts "=> Could not find boot file in: #{options.chdir}/config/boot.rb !!!"
  abort
end

#start(*args) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/padrino-core/cli/launcher.rb', line 25

def start(*args)
  prepare :start
  require File.expand_path('adapter', __dir__)
  require File.expand_path('config/boot.rb')

  if options[:server_options]
    puts server_options(options)
  else
    Padrino::Cli::Adapter.start(args.last ? options.merge(config: args.last).freeze : options)
  end
end

#stopObject



40
41
42
43
44
# File 'lib/padrino-core/cli/launcher.rb', line 40

def stop
  prepare :stop
  require File.expand_path('adapter', __dir__)
  Padrino::Cli::Adapter.stop(options)
end