nezu 0.5.24 → 0.5.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/Gemfile.lock +1 -1
  2. data/VERSION +1 -1
  3. data/bin/nezu +0 -1
  4. data/lib/nezu/cli.rb +44 -23
  5. data/lib/nezu.rb +14 -22
  6. metadata +2 -2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nezu (0.5.24)
4
+ nezu (0.5.25)
5
5
  activerecord (~> 3.2.11)
6
6
  activesupport (~> 3.2.11)
7
7
  amqp
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.24
1
+ 0.5.25
data/bin/nezu CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- puts File.join(File.expand_path('../..', __FILE__), 'lib')
3
2
  $:.unshift(File.join(File.expand_path('../..', __FILE__), 'lib'))
4
3
  ARGV << 'help' if ARGV.length == 0
5
4
 
data/lib/nezu/cli.rb CHANGED
@@ -1,35 +1,21 @@
1
+ require 'optparse'
1
2
  require 'nezu'
2
3
  module Nezu
3
4
  module CLI
4
- def self.help(*params)
5
- script_name = File.basename(__FILE__)
6
- puts %Q(
7
- Usage:
8
-
9
- "#{script_name} new <appname>" for an app skeleton dir in <appname>
10
- "#{script_name} run" inside an app dir to start it
11
- "#{script_name} console" inside an app dir to get an irb shell with your current env loaded
12
-
13
- ).gsub(/^\s*/, '')
14
- exit(1)
15
- end
16
-
17
- def self.new(*params)
18
- amqp_scope = params[0].grep(/--amqp_scope/)[0].match(/=(\S*)/)[1] rescue nil
19
- configatron.amqp_scope = amqp_scope if amqp_scope
20
- puts %Q(Creating application dir in "#{params[0][0]}")
5
+ def self.new(params={})
6
+ puts %Q(Creating application dir in "#{params[:app]}")
21
7
  require 'nezu/generators'
22
- app = Nezu::Generators::Application::AppGenerator.new(params[0][0])
8
+ app = Nezu::Generators::Application::AppGenerator.new(params[:app])
23
9
  app.generate!
24
10
  puts %Q(Successfully created App.)
25
11
  exit(0)
26
12
  end
27
13
 
28
- def self.run(*params)
14
+ def self.run(params={})
29
15
  puts %Q(Starting app...)
30
16
  require 'nezu/runner'
31
17
  Nezu::Runtime.load_config
32
- if params[0].include?('--daemon')
18
+ if params[:daemon]
33
19
  fork do
34
20
  $stdout=File.open(Nezu.root.join('log', 'nezu.stdout'), File::CREAT|File::WRONLY)
35
21
  $stderr=File.open(Nezu.root.join('log', 'nezu.stderr'), File::CREAT|File::WRONLY)
@@ -41,14 +27,49 @@ module Nezu
41
27
  exit(0)
42
28
  end
43
29
 
44
- def self.console(*params)
30
+ def self.console(params={})
45
31
  puts %Q(Starting console...)
46
- ARGV.clear
47
32
  Nezu::Runtime.load_config
48
33
  IRB.start()
49
34
  end
50
35
  end
51
36
  end
52
37
 
53
- Nezu::CLI.send(ARGV.shift, ARGV)
38
+ begin
39
+ command = ARGV.shift
40
+ options = {}
41
+
42
+ if command == 'new'
43
+ options[:app] = ARGV.shift
44
+ else
45
+
46
+ optparse = OptionParser.new do|opts|
47
+ opts.program_name = "#{File.basename($0, '.*')} COMMAND:=run|console|new"
48
+
49
+ opts.on( '-h', '--help', 'Display this screen' ) do
50
+ puts opts
51
+ exit
52
+ end
53
+ if command == 'run'
54
+ options[:daemon] = false
55
+ opts.on( '-d', '--daemon', 'Run as a background process' ) do
56
+ options[:daemon] = true
57
+ end
58
+
59
+ end
60
+
61
+ opts.on( '-E <ENV>', '--env <ENV>', 'Start the app with the given environment' ) do |env|
62
+ options[:env] = env
63
+ Nezu.env = Nezu::Env.new(env)
64
+ end
65
+ end
54
66
 
67
+ optparse.parse!
68
+ end
69
+
70
+ require 'debugger' if Nezu.env.development? || Nezu.env.test?
71
+
72
+ Nezu::CLI.send(command, options)
73
+ rescue OptionParser::MissingArgument, OptionParser::InvalidOption
74
+ puts optparse
75
+ end
data/lib/nezu.rb CHANGED
@@ -9,7 +9,7 @@ require 'term/ansicolor'
9
9
  require 'nezu/runtime'
10
10
 
11
11
  module Nezu
12
- mattr_accessor :logger
12
+ mattr_accessor :logger, :app, :env, :root, :gem_path
13
13
 
14
14
  #used by Nezu.env and Nezu.env.developent? etc.
15
15
  class Env < String
@@ -43,6 +43,19 @@ module Nezu
43
43
  end
44
44
  end
45
45
 
46
+ # Returns a String like object with the current name of the environment that responds to thinks like "#development?"
47
+ self.env = Env.new(ENV['NEZU_ENV']||'development')
48
+
49
+ # Returns the app as a class
50
+ self.app = configatron.app_name.classify
51
+
52
+ # Returns a String like object with the applications absolute root
53
+ self.root = Root::APP_PATH
54
+
55
+ # Returns a String like object with the gems absolute root
56
+ self.gem_path = Root::GEM_PATH
57
+
58
+
46
59
  # all these nice colorful log entries are created here
47
60
  # if you don`t like them just override its #call method
48
61
  class CustomLogFormatter
@@ -91,25 +104,6 @@ module Nezu
91
104
  end
92
105
  end
93
106
 
94
- # Returns a String like object with the current name of the environment
95
- def self.env
96
- Env.new(ENV['NEZU_ENV']||'development')
97
- end
98
-
99
- def self.app
100
- configatron.app_name.classify
101
- end
102
-
103
- # Returns a String like object with the applications absolute root
104
- def self.root
105
- Root::APP_PATH
106
- end
107
-
108
- # Returns a String like object with the gems absolute root
109
- def self.gem_path
110
- Root::GEM_PATH
111
- end
112
-
113
107
  # turn errors into warnings if used in verbose mode (Nezu.try(true) { ... })
114
108
  # useful if you find it acceptable that something isn't
115
109
  # working
@@ -137,5 +131,3 @@ module Nezu
137
131
  end
138
132
  end
139
133
 
140
- require 'debugger' if Nezu.env.development? || Nezu.env.test?
141
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nezu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.24
4
+ version: 0.5.25
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-04-24 00:00:00.000000000 Z
13
+ date: 2013-04-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: amqp