public
Rubygem
Description: JSON Web App Framework
Homepage: http://halcyon.rubyforge.org/
Clone URL: git://github.com/mtodd/halcyon.git
Search Repo:
Click here to lend your support to: halcyon and make a donation at www.pledgie.com !
Added command line parsing and processing of commands:
* Added init which will initialize a new Halcyon application.
* Added start which will run rackup or thin passing along params to start 
the Halcyon application.
mtodd (author)
Tue Mar 25 17:52:52 -0700 2008
commit  32559974b4e68e3ebf6e6c1c17b7d5e474ff4bbb
tree    b23fc68379f65658f06ba69aa6e2696c9e349557
parent  0543566fb3c463d471bff60521e90b36efbbcdc0
...
1
2
3
4
5
6
7
8
9
 
 
...
1
2
 
 
 
 
 
 
 
3
4
0
@@ -1,10 +1,5 @@
0
 #!/usr/bin/env ruby
0
 
0
-require 'rubygems'
0
-require 'rubigen'
0
-
0
-require 'rubigen/scripts/generate'
0
-RubiGen::Base.use_application_sources!
0
-RubiGen::Base.sources << RubiGen::PathSource.new(:custom, File.expand_path(File.join(File.dirname(__FILE__), '..', "support/generators")))
0
-RubiGen::Scripts::Generate.new.run(ARGV, :generator => 'halcyon')
0
+require File.join(File.dirname(__FILE__), '..', 'lib', 'halcyon')
0
+Halcyon::Runner.run! ARGV
...
1
2
3
 
 
4
5
6
7
8
9
 
 
10
11
12
13
 
 
 
 
 
 
 
 
 
 
 
14
15
16
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 
17
18
19
20
21
22
23
24
25
26
27
28
29
30
0
@@ -1,16 +1,30 @@
0
 # Partly modeled after Thin's Runner, found at
0
 # http://github.com/macournoyer/thin/tree/master/lib/thin/runner.rb
0
 
0
+require 'optparse'
0
+
0
 module Halcyon
0
   
0
   # = CLI Runner
0
   # Parse options and start serving the app
0
   class Runner
0
     
0
+ autoload :Commands, 'halcyon/runner/commands'
0
+
0
     # Make sure that the Halcyon.config hash is setup
0
     Halcyon.config ||= Mash.new(Halcyon::Application::DEFAULT_OPTIONS)
0
     
0
- def initialize(argv=ARGV)
0
+ class << self
0
+
0
+ # Runs commands from the CLI; foregoes actually running the app
0
+ def run!(argv=ARGV)
0
+ Commands.send(argv.shift, argv)
0
+ end
0
+
0
+ end
0
+
0
+ # Sets up the application to run
0
+ def initialize
0
       if Halcyon.config[:logger]
0
         Halcyon.logger = Halcyon.config[:logger]
0
       else
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
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
44
45
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
0
@@ -1 +1,76 @@
0
+module Halcyon
0
+ class Runner
0
+ class Commands
0
+ class << self
0
+
0
+ # Run the Halcyon application
0
+ def start(argv)
0
+ options = {
0
+ :port => 4647,
0
+ :server => (Gem.searcher.find('thin').nil? ? 'mongrel' : 'thin')
0
+ }
0
+
0
+ OptionParser.new do |opts|
0
+ opts.banner = "Usage: halcyon start [options]"
0
+
0
+ opts.separator ""
0
+ opts.separator "Start options:"
0
+ opts.on("-s", "--server SERVER", "") { |server| options[:server] = server }
0
+
0
+ begin
0
+ opts.parse! argv
0
+ rescue OptionParser::InvalidOption => e
0
+ # the other options can be used elsewhere, like in RubiGen
0
+ argv = e.recover(argv)
0
+ end
0
+ end
0
+
0
+ if options[:server] == 'thin'
0
+ # Thin is installed
0
+ command = "thin start -r runner.ru #{argv.join(' ')}"
0
+ else
0
+ # Thin is not installed
0
+ command = "rackup runner.ru -s #{options[:server]} #{argv.join(' ')}"
0
+ end
0
+
0
+ # run command
0
+ exec command
0
+ end
0
+
0
+ # Generate a new Halcyon application
0
+ def init(argv)
0
+ options = {
0
+ :generator => 'halcyon',
0
+ :git => false
0
+ }
0
+
0
+ OptionParser.new do |opts|
0
+ opts.banner = "Usage: halcyon init [options]"
0
+
0
+ opts.separator ""
0
+ opts.separator "Generator options:"
0
+ opts.on("-f", "--flat", "") { options[:generator] = 'halcyon_flat' }
0
+
0
+ opts.separator ""
0
+ opts.separator "Additional options:"
0
+ opts.on("-g", "--git", "Initialize a Git repository when finished generating") { options[:git] = true }
0
+
0
+ begin
0
+ opts.parse! argv
0
+ rescue OptionParser::InvalidOption => e
0
+ # the other options can be used elsewhere, like in RubiGen
0
+ end
0
+ end
0
+
0
+ require 'rubigen'
0
+ require 'rubigen/scripts/generate'
0
+ RubiGen::Base.use_application_sources!
0
+ RubiGen::Base.sources << RubiGen::PathSource.new(:custom, File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', "support/generators")))
0
+ RubiGen::Scripts::Generate.new.run(argv, :generator => options[:generator])
0
+ end
0
+
0
+ end
0
+ end
0
+ end
0
+end

Comments

    No one has commented yet.