From 96ceaf6fb4e37b014ba4d08e534acc24ef1aa8a7 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Sun, 4 Jul 2010 17:20:50 +0900 Subject: [PATCH 1/2] whitespace --- railties/lib/rails/commands/plugin.rb | 97 ++++++++++++++++----------------- 1 files changed, 47 insertions(+), 50 deletions(-) diff --git a/railties/lib/rails/commands/plugin.rb b/railties/lib/rails/commands/plugin.rb index 8bcd92a..e0930cd 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,11 +325,11 @@ 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) @@ -343,26 +340,26 @@ module Commands 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] 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,7 +407,7 @@ module Commands end @method end - + def parse!(args) options.parse!(args) environment = @base_command.environment @@ -430,7 +427,7 @@ module Commands def initialize(base_command) @base_command = base_command end - + def options OptionParser.new do |o| o.set_summary_indent(' ') @@ -438,7 +435,7 @@ module Commands o.define_head "Remove plugins." end end - + def parse!(args) options.parse!(args) root = @base_command.environment.root @@ -470,7 +467,7 @@ module Commands end end end - + class RecursiveHTTPFetcher attr_accessor :quiet def initialize(urls_to_fetch, level = 1, cwd = ".") @@ -511,7 +508,7 @@ class RecursiveHTTPFetcher end links end - + def download(link) puts "+ #{File.join(@cwd, File.basename(link))}" unless @quiet open(link) do |stream| @@ -520,13 +517,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 -- 1.7.1.1 From 16cbfe1ed57cf57d68255aea7206ac0f34217334 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Sun, 4 Jul 2010 17:37:57 +0900 Subject: [PATCH 2/2] Print proper "Usage:" messages for "rails plugin" command * suppress outputting "Unknown command:" when no command were specified * output the "Usage:" message when no plugin names were given --- railties/lib/rails/commands/plugin.rb | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-) diff --git a/railties/lib/rails/commands/plugin.rb b/railties/lib/rails/commands/plugin.rb index e0930cd..96b6f9c 100644 --- a/railties/lib/rails/commands/plugin.rb +++ b/railties/lib/rails/commands/plugin.rb @@ -335,7 +335,7 @@ module Commands 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 @@ -345,7 +345,7 @@ module Commands 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) @@ -410,6 +410,10 @@ module Commands 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 @@ -438,6 +442,10 @@ module Commands 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 -- 1.7.1.1