Merge pull request #407 from hcatlin/master
Actions should obey options[:quiet]
This commit is contained in:
commit
47ad8f17aa
@ -17,13 +17,14 @@ module Compass
|
|||||||
# create a directory and all the directories necessary to reach it.
|
# create a directory and all the directories necessary to reach it.
|
||||||
def directory(dir, options = nil)
|
def directory(dir, options = nil)
|
||||||
options ||= self.options if self.respond_to?(:options)
|
options ||= self.options if self.respond_to?(:options)
|
||||||
|
options ||= {}
|
||||||
if File.exists?(dir) && File.directory?(dir)
|
if File.exists?(dir) && File.directory?(dir)
|
||||||
# logger.record :exists, basename(dir) unless options[:quiet]
|
# logger.record :exists, basename(dir) unless options[:quiet]
|
||||||
elsif File.exists?(dir)
|
elsif File.exists?(dir)
|
||||||
msg = "#{basename(dir)} already exists and is not a directory."
|
msg = "#{basename(dir)} already exists and is not a directory."
|
||||||
raise Compass::FilesystemConflict.new(msg)
|
raise Compass::FilesystemConflict.new(msg)
|
||||||
else
|
else
|
||||||
logger.record :directory, separate("#{basename(dir)}/")
|
logger.record(:directory, separate("#{basename(dir)}/")) unless options[:quiet]
|
||||||
FileUtils.mkdir_p(dir) unless options[:dry_run]
|
FileUtils.mkdir_p(dir) unless options[:dry_run]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -37,16 +38,16 @@ module Compass
|
|||||||
if File.exists?(file_name)
|
if File.exists?(file_name)
|
||||||
existing_contents = IO.read(file_name)
|
existing_contents = IO.read(file_name)
|
||||||
if existing_contents == contents
|
if existing_contents == contents
|
||||||
logger.record :identical, basename(file_name), extra
|
logger.record(:identical, basename(file_name), extra) unless options[:quiet]
|
||||||
skip_write = true
|
skip_write = true
|
||||||
elsif options[:force]
|
elsif options[:force]
|
||||||
logger.record :overwrite, basename(file_name), extra
|
logger.record(:overwrite, basename(file_name), extra) unless options[:quiet]
|
||||||
else
|
else
|
||||||
msg = "File #{basename(file_name)} already exists. Run with --force to force overwrite."
|
msg = "File #{basename(file_name)} already exists. Run with --force to force overwrite."
|
||||||
raise Compass::FilesystemConflict.new(msg)
|
raise Compass::FilesystemConflict.new(msg)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
logger.record :create, basename(file_name), extra
|
logger.record(:create, basename(file_name), extra) unless options[:quiet]
|
||||||
end
|
end
|
||||||
if skip_write
|
if skip_write
|
||||||
FileUtils.touch file_name unless options[:dry_run]
|
FileUtils.touch file_name unless options[:dry_run]
|
||||||
@ -67,7 +68,7 @@ module Compass
|
|||||||
def remove(file_name)
|
def remove(file_name)
|
||||||
if File.exists?(file_name)
|
if File.exists?(file_name)
|
||||||
File.unlink file_name
|
File.unlink file_name
|
||||||
logger.record :remove, basename(file_name)
|
logger.record(:remove, basename(file_name)) unless options[:quiet]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
24
test/units/actions_test.rb
Normal file
24
test/units/actions_test.rb
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
require 'compass'
|
||||||
|
|
||||||
|
class ActionsTest < Test::Unit::TestCase
|
||||||
|
class BaseActionExtender
|
||||||
|
include Compass::Actions
|
||||||
|
def options
|
||||||
|
@@options ||= {}
|
||||||
|
end
|
||||||
|
def working_path
|
||||||
|
"/tmp"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# When log4r is included, it sometimes breaks the Actions
|
||||||
|
def test_quiet_option
|
||||||
|
b = BaseActionExtender.new
|
||||||
|
b.logger = ""
|
||||||
|
b.options[:quiet] = true
|
||||||
|
|
||||||
|
# logger shouldn't be called... if it is, this will error
|
||||||
|
b.directory("/tmp/#{(rand * 1000000).to_i}")
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user