Skip to content

Commit 5f52524

Browse files
committed
Refactoring the sh command a bit.
1 parent 34ddd30 commit 5f52524

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

lib/rake/file_utils.rb

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,9 @@ module FileUtils
2929
#
3030
def sh(*cmd, &block)
3131
options = (Hash === cmd.last) ? cmd.pop : {}
32-
unless block_given?
33-
show_command = cmd.join(" ")
34-
show_command = show_command[0,42] + "..." unless $trace
35-
# TODO code application logic heref show_command.length > 45
36-
block = lambda { |ok, status|
37-
ok or fail "Command failed with status (#{status.exitstatus}): [#{show_command}]"
38-
}
39-
end
32+
block = create_shell_command(cmd) unless block_given?
4033
set_verbose_option(options)
41-
options[:noop] ||= RakeFileUtils.nowrite_flag
34+
options[:noop] ||= RakeFileUtils.nowrite_flag
4235
rake_check_options options, :noop, :verbose
4336
rake_output_message cmd.join(" ") if options[:verbose]
4437
unless options[:noop]
@@ -49,11 +42,17 @@ def sh(*cmd, &block)
4942
end
5043
end
5144

45+
def create_shell_command(cmd)
46+
show_command = cmd.join(" ")
47+
show_command = show_command[0,42] + "..." unless $trace
48+
block = lambda { |ok, status|
49+
ok or fail "Command failed with status (#{status.exitstatus}): [#{show_command}]"
50+
}
51+
end
52+
5253
def set_verbose_option(options)
53-
if RakeFileUtils.verbose_flag.nil? && options[:verbose].nil?
54-
options[:verbose] = true
55-
elsif options[:verbose].nil?
56-
options[:verbose] ||= RakeFileUtils.verbose_flag
54+
if options[:verbose].nil?
55+
options[:verbose] = RakeFileUtils.verbose_flag.nil? || RakeFileUtils.verbose_flag
5756
end
5857
end
5958
private :set_verbose_option

0 commit comments

Comments
 (0)