diff options
Diffstat (limited to 'railties/lib/rails/commands')
-rw-r--r-- | railties/lib/rails/commands/application.rb | 2 | ||||
-rw-r--r-- | railties/lib/rails/commands/plugin.rb | 109 | ||||
-rw-r--r-- | railties/lib/rails/commands/runner.rb | 2 | ||||
-rw-r--r-- | railties/lib/rails/commands/server.rb | 3 |
4 files changed, 62 insertions, 54 deletions
diff --git a/railties/lib/rails/commands/application.rb b/railties/lib/rails/commands/application.rb index a3a5aed399..47c6752ca3 100644 --- a/railties/lib/rails/commands/application.rb +++ b/railties/lib/rails/commands/application.rb @@ -4,7 +4,7 @@ if %w(--version -v).include? ARGV.first exit(0) end -if ARGV.first != "new" || ARGV.empty? +if ARGV.first != "new" ARGV[0] = "--help" else ARGV.shift diff --git a/railties/lib/rails/commands/plugin.rb b/railties/lib/rails/commands/plugin.rb index 8bcd92a33b..96b6f9c372 100644 --- a/railties/lib/rails/commands/plugin.rb +++ b/railties/lib/rails/commands/plugin.rb @@ -3,7 +3,7 @@ # Installing plugins: # # $ rails plugin install continuous_builder asset_timestamping -# +# # Specifying revisions: # # * Subversion revision is a single integer. @@ -14,12 +14,11 @@ # 'tag 1.8.0' (equivalent to 'refs/tags/1.8.0') # # -# This is Free Software, copyright 2005 by Ryan Tomayko (rtomayko@gmail.com) +# This is Free Software, copyright 2005 by Ryan Tomayko (rtomayko@gmail.com) # and is licensed MIT: (http://www.opensource.org/licenses/mit-license.php) $verbose = false - require 'open-uri' require 'fileutils' require 'tempfile' @@ -40,18 +39,18 @@ class RailsEnvironment dir = File.dirname(dir) end end - + def self.default @default ||= find end - + def self.default=(rails_env) @default = rails_env end - + def install(name_uri_or_plugin) if name_uri_or_plugin.is_a? String - if name_uri_or_plugin =~ /:\/\// + if name_uri_or_plugin =~ /:\/\// plugin = Plugin.new(name_uri_or_plugin) else plugin = Plugins[name_uri_or_plugin] @@ -65,7 +64,7 @@ class RailsEnvironment puts "Plugin not found: #{name_uri_or_plugin}" end end - + def use_svn? require 'active_support/core_ext/kernel' silence_stderr {`svn --version` rescue nil} @@ -97,7 +96,7 @@ class RailsEnvironment ext = `svn propget svn:externals "#{root}/vendor/plugins"` lines = ext.respond_to?(:lines) ? ext.lines : ext lines.reject{ |line| line.strip == '' }.map do |line| - line.strip.split(/\s+/, 2) + line.strip.split(/\s+/, 2) end end @@ -111,38 +110,37 @@ class RailsEnvironment system("svn propset -q svn:externals -F \"#{file.path}\" \"#{root}/vendor/plugins\"") end end - end class Plugin attr_reader :name, :uri - + def initialize(uri, name = nil) @uri = uri guess_name(uri) end - + def self.find(name) new(name) end - + def to_s "#{@name.ljust(30)}#{@uri}" end - + def svn_url? @uri =~ /svn(?:\+ssh)?:\/\/*/ end - + def git_url? @uri =~ /^git:\/\// || @uri =~ /\.git$/ end - + def installed? File.directory?("#{rails_env.root}/vendor/plugins/#{name}") \ or rails_env.externals.detect{ |name, repo| self.uri == repo } end - + def install(method=nil, options = {}) method ||= rails_env.best_install_method? if :http == method @@ -173,7 +171,7 @@ class Plugin if rails_env.use_externals? # clean up svn:externals externals = rails_env.externals - externals.reject!{|n,u| name == n or name == u} + externals.reject!{|n, u| name == n or name == u} rails_env.externals = externals end end @@ -192,7 +190,7 @@ class Plugin FileUtils.rm_rf tmp if svn_url? end - private + private def run_install_hook install_hook_file = "#{rails_env.root}/vendor/plugins/#{name}/install.rb" @@ -207,11 +205,11 @@ class Plugin def install_using_export(options = {}) svn_command :export, options end - + def install_using_checkout(options = {}) svn_command :checkout, options end - + def install_using_externals(options = {}) externals = rails_env.externals externals.push([@name, uri]) @@ -229,7 +227,7 @@ class Plugin fetcher.fetch end end - + def install_using_git(options = {}) root = rails_env.root mkdir_p(install_path = "#{root}/vendor/plugins/#{name}") @@ -268,7 +266,7 @@ class Plugin end @name.gsub!(/\.git$/, '') if @name =~ /\.git$/ end - + def rails_env @rails_env || RailsEnvironment.default end @@ -277,45 +275,44 @@ end # load default environment and parse arguments require 'optparse' module Commands - class Plugin attr_reader :environment, :script_name, :sources def initialize @environment = RailsEnvironment.default @rails_root = RailsEnvironment.default.root - @script_name = File.basename($0) + @script_name = File.basename($0) @sources = [] end - + def environment=(value) @environment = value RailsEnvironment.default = value end - + def options OptionParser.new do |o| o.set_summary_indent(' ') o.banner = "Usage: plugin [OPTIONS] command" o.define_head "Rails plugin manager." - - o.separator "" + + o.separator "" o.separator "GENERAL OPTIONS" - + o.on("-r", "--root=DIR", String, "Set an explicit rails app directory.", "Default: #{@rails_root}") { |rails_root| @rails_root = rails_root; self.environment = RailsEnvironment.new(@rails_root) } o.on("-s", "--source=URL1,URL2", Array, "Use the specified plugin repositories instead of the defaults.") { |sources| @sources = sources} - + o.on("-v", "--verbose", "Turn on verbose output.") { |verbose| $verbose = verbose } o.on("-h", "--help", "Show this help message.") { puts o; exit } - + o.separator "" o.separator "COMMANDS" - + o.separator " install Install plugin(s) from known repositories or URLs." o.separator " remove Uninstall plugins." - + o.separator "" o.separator "EXAMPLES" o.separator " Install a plugin:" @@ -328,41 +325,41 @@ module Commands o.separator " #{@script_name} plugin install -x continuous_builder\n" end end - + def parse!(args=ARGV) general, sub = split_args(args) options.parse!(general) - + command = general.shift if command =~ /^(install|remove)$/ command = Commands.const_get(command.capitalize).new(self) command.parse!(sub) else - puts "Unknown command: #{command}" + puts "Unknown command: #{command}" unless command.blank? puts options exit 1 end end - + def split_args(args) left = [] left << args.shift while args[0] and args[0] =~ /^-/ left << args.shift if args[0] - return [left, args] + [left, args] end - + def self.parse!(args=ARGV) Plugin.new.parse!(args) end end - + class Install def initialize(base_command) @base_command = base_command @method = :http @options = { :quiet => false, :revision => nil, :force => false } end - + def options OptionParser.new do |o| o.set_summary_indent(' ') @@ -370,8 +367,8 @@ module Commands o.define_head "Install one or more plugins." o.separator "" o.separator "Options:" - o.on( "-x", "--externals", - "Use svn:externals to grab the plugin.", + o.on( "-x", "--externals", + "Use svn:externals to grab the plugin.", "Enables plugin updates and plugin versioning.") { |v| @method = :externals } o.on( "-o", "--checkout", "Use svn checkout to grab the plugin.", @@ -392,7 +389,7 @@ module Commands o.separator "a plugin repository." end end - + def determine_install_method best = @base_command.environment.best_install_method @method = :http if best == :http and @method == :export @@ -410,9 +407,13 @@ module Commands end @method end - + def parse!(args) options.parse!(args) + if args.blank? + puts options + exit 1 + end environment = @base_command.environment install_method = determine_install_method puts "Plugins will be installed using #{install_method}" if $verbose @@ -430,7 +431,7 @@ module Commands def initialize(base_command) @base_command = base_command end - + def options OptionParser.new do |o| o.set_summary_indent(' ') @@ -438,9 +439,13 @@ module Commands o.define_head "Remove plugins." end end - + def parse!(args) options.parse!(args) + if args.blank? + puts options + exit 1 + end root = @base_command.environment.root args.each do |name| ::Plugin.new(name).uninstall @@ -470,7 +475,7 @@ module Commands end end end - + class RecursiveHTTPFetcher attr_accessor :quiet def initialize(urls_to_fetch, level = 1, cwd = ".") @@ -511,7 +516,7 @@ class RecursiveHTTPFetcher end links end - + def download(link) puts "+ #{File.join(@cwd, File.basename(link))}" unless @quiet open(link) do |stream| @@ -520,13 +525,13 @@ class RecursiveHTTPFetcher end end end - + def fetch(links = @urls_to_fetch) links.each do |l| (l =~ /\/$/ || links == @urls_to_fetch) ? fetch_dir(l) : download(l) end end - + def fetch_dir(url) @level += 1 push_d(File.basename(url)) if @level > 0 diff --git a/railties/lib/rails/commands/runner.rb b/railties/lib/rails/commands/runner.rb index b97ff086b6..c43a233bc3 100644 --- a/railties/lib/rails/commands/runner.rb +++ b/railties/lib/rails/commands/runner.rb @@ -37,7 +37,7 @@ ARGV.delete(code_or_file) ENV["RAILS_ENV"] = options[:environment] require APP_PATH -Rails::Application.require_environment! +Rails.application.require_environment! begin if code_or_file.nil? diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb index 9d9dd48ea9..c3927b6613 100644 --- a/railties/lib/rails/commands/server.rb +++ b/railties/lib/rails/commands/server.rb @@ -21,6 +21,9 @@ module Rails opts.on("-e", "--environment=name", String, "Specifies the environment to run this server under (test/development/production).", "Default: development") { |v| options[:environment] = v } + opts.on("-P","--pid=pid",String, + "Specifies the PID file.", + "Default: tmp/pids/server.pid") { |v| options[:pid] = v } opts.separator "" |