dm-cli 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 Wayne E. Seguin
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,7 @@
1
+ dm-cli
2
+ ======
3
+
4
+ DataMapper plugin allowing interaction with models through a Command-Line
5
+ Interface (CLI).
6
+
7
+ For any issues or questions, in addition to tickets please contact wayneeseguin@gmail.com / wayneeseguin on irc.freenode.net.
data/Rakefile ADDED
@@ -0,0 +1,67 @@
1
+ require "rubygems"
2
+ require "spec"
3
+ require "rake/clean"
4
+ require "rake/gempackagetask"
5
+ require "spec/rake/spectask"
6
+ require "pathname"
7
+
8
+ CLEAN.include "{log,pkg}/"
9
+
10
+ spec = Gem::Specification.new do |s|
11
+ s.name = "dm-cli"
12
+ s.version = "0.9.2"
13
+ s.platform = Gem::Platform::RUBY
14
+ s.has_rdoc = true
15
+ s.extra_rdoc_files = %w[ README LICENSE TODO ]
16
+ s.summary = "DataMapper plugin allowing interaction with models through a CLI"
17
+ s.description = s.summary
18
+ s.author = "Wayne E. Seguin"
19
+ s.email = "wayneeseguin@gmail.com"
20
+ s.homepage = "http://github.com/sam/dm-more/tree/master/dm-cli"
21
+ s.executables = [ "dm" ]
22
+ s.bindir = "bin"
23
+ s.require_path = "lib"
24
+ s.files = FileList[ "bin/.*", "{lib,spec}/**/*.rb", "spec/spec.opts", "Rakefile", *s.extra_rdoc_files ]
25
+ s.add_dependency("dm-core", "=#{s.version}")
26
+ end
27
+
28
+ task :default => [ :spec ]
29
+
30
+ WIN32 = (RUBY_PLATFORM =~ /win32|mingw|cygwin/) rescue nil
31
+ SUDO = WIN32 ? "" : ("sudo" unless ENV["SUDOLESS"])
32
+
33
+ Rake::GemPackageTask.new(spec) do |pkg|
34
+ pkg.gem_spec = spec
35
+ end
36
+
37
+ desc "Install #{spec.name} #{spec.version} (default ruby)"
38
+ task :install => [ :package ] do
39
+ sh "#{SUDO} gem install --local pkg/#{spec.name}-#{spec.version} --no-update-sources", :verbose => false
40
+ end
41
+
42
+ desc "Uninstall #{spec.name} #{spec.version} (default ruby)"
43
+ task :uninstall => [ :clobber ] do
44
+ sh "#{SUDO} gem uninstall #{spec.name} -v#{spec.version} -I -x", :verbose => false
45
+ end
46
+
47
+ namespace :jruby do
48
+ desc "Install #{spec.name} #{spec.version} with JRuby"
49
+ task :install => [ :package ] do
50
+ sh %{#{SUDO} jruby -S gem install --local pkg/#{spec.name}-#{spec.version} --no-update-sources}, :verbose => false
51
+ end
52
+ end
53
+
54
+ desc "Run specifications"
55
+ Spec::Rake::SpecTask.new(:spec) do |t|
56
+ t.spec_opts << "--options" << "spec/spec.opts" if File.exists?("spec/spec.opts")
57
+ t.spec_files = Pathname.glob(Pathname.new(__FILE__).dirname + "spec/**/*_spec.rb")
58
+
59
+ begin
60
+ t.rcov = ENV.has_key?("NO_RCOV") ? ENV["NO_RCOV"] != "true" : true
61
+ t.rcov_opts << "--exclude" << "spec"
62
+ t.rcov_opts << "--text-summary"
63
+ t.rcov_opts << "--sort" << "coverage" << "--sort-reverse"
64
+ rescue Exception
65
+ # rcov not installed
66
+ end
67
+ end
data/TODO ADDED
@@ -0,0 +1,8 @@
1
+ TODO
2
+ ====
3
+
4
+
5
+
6
+ ---
7
+ TODO tickets may also be found in the DataMapper Issue Tracker:
8
+ http://wm.lighthouseapp.com/projects/4819-datamapper/overview
data/bin/.irbrc ADDED
@@ -0,0 +1,2 @@
1
+ IRB.conf[:PROMPT] = {:DM => { :PROMPT_I=>"%03n:%i dm> ", :PROMPT_N=>"%03n:%i dm> ", :PROMPT_S=>"%03n:%i%l dm", :PROMPT_C=>"%03n:%i dm*", :RETURN=>"%s\n" }}
2
+ IRB.conf[:PROMPT_MODE] = :DM
data/bin/dm ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ require "rubygems"
3
+
4
+ gem "dm-core", ">=0.9.2"
5
+ require "dm-core"
6
+ require "pathname"
7
+ require Pathname("data_mapper/cli")
8
+ require "optparse"
9
+
10
+ DataMapper::CLI::BinDir = File.dirname(__FILE__)
11
+ DataMapper::CLI.start
@@ -0,0 +1,185 @@
1
+ require "yaml"
2
+ require "irb"
3
+ require Pathname("irb/completion")
4
+
5
+ # TODO: error handling for:
6
+ # missing adapter, host or database
7
+ module DataMapper
8
+
9
+ class CLI
10
+
11
+ class << self
12
+
13
+ def usage
14
+ <<-USAGE
15
+
16
+ dm - Data Mapper CLI
17
+
18
+ Usage Examples\n#{'='*80}
19
+
20
+ * If exactly one argument is given the CLI assumes it is a connection string:
21
+ $ dm mysql://root@localhost/test_development
22
+
23
+ The connection string has the format:
24
+ adapter://user:password@host:port/database
25
+ Where adapter is in: {mysql, pgsql, sqlite...} and the user/password is optional
26
+
27
+ * Load the database by specifying only cli options
28
+ $ dm -a mysql -u root -h localhost -d test_development -e developemnt
29
+
30
+ * Load the database using a yaml config file and specifying the environment to use
31
+ $ dm --yaml config/database.yml -e development
32
+
33
+ * Load everything from a config file, this example is equivalent to the above
34
+ $ dm --config config/development.yml
35
+
36
+ * Load the database and some model files from a directory, specifying the environment
37
+ $ dm --yaml config/database.yml -e development --models app/models
38
+
39
+ * Load an assumed structure of a typical merb application
40
+ $ dm --merb -e development
41
+
42
+ This is similar to merb -i without the merb framework being loaded.
43
+
44
+ USAGE
45
+ end
46
+
47
+ attr_accessor :options, :config
48
+
49
+ def parse_args(argv = ARGV)
50
+ @config ||= {}
51
+
52
+ # Build a parser for the command line arguments
53
+ OptionParser.new do |opt|
54
+ opt.define_head "DataMapper CLI"
55
+ opt.banner = usage
56
+
57
+ opt.on("-m", "--models MODELS", "The directory to load models from.") do |models|
58
+ @config[:models] = Pathname(models)
59
+ end
60
+
61
+ opt.on("-c", "--config FILE", "Entire configuration structure, useful for testing scenarios.") do |config_file|
62
+ @config = YAML::load_file Pathname(config_file)
63
+ end
64
+
65
+ opt.on("--merb", "--rails", "Loads application settings: config/database.yml, app/models.") do
66
+ @config[:models] = Pathname("app/models")
67
+ @config[:yaml] = Pathname("config/database.yml")
68
+ end
69
+
70
+ opt.on("-y", "--yaml YAML", "The database connection configuration yaml file.") do |yaml_file|
71
+ if (yaml = Pathname(yaml_file)).file?
72
+ @config[:yaml] = yaml
73
+ elsif (yaml = Pathname("#{Dir.getwd}/#{yaml_file}")).file?
74
+ @config[:yaml] = yaml
75
+ else
76
+ raise "yaml file was specifed as #{yaml_file} but does not exist."
77
+ end
78
+ end
79
+
80
+ opt.on("-l", "--log LOGFILE", "A string representing the logfile to use.") do |log_file|
81
+ @config[:log_file] = Pathname(log_file)
82
+ end
83
+
84
+ opt.on("-e", "--environment STRING", "Run merb in the correct mode(development, production, testing)") do |environment|
85
+ @config[:environment] = environment
86
+ end
87
+
88
+ opt.on("-a", "--adapter ADAPTER", "Number of merb daemons to run.") do |adapter|
89
+ @config[:adapter] = adapter
90
+ end
91
+
92
+ opt.on("-u", "--username USERNAME", "The user to connect to the database as.") do |username|
93
+ @config[:username] = username
94
+ end
95
+
96
+ opt.on("-p", "--password PASSWORD", "The password to connect to the database with") do |password|
97
+ @config[:password] = password
98
+ end
99
+
100
+ opt.on("-h", "--host HOSTNAME", "Host to connect to.") do |host|
101
+ @config[:host] = host
102
+ end
103
+
104
+ opt.on("-s", "--socket SOCKET", "The socket to connect to.") do |socket|
105
+ @config[:socket] = socket
106
+ end
107
+
108
+ opt.on("-o", "--port PORT", "The port to connect to.") do |port|
109
+ @config[:port] = port
110
+ end
111
+
112
+ opt.on("-d", "--database DATABASENAME", "Name of the database to connect to.") do |database_name|
113
+ @config[:database] = database_name
114
+ end
115
+
116
+ opt.on("-?", "-H", "--help", "Show this help message") do
117
+ puts opt
118
+ exit
119
+ end
120
+
121
+ end.parse!(argv)
122
+
123
+ end
124
+
125
+ def configure(args)
126
+ if args[0] && args[0].match(/^(.+):\/\/(?:(.*)(?::(.+))?@)?(.+)\/(.+)$/)
127
+ @options = {
128
+ :adapter => $1,
129
+ :username => $2,
130
+ :password => $3,
131
+ :host => $4,
132
+ :database => $5
133
+ }
134
+ @config = @options.merge(:connection_string => ARGV.shift)
135
+ else
136
+
137
+ parse_args(args)
138
+
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
156
+
157
+ end
158
+ end
159
+
160
+ def load_models
161
+ Pathname.glob("#{config[:models]}/**/*.rb") { |file| load file }
162
+ end
163
+
164
+ def start(argv = ARGV)
165
+ if (ARGV.nil? || ARGV.empty?)
166
+ puts DataMapper::CLI.usage
167
+ exit 1
168
+ end
169
+
170
+ begin
171
+ configure(argv)
172
+ DataMapper.setup(:default, options.dup)
173
+ 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
176
+ IRB.start
177
+ rescue => error
178
+ puts error.message
179
+ exit
180
+ end
181
+
182
+ end
183
+ end
184
+ end # module CLI
185
+ end # module DataMapper
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --format specdoc
2
+ --colour
@@ -0,0 +1,128 @@
1
+ require "rubygems"
2
+
3
+ gem "dm-core", ">=0.9.2"
4
+ require "dm-core"
5
+
6
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "lib", "data_mapper", "cli"))
7
+
8
+ describe DataMapper::CLI do
9
+
10
+ describe "connection string" do
11
+ end
12
+
13
+ describe "CLI options" do
14
+
15
+ # Entire configuration structure, useful for testing scenarios.
16
+ describe "-c or --config" do
17
+ it "should load config file" do
18
+ pending
19
+ # arg = ["c"]
20
+ # cli = DataMapper::CLI.new
21
+ # cli.parse_args(arg)
22
+
23
+ end
24
+ end
25
+
26
+ describe "-m or --models" do
27
+ it "should set options[:models]" do
28
+ pending
29
+ end
30
+ end
31
+
32
+ # database connection configuration yaml file.
33
+ describe "-y or --yaml" do
34
+ it "should set options[:yaml]" do
35
+ pending
36
+ end
37
+ end
38
+
39
+ # logfile
40
+ describe "-l or --log" do
41
+ it "should set options[:log_file]" do
42
+ pending
43
+ end
44
+ end
45
+
46
+ # environment to use with database yaml file.
47
+ describe "-e, --environment" do
48
+ it "should set options[:environment]" do
49
+ pending
50
+ end
51
+ end
52
+
53
+ # Loads Merb app settings: config/database.yml, app/models
54
+ # Loads Rails app settings: config/database.yml, app/models
55
+ describe "--merb, --rails" do
56
+ it "should set options[:models]" do
57
+ pending
58
+ end
59
+
60
+ it "should set options[:yaml]" do
61
+ pending
62
+ end
63
+ end
64
+
65
+ describe "database options" do
66
+
67
+ # adapter {mysql, pgsql, etc...}
68
+ describe "-a, --adapter" do
69
+ it "should support mysql" do
70
+ pending
71
+ end
72
+
73
+ it "should support pgsql" do
74
+ pending
75
+ end
76
+
77
+ it "should support sqlite" do
78
+ pending
79
+ end
80
+ end
81
+
82
+ # database name
83
+ describe "-d, --database" do
84
+ it "should set options[:database]" do
85
+ pending
86
+ end
87
+ end
88
+
89
+ # user name
90
+ describe "-u, --username" do
91
+ it "should set options[:username]" do
92
+ pending
93
+ end
94
+ end
95
+
96
+ # password
97
+ describe "-p, --password" do
98
+ it "should set options[:password]" do
99
+ pending
100
+ end
101
+ end
102
+
103
+ # host
104
+ describe "-h, --host" do
105
+ it "should set options[:host]" do
106
+ pending
107
+ end
108
+ end
109
+
110
+ # socket
111
+ describe "-s, --socket" do
112
+ it "should set options[:socket]" do
113
+ pending
114
+ end
115
+ end
116
+
117
+ # port
118
+ describe "-o, --port" do
119
+ it "should set options[:port]" do
120
+ pending
121
+ end
122
+ end
123
+
124
+ end
125
+
126
+ end
127
+
128
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dm-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.2
5
+ platform: ruby
6
+ authors:
7
+ - Wayne E. Seguin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-06-25 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: dm-core
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - "="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.9.2
23
+ version:
24
+ description: DataMapper plugin allowing interaction with models through a CLI
25
+ email: wayneeseguin@gmail.com
26
+ executables:
27
+ - dm
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README
32
+ - LICENSE
33
+ - TODO
34
+ files:
35
+ - bin/.
36
+ - bin/..
37
+ - bin/.irbrc
38
+ - lib/data_mapper/cli.rb
39
+ - spec/unit/cli_spec.rb
40
+ - spec/spec.opts
41
+ - Rakefile
42
+ - README
43
+ - LICENSE
44
+ - TODO
45
+ has_rdoc: true
46
+ homepage: http://github.com/sam/dm-more/tree/master/dm-cli
47
+ post_install_message:
48
+ rdoc_options: []
49
+
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.0.1
68
+ signing_key:
69
+ specification_version: 2
70
+ summary: DataMapper plugin allowing interaction with models through a CLI
71
+ test_files: []
72
+