dm-cli 0.9.5 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -46,7 +46,7 @@ end
46
46
  desc "Run specifications"
47
47
  Spec::Rake::SpecTask.new(:spec) do |t|
48
48
  t.spec_opts << "--options" << "spec/spec.opts" if File.exists?("spec/spec.opts")
49
- t.spec_files = Pathname.glob(Pathname.new(__FILE__).dirname + "spec/**/*_spec.rb")
49
+ t.spec_files = Pathname.glob((ROOT + 'spec/**/*_spec.rb').to_s)
50
50
 
51
51
  begin
52
52
  t.rcov = ENV.has_key?("NO_RCOV") ? ENV["NO_RCOV"] != "true" : true
data/bin/dm CHANGED
@@ -3,9 +3,8 @@ require "rubygems"
3
3
 
4
4
  gem "dm-core", ">=0.9.5"
5
5
  require "dm-core"
6
- require "pathname"
7
- require Pathname("data_mapper/cli")
6
+ require "dm-cli"
8
7
  require "optparse"
9
8
 
10
9
  DataMapper::CLI::BinDir = File.dirname(__FILE__)
11
- DataMapper::CLI.start
10
+ DataMapper::CLI.start
data/lib/dm-cli/cli.rb CHANGED
@@ -17,15 +17,19 @@ dm - Data Mapper CLI
17
17
 
18
18
  Usage Examples\n#{'='*80}
19
19
 
20
- * If exactly one argument is given the CLI assumes it is a connection string:
20
+ * If one argument is given the CLI assumes it is a connection string:
21
21
  $ dm mysql://root@localhost/test_development
22
22
 
23
23
  The connection string has the format:
24
24
  adapter://user:password@host:port/database
25
25
  Where adapter is in: {mysql, pgsql, sqlite...} and the user/password is optional
26
26
 
27
- * Load the database by specifying only cli options
28
- $ dm -a mysql -u root -h localhost -d test_development -e developemnt
27
+ Note that if there are any non-optional arguments specified, the first is
28
+ assumed to be a database connection string which will be used instead of any
29
+ database specified by options.
30
+
31
+ * Load the database by specifying cli options
32
+ $ dm -a mysql -u root -h localhost -d test_development
29
33
 
30
34
  * Load the database using a yaml config file and specifying the environment to use
31
35
  $ dm --yaml config/database.yml -e development
@@ -41,6 +45,12 @@ dm - Data Mapper CLI
41
45
 
42
46
  This is similar to merb -i without the merb framework being loaded.
43
47
 
48
+ * Load the dm-validations and dm-timestamps plugins before connecting to the db
49
+ $ dm -P validations,dm-timestamps mysql://root@localhost/test_development
50
+
51
+ If dm- isn't at the start of the file, it will be prepended.
52
+
53
+
44
54
  USAGE
45
55
  end
46
56
 
@@ -77,8 +87,8 @@ USAGE
77
87
  end
78
88
  end
79
89
 
80
- opt.on("-l", "--log LOGFILE", "A string representing the logfile to use.") do |log_file|
81
- @config[:log_file] = Pathname(log_file)
90
+ opt.on("-l", "--log LOGFILE", "A string representing the logfile to use. Also accepts STDERR and STDOUT") do |log_file|
91
+ @config[:log_file] = log_file
82
92
  end
83
93
 
84
94
  opt.on("-e", "--environment STRING", "Run merb in the correct mode(development, production, testing)") do |environment|
@@ -113,6 +123,10 @@ USAGE
113
123
  @config[:database] = database_name
114
124
  end
115
125
 
126
+ opt.on("-P", "--plugins PLUGIN,PLUGIN...", "A list of dm-plugins to require", Array) do |plugins|
127
+ @config[:plugins] = plugins
128
+ end
129
+
116
130
  opt.on("-?", "-H", "--help", "Show this help message") do
117
131
  puts opt
118
132
  exit
@@ -123,42 +137,57 @@ USAGE
123
137
  end
124
138
 
125
139
  def configure(args)
126
- if args[0] && args[0].match(/^(.+):\/\/(?:(.*)(?::(.+))?@)?(.+)\/(.+)$/)
140
+
141
+ parse_args(args)
142
+
143
+ @config[:environment] ||= "development"
144
+ if @config[:config]
145
+ @config.merge!(YAML::load_file(@config[:config]))
146
+ @options = @config[:options]
147
+ elsif @config[:yaml]
148
+ @config.merge!(YAML::load_file(@config[:yaml]))
149
+ @options = @config[@config[:environment]] || @config[@config[:environment].to_sym]
150
+ raise "Options for environment '#{@config[:environment]}' are missing." if @options.nil?
151
+ else
127
152
  @options = {
128
- :adapter => $1,
129
- :username => $2,
130
- :password => $3,
131
- :host => $4,
132
- :database => $5
153
+ :adapter => @config[:adapter],
154
+ :username => @config[:username],
155
+ :password => @config[:password],
156
+ :host => @config[:host],
157
+ :database => @config[:database]
133
158
  }
134
- @config = @options.merge(:connection_string => ARGV.shift)
135
- else
159
+ end
160
+ if !ARGV.empty?
161
+ @config[:connection_string] = ARGV.shift
162
+ end
136
163
 
137
- parse_args(args)
164
+ end
138
165
 
139
- @config[:environment] ||= "development"
140
- if @config[:config]
141
- @config.merge!(YAML::load_file(@config[:config]))
142
- @options = @config[:options]
143
- elsif @config[:yaml]
144
- @config.merge!(YAML::load_file(@config[:yaml]))
145
- @options = @config[@config[:environment]] || @config[@config[:environment].to_sym]
146
- raise "Options for environment '#{@config[:environment]}' are missing." if @options.nil?
147
- else
148
- @options = {
149
- :adapter => @config[:adapter],
150
- :username => @config[:username],
151
- :password => @config[:password],
152
- :host => @config[:host],
153
- :database => @config[:database]
154
- }
155
- end
166
+ def load_models
167
+ Pathname.glob("#{config[:models]}/**/*.rb") { |file| load file }
168
+ end
156
169
 
170
+ def require_plugins
171
+ # make sure we're loading dm plugins!
172
+ plugins = config[:plugins].map {|p| (p =~ /^dm/) ? p : "dm-" + p }
173
+ plugins.each do |plugin|
174
+ begin
175
+ require plugin
176
+ puts "required #{plugin}."
177
+ rescue LoadError => e
178
+ puts "couldn't load #{plugin}."
179
+ end
157
180
  end
158
181
  end
159
182
 
160
- def load_models
161
- Pathname.glob("#{config[:models]}/**/*.rb") { |file| load file }
183
+ def setup_logger
184
+ if config[:log_file] =~ /^std(?:out|err)$/i
185
+ log = Object.full_const_get(config[:log_file].upcase)
186
+ else
187
+ log = Pathname(config[:log_file])
188
+ end
189
+
190
+ DataMapper::Logger.new(log, :debug)
162
191
  end
163
192
 
164
193
  def start(argv = ARGV)
@@ -169,10 +198,20 @@ USAGE
169
198
 
170
199
  begin
171
200
  configure(argv)
172
- DataMapper.setup(:default, options.dup)
201
+
202
+ require_plugins if config[:plugins]
203
+
204
+ setup_logger if config[:log_file]
205
+
206
+ if config[:connection_string]
207
+ DataMapper.setup(:default, config[:connection_string])
208
+ puts "DataMapper has been loaded using '#{config[:connection_string]}'"
209
+ else
210
+ DataMapper.setup(:default, options.dup)
211
+ puts "DataMapper has been loaded using the '#{options[:adapter] || options["adapter"]}' database '#{options[:database] || options["database"]}' on '#{options[:host] || options["host"]}' as '#{options[:username] || options["username"]}'"
212
+ end
173
213
  load_models if config[:models]
174
- puts "DataMapper has been loaded using the '#{options[:adapter] || options["adapter"]}' database '#{options[:database] || options["database"]}' on '#{options[:host] || options["host"]}' as '#{options[:username] || options["username"]}'"
175
- ENV["IRBRC"] = DataMapper::CLI::BinDir + "/.irbrc" # Do not change this please. This should NOT be DataMapper.root
214
+ ENV["IRBRC"] ||= DataMapper::CLI::BinDir + "/.irbrc" # Do not change this please. This should NOT be DataMapper.root
176
215
  IRB.start
177
216
  rescue => error
178
217
  puts error.message
@@ -1,5 +1,5 @@
1
1
  module DataMapper
2
2
  class CLI
3
- VERSION = "0.9.5"
3
+ VERSION = "0.9.6"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wayne E. Seguin
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-26 00:00:00 -05:00
12
+ date: 2008-10-12 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - "="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.9.5
23
+ version: 0.9.6
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hoe