From b4ef958de6b16294094de28d00ba25fe2f48accc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 15 Jul 2009 20:16:37 +0200 Subject: Change false to :verbose => false as in new Thor version. --- .../lib/vendor/thor-0.11.1/lib/thor/actions.rb | 70 ++++++++++------------ .../thor-0.11.1/lib/thor/actions/copy_file.rb | 10 ++-- .../thor-0.11.1/lib/thor/actions/create_file.rb | 10 ++-- .../thor-0.11.1/lib/thor/actions/directory.rb | 31 +++++----- .../lib/thor/actions/empty_directory.rb | 10 ++-- .../lib/vendor/thor-0.11.1/lib/thor/actions/get.rb | 10 ++-- .../lib/thor/actions/inject_into_file.rb | 24 ++++---- .../thor-0.11.1/lib/thor/actions/template.rb | 10 ++-- .../thor-0.11.1/lib/thor/actions/templater.rb | 13 ++-- 9 files changed, 88 insertions(+), 100 deletions(-) (limited to 'railties/lib/vendor') diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions.rb index 83d082382c..939339088a 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions.rb @@ -164,8 +164,8 @@ class Thor # Same as inside, but log status and use padding. # - def inside_with_padding(dir='', log_status=true, &block) - say_status :inside, dir, log_status + def inside_with_padding(dir='', config={}, &block) + say_status :inside, dir, config.fetch(:verbose, true) shell.padding += 1 inside(dir, &block) shell.padding -= 1 @@ -182,17 +182,16 @@ class Thor # ==== Parameters # mode:: the file mode # path:: the name of the file to change mode - # log_status:: if false, does not log the status. True by default. - # If a symbol is given, uses it as the output color. + # config:: give :verbose => false to not log the status. # # ==== Example # # chmod "script/*", 0755 # - def chmod(path, mode, log_status=true) + def chmod(path, mode, config={}) return unless behavior == :invoke path = File.expand_path(path, destination_root) - say_status :chmod, relative_to_original_destination_root(path), log_status + say_status :chmod, relative_to_original_destination_root(path), config.fetch(:verbose, true) FileUtils.chmod_R(mode, path) unless options[:pretend] end @@ -200,8 +199,7 @@ class Thor # # ==== Parameters # command:: the command to be executed. - # log_status:: if false, does not log the status. True by default. - # If a symbol is given, uses it as the output color. + # config:: give :verbose => false to not log the status. # # ==== Example # @@ -209,9 +207,10 @@ class Thor # run('ln -s ~/edge rails') # end # - def run(command, log_status=true) + def run(command, config={}) return unless behavior == :invoke - say_status :run, "\"#{command}\" from #{relative_to_original_destination_root(destination_root, false)}", log_status + description = "#{command.inspect} from #{relative_to_original_destination_root(destination_root, false)}" + say_status :run, description, config.fetch(:verbose, true) `#{command}` unless options[:pretend] end @@ -219,12 +218,11 @@ class Thor # # ==== Parameters # command:: the command to be executed. - # log_status:: if false, does not log the status. True by default. - # If a symbol is given, uses it as the output color. + # config:: give :verbose => false to not log the status. # - def run_ruby_script(command, log_status=true) + def run_ruby_script(command, config={}) return unless behavior == :invoke - say_status File.basename(Thor::Util.ruby_command), command, log_status + say_status File.basename(Thor::Util.ruby_command), command, config.fetch(:verbose, true) `#{Thor::Util.ruby_command} #{command}` unless options[:pretend] end @@ -234,9 +232,8 @@ class Thor # ==== Parameters # task:: the task to be invoked # args:: arguments to the task - # options:: a hash with options used on invocation - # log_status:: if false, does not log the status. True by default. - # If a symbol is given, uses it as the output color. + # options:: give :verbose => false to not log the status. Other options + # are given as parameter to Thor. # # ==== Examples # @@ -247,35 +244,33 @@ class Thor # #=> thor list --all --substring=rails # def thor(task, *args) - log_status = args.last.is_a?(Symbol) || [true, false].include?(args.last) ? args.pop : true - options = args.last.is_a?(Hash) ? args.pop : {} + config = args.last.is_a?(Hash) ? args.pop : {} + verbose = config.key?(:verbose) ? config.delete(:verbose) : true args.unshift task - args.push Thor::Options.to_switches(options) + args.push Thor::Options.to_switches(config) command = args.join(' ').strip - say_status :thor, command, log_status - run "thor #{command}", false + say_status :thor, command, verbose + run "thor #{command}", :verbose => false end # Removes a file at the given location. # # ==== Parameters # path:: path of the file to be changed - # log_status:: if false, does not log the status. True by default. - # If a symbol is given, uses it as the output color. + # config:: give :verbose => false to not log the status. # # ==== Example # # remove_file 'README' # remove_file 'app/controllers/application_controller.rb' # - def remove_file(path, log_status=true) + def remove_file(path, config={}) return unless behavior == :invoke path = File.expand_path(path, destination_root) - color = log_status.is_a?(Symbol) ? log_status : :red - say_status :remove, relative_to_original_destination_root(path), log_status + say_status :remove, relative_to_original_destination_root(path), config.fetch(:verbose, true) ::FileUtils.rm_rf(path) if !options[:pretend] && File.exists?(path) end @@ -285,8 +280,7 @@ class Thor # path:: path of the file to be changed # flag:: the regexp or string to be replaced # replacement:: the replacement, can be also given as a block - # log_status:: if false, does not log the status. True by default. - # If a symbol is given, uses it as the output color. + # config:: give :verbose => false to not log the status. # # ==== Example # @@ -298,10 +292,10 @@ class Thor # def gsub_file(path, flag, *args, &block) return unless behavior == :invoke - log_status = args.last.is_a?(Symbol) || [ true, false ].include?(args.last) ? args.pop : true + config = args.last.is_a?(Hash) ? args.pop : {} path = File.expand_path(path, destination_root) - say_status :gsub, relative_to_original_destination_root(path), log_status + say_status :gsub, relative_to_original_destination_root(path), config.fetch(:verbose, true) unless options[:pretend] content = File.read(path) @@ -315,17 +309,16 @@ class Thor # ==== Parameters # path:: path of the file to be changed # data:: the data to append to the file, can be also given as a block. - # log_status:: if false, does not log the status. True by default. - # If a symbol is given, uses it as the output color. + # config:: give :verbose => false to not log the status. # # ==== Example # # append_file 'config/environments/test.rb', 'config.gem "rspec"' # - def append_file(path, data=nil, log_status=true, &block) + def append_file(path, data=nil, config={}, &block) return unless behavior == :invoke path = File.expand_path(path, destination_root) - say_status :append, relative_to_original_destination_root(path), log_status + say_status :append, relative_to_original_destination_root(path), config.fetch(:verbose, true) File.open(path, 'ab') { |file| file.write(data || block.call) } unless options[:pretend] end @@ -334,17 +327,16 @@ class Thor # ==== Parameters # path:: path of the file to be changed # data:: the data to prepend to the file, can be also given as a block. - # log_status:: if false, does not log the status. True by default. - # If a symbol is given, uses it as the output color. + # config:: give :verbose => false to not log the status. # # ==== Example # # prepend_file 'config/environments/test.rb', 'config.gem "rspec"' # - def prepend_file(path, data=nil, log_status=true, &block) + def prepend_file(path, data=nil, config={}, &block) return unless behavior == :invoke path = File.expand_path(path, destination_root) - say_status :prepend, relative_to_original_destination_root(path), log_status + say_status :prepend, relative_to_original_destination_root(path), config.fetch(:verbose, true) unless options[:pretend] content = data || block.call diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/copy_file.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/copy_file.rb index b9d2e9e0a7..bfbc38a367 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/copy_file.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/copy_file.rb @@ -7,9 +7,9 @@ class Thor # the destination is not given it's assumed to be equal to the source. # # ==== Parameters - # source:: the relative path to the source root - # destination:: the relative path to the destination root - # log_status:: if false, does not log the status. True by default. + # source:: the relative path to the source root. + # destination:: the relative path to the destination root. + # config:: give :verbose => false to not log the status. # # ==== Examples # @@ -17,8 +17,8 @@ class Thor # # copy_file "doc/README" # - def copy_file(source, destination=nil, log_status=true) - action CopyFile.new(self, source, destination || source, log_status) + def copy_file(source, destination=nil, config={}) + action CopyFile.new(self, source, destination || source, config) end class CopyFile < Templater #:nodoc: diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/create_file.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/create_file.rb index 2f3732247e..72bf34c0a3 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/create_file.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/create_file.rb @@ -9,7 +9,7 @@ class Thor # ==== Parameters # destination:: the relative path to the destination root. # data:: the data to append to the file. - # log_status:: if false, does not log the status. True by default. + # config:: give :verbose => false to not log the status. # # ==== Examples # @@ -20,8 +20,8 @@ class Thor # # create_file "config/apach.conf", "your apache config" # - def create_file(destination, data=nil, log_status=true, &block) - action CreateFile.new(self, destination, block || data.to_s, log_status) + def create_file(destination, data=nil, config={}, &block) + action CreateFile.new(self, destination, block || data.to_s, config) end alias :add_file :create_file @@ -31,8 +31,8 @@ class Thor class CreateFile < Templater #:nodoc: attr_reader :data - def initialize(base, destination, data, log_status) - super(base, nil, destination, log_status) + def initialize(base, destination, data, config={}) + super(base, nil, destination, config) @data = data end diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/directory.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/directory.rb index 134f13d1b7..2c6d2bc59b 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/directory.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/directory.rb @@ -30,30 +30,27 @@ class Thor # blog.rb # # ==== Parameters - # source:: the relative path to the source root - # destination:: the relative path to the destination root - # recursive:: if the directory must be copied recursively, true by default - # log_status:: if false, does not log the status. True by default. + # source:: the relative path to the source root. + # destination:: the relative path to the destination root. + # config:: give :verbose => false to not log the status. + # If :recursive => false, does not look for paths recursively. # # ==== Examples # # directory "doc" - # directory "doc", "docs", false + # directory "doc", "docs", :recursive => false # - def directory(source, destination=nil, recursive=true, log_status=true) - action Directory.new(self, source, destination || source, recursive, log_status) + def directory(source, destination=nil, config={}) + action Directory.new(self, source, destination || source, config) end class Directory < Templater #:nodoc: - attr_reader :recursive - - def initialize(base, source, destination=nil, recursive=true, log_status=true) - @recursive = recursive - super(base, source, destination, log_status) + def initialize(base, source, destination=nil, config={}) + super(base, source, destination, { :recursive => true }.merge(config)) end def invoke! - base.empty_directory given_destination, @log_status + base.empty_directory given_destination, config execute! end @@ -64,7 +61,7 @@ class Thor protected def execute! - lookup = recursive ? File.join(source, '**') : source + lookup = config[:recursive] ? File.join(source, '**') : source lookup = File.join(lookup, '{*,.[a-z]*}') Dir[lookup].each do |file_source| @@ -73,11 +70,11 @@ class Thor case file_source when /\.empty_directory$/ - base.empty_directory(File.dirname(file_destination), @log_status) + base.empty_directory(File.dirname(file_destination), config) when /\.tt$/ - base.template(file_source, file_destination[0..-4], @log_status) + base.template(file_source, file_destination[0..-4], config) else - base.copy_file(file_source, file_destination, @log_status) + base.copy_file(file_source, file_destination, config) end end end diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/empty_directory.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/empty_directory.rb index 3f29d52362..04f9817212 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/empty_directory.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/empty_directory.rb @@ -6,21 +6,21 @@ class Thor # Creates an empty directory. # # ==== Parameters - # destination:: the relative path to the destination root - # log_status:: if false, does not log the status. True by default. + # destination:: the relative path to the destination root. + # config:: give :verbose => false to not log the status. # # ==== Examples # # empty_directory "doc" # - def empty_directory(destination, log_status=true) - action EmptyDirectory.new(self, nil, destination, log_status) + def empty_directory(destination, config={}) + action EmptyDirectory.new(self, nil, destination, config) end class EmptyDirectory < Templater #:nodoc: def invoke! - invoke_with_options!(base.options) do + invoke_with_options!(base.options.merge(config)) do ::FileUtils.mkdir_p(destination) end end diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/get.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/get.rb index a0d12b8370..bd8deb8194 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/get.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/get.rb @@ -9,9 +9,9 @@ class Thor # the url is yielded and used as location. # # ==== Parameters - # source:: the address of the given content - # destination:: the relative path to the destination root - # log_status:: if false, does not log the status. True by default. + # source:: the address of the given content. + # destination:: the relative path to the destination root. + # config:: give :verbose => false to not log the status. # # ==== Examples # @@ -21,8 +21,8 @@ class Thor # content.split("\n").first # end # - def get(source, destination=nil, log_status=true, &block) - action Get.new(self, source, block || destination, log_status) + def get(source, destination=nil, config={}, &block) + action Get.new(self, source, block || destination, config) end class Get < Templater #:nodoc: diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/inject_into_file.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/inject_into_file.rb index c91bd96098..6bd0100a12 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/inject_into_file.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/inject_into_file.rb @@ -9,9 +9,8 @@ class Thor # ==== Parameters # destination:: Relative path to the destination root # data:: Data to add to the file. Can be given as a block. - # flag:: Flag of where to add the changes. - # log_status:: If false, does not log the status. True by default. - # If a symbol is given, uses it as the output color. + # config:: give :verbose => false to not log the status and the flag + # for injection (:after or :before). # # ==== Examples # @@ -24,28 +23,29 @@ class Thor # def inject_into_file(destination, *args, &block) if block_given? - data, flag = block, args.shift + data, config = block, args.shift else - data, flag = args.shift, args.shift + data, config = args.shift, args.shift end log_status = args.empty? || args.pop - action InjectIntoFile.new(self, destination, data, flag, log_status) + action InjectIntoFile.new(self, destination, data, config) end class InjectIntoFile #:nodoc: - attr_reader :base, :destination, :relative_destination, :flag, :replacement + attr_reader :base, :destination, :relative_destination, :flag, :replacement, :config - def initialize(base, destination, data, flag, log_status=true) - @base, @log_status = base, log_status - behavior, @flag = flag.keys.first, flag.values.first + def initialize(base, destination, data, config) + @base, @config = base, { :verbose => true }.merge(config) self.destination = destination data = data.call if data.is_a?(Proc) - @replacement = if behavior == :after + @replacement = if @config.key?(:after) + @flag = @config.delete(:after) @flag + data else + @flag = @config.delete(:before) data + @flag end end @@ -75,7 +75,7 @@ class Thor # Shortcut to say_status shell method. # def say_status(status) - base.shell.say_status status, relative_destination, @log_status + base.shell.say_status status, relative_destination, config[:verbose] end # Adds the content to the file. diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/template.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/template.rb index 6b2e50b8c5..95e2412514 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/template.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/template.rb @@ -9,9 +9,9 @@ class Thor # to be equal to the source removing .tt from the filename. # # ==== Parameters - # source:: the relative path to the source root - # destination:: the relative path to the destination root - # log_status:: if false, does not log the status. True by default. + # source:: the relative path to the source root. + # destination:: the relative path to the destination root. + # config:: give :verbose => false to not log the status. # # ==== Examples # @@ -19,9 +19,9 @@ class Thor # # template "doc/README" # - def template(source, destination=nil, log_status=true) + def template(source, destination=nil, config={}) destination ||= source.gsub(/.tt$/, '') - action Template.new(self, source, destination, log_status) + action Template.new(self, source, destination, config) end class Template < Templater #:nodoc: diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/templater.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/templater.rb index b4b7bae3af..455178c6e8 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/templater.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/templater.rb @@ -8,7 +8,7 @@ class Thor # by Jonas Nicklas and Michael S. Klishin under MIT LICENSE. # class Templater #:nodoc: - attr_reader :base, :source, :destination, :given_destination, :relative_destination + attr_reader :base, :source, :destination, :given_destination, :relative_destination, :config # Initializes given the source and destination. # @@ -16,11 +16,10 @@ class Thor # base:: A Thor::Base instance # source:: Relative path to the source of this file # destination:: Relative path to the destination of this file - # log_status:: If false, does not log the status. True by default. - # Templater log status does not accept color. + # config:: give :verbose => false to not log the status. # - def initialize(base, source, destination, log_status=true) - @base, @log_status = base, log_status + def initialize(base, source, destination, config={}) + @base, @config = base, { :verbose => true }.merge(config) self.source = source self.destination = destination end @@ -56,7 +55,7 @@ class Thor # but you can modify in the subclass. # def invoke! - invoke_with_options!(base.options) do + invoke_with_options!(base.options.merge(config)) do ::FileUtils.mkdir_p(::File.dirname(destination)) ::File.open(destination, 'w'){ |f| f.write render } end @@ -187,7 +186,7 @@ class Thor # Shortcut to say_status shell method. # def say_status(status, color) - base.shell.say_status status, relative_destination, color if @log_status + base.shell.say_status status, relative_destination, color if config[:verbose] end end -- cgit v1.2.3