Class: Halcyon::Runner::Commands

Inherits:
Object
  • Object
show all
Defined in:
lib/halcyon/runner/commands.rb

Class Method Summary collapse

Class Method Details

.console(argv) ⇒ Object Also known as: interactive, irb, -i

Start the Halcyon server up in interactive mode



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/halcyon/runner/commands.rb', line 46

def console(argv)
  # Notify user of environment
  puts "(Starting Halcyon app in console...)"
  
  # Add ./lib to load path
  $:.unshift(Halcyon.root/'lib')
  
  # prepare environment for IRB
  ARGV.clear
  require 'rack/mock'
  require 'logger'
  require 'irb'
  require 'irb/completion'
  if File.exists? '.irbrc'
    ENV['IRBRC'] = '.irbrc'
  end
  
  # Set up the application
  Object.instance_eval do
    $log = ''
    $app = Halcyon::Runner.new do |c|
      c[:logger] = Logger.new(StringIO.new($log))
    end
    $response = nil
  end
  
  # Setup helper methods
  Object.send(:include, Halcyon::Runner::Helpers::CommandHelper)
  
  # Let users know what methods and values are available
  puts "Call #usage for usage details."
  
  # Start IRB session
  IRB.start
  
  exit
end

.init(argv) ⇒ Object

Generate a new Halcyon application



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/halcyon/runner/commands.rb', line 88

def init(argv)
  app_name = argv.last
  
  options = {
    :generator => 'halcyon',
    :git => false
  }
  
  OptionParser.new do |opts|
    opts.banner = "Usage: halcyon init [options]"
    
    opts.separator ""
    opts.separator "Generator options:"
    opts.on("-f", "--flat", "") { options[:generator] = 'halcyon_flat' }
    
    opts.separator ""
    opts.separator "Additional options:"
    opts.on("-g", "--git", "Initialize a Git repository when finished generating") { options[:git] = true }
    opts.on("-G", "--git-commit", "Initialize a Git repo and commit") { options[:git] = options[:git_commit] = true }
    
    begin
      opts.parse! argv
    rescue OptionParser::InvalidOption => e
      # the other options can be used elsewhere, like in RubiGen
    end
  end
  
  require 'rubigen'
  require 'rubigen/scripts/generate'
  RubiGen::Base.use_application_sources!
  RubiGen::Base.sources << RubiGen::PathSource.new(:custom, File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', "support/generators")))
  RubiGen::Scripts::Generate.new.run(argv, :generator => options[:generator])
  
  # Create a Git repository in the new app dir
  if options[:git]
    system("cd #{app_name} && git init -q && cd #{Dir.pwd}")
    puts "Initialized Git repository in #{app_name}/"
    File.open(File.join("#{app_name}",'.gitignore'),"w") {|f| f << "log/*.log" }
    File.open(File.join("#{app_name}",'log','.gitignore'),"w") {|f| f << "" }
  end
  
  # commit to the git repo
  if options[:git_commit]
    system("cd #{app_name} && git add . && git commit -m 'Initial import.' -q && cd #{Dir.pwd}")
    puts "Committed empty application in #{app_name}/"
    puts "Run `git commit --amend` to change the commit message."
  end
end

.start(argv) ⇒ Object

Run the Halcyon application



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/halcyon/runner/commands.rb', line 12

def start(argv)
  options = {
    :port => 4647,
    :server => (Gem.searcher.find('thin').nil? ? 'mongrel' : 'thin')
  }
  
  OptionParser.new do |opts|
    opts.banner = "Usage: halcyon start [options]"
    
    opts.separator ""
    opts.separator "Start options:"
    opts.on("-s", "--server SERVER", "") { |server| options[:server] = server }
    
    begin
      opts.parse! argv
    rescue OptionParser::InvalidOption => e
      # the other options can be used elsewhere, like in RubiGen
      argv = e.recover(argv)
    end
  end
  
  if options[:server] == 'thin'
    # Thin is installed
    command = "thin start -R runner.ru #{argv.join(' ')}"
  else
    # Thin is not installed
    command = "rackup runner.ru -s #{options[:server]} #{argv.join(' ')}"
  end
  
  # run command
  exec command
end