Skip to content

Commit 1abf0b9

Browse files
committed
Merge pull request Homebrew#6329 from rolandwalker/system_command_refactor
refactor Cask::SystemCommand
2 parents 109b52d + 0e7be24 commit 1abf0b9

21 files changed

+110
-93
lines changed

lib/cask/artifact/base.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def self.read_script_arguments(arguments, stanza, default_arguments={}, override
4545
end
4646

4747
# key sanity
48-
permitted_keys = [:args, :input, :executable, :must_succeed, :sudo, :print]
48+
permitted_keys = [:args, :input, :executable, :must_succeed, :sudo, :print_stdout, :print_stderr]
4949
unknown_keys = arguments.keys - permitted_keys
5050
unless unknown_keys.empty?
5151
opoo %Q{Unknown arguments to #{description} -- #{unknown_keys.inspect} (ignored). Running "brew update && brew upgrade brew-cask && brew cleanup && brew cask cleanup" will likely fix it.}

lib/cask/artifact/install_script.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def install_phase
1616
artifact,
1717
"#{self.class.artifact_dsl_key}",
1818
{:must_succeed => true},
19-
{:print => true}
19+
{:print_stdout => true}
2020
)
2121
ohai "Running #{self.class.artifact_dsl_key} script #{executable}"
2222
raise CaskInvalidError.new(@cask, "#{self.class.artifact_dsl_key} missing executable") if executable.nil?

lib/cask/artifact/pkg.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ def run_installer(pkg_description)
4848
]
4949
args << '-verboseR' if ARGV.verbose?
5050
args << '-allowUntrusted' if pkg_install_opts :allow_untrusted
51-
@command.run!('/usr/sbin/installer', {:sudo => true, :args => args, :print => true})
51+
@command.run!('/usr/sbin/installer', {:sudo => true, :args => args, :print_stdout => true})
5252
end
5353
end

lib/cask/artifact/symlinked.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ def add_altname_metadata(source, target)
2222
odebug "Adding #{attribute} metadata"
2323
altnames = @command.run('/usr/bin/xattr',
2424
:args => ['-p', attribute, target],
25-
:stderr => :silence).sub(/\A\((.*)\)\Z/, "#{$1}")
25+
:print_stderr => false).stdout.sub(/\A\((.*)\)\Z/, "#{$1}")
2626
odebug "Existing metadata is: '#{altnames}'"
2727
altnames.concat(', ') if altnames.length > 0
2828
altnames.concat(%Q{"#{target.basename}"})
2929
altnames = %Q{(#{altnames})}
3030
@command.run!('/usr/bin/xattr',
3131
:args => ['-w', attribute, altnames, target],
32-
:stderr => :silence)
32+
:print_stderr => false)
3333
end
3434

3535
def summary

lib/cask/artifact/uninstall_base.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def dispatch_uninstall_directives(stanza, expand_tilde=false)
5151
executable, script_arguments = self.class.read_script_arguments(directives,
5252
'uninstall',
5353
{:must_succeed => true},
54-
{:sudo => true, :print => true},
54+
{:sudo => true, :print_stdout => true},
5555
:early_script)
5656

5757
ohai "Running uninstall script #{executable}"
@@ -65,7 +65,7 @@ def dispatch_uninstall_directives(stanza, expand_tilde=false)
6565
Array(directives[:launchctl]).each do |service|
6666
ohai "Removing launchctl service #{service}"
6767
[false, true].each do |with_sudo|
68-
xml_status = @command.run('/bin/launchctl', :args => ['list', '-x', service], :sudo => with_sudo)
68+
xml_status = @command.run('/bin/launchctl', :args => ['list', '-x', service], :sudo => with_sudo).stdout
6969
if %r{^<\?xml}.match(xml_status)
7070
@command.run('/bin/launchctl', :args => ['unload', '-w', '--', service], :sudo => with_sudo)
7171
sleep 1
@@ -80,7 +80,7 @@ def dispatch_uninstall_directives(stanza, expand_tilde=false)
8080
directives_set.select{ |h| h.key?(:quit) }.each do |directives|
8181
Array(directives[:quit]).each do |id|
8282
ohai "Quitting application ID #{id}"
83-
num_running = @command.run!('/usr/bin/osascript', :args => ['-e', %Q{tell application "System Events" to count processes whose bundle identifier is "#{id}"}], :sudo => true).to_i
83+
num_running = @command.run!('/usr/bin/osascript', :args => ['-e', %Q{tell application "System Events" to count processes whose bundle identifier is "#{id}"}], :sudo => true).stdout.to_i
8484
if num_running > 0
8585
@command.run!('/usr/bin/osascript', :args => ['-e', %Q{tell application id "#{id}" to quit}], :sudo => true)
8686
sleep 3
@@ -94,7 +94,7 @@ def dispatch_uninstall_directives(stanza, expand_tilde=false)
9494
raise CaskInvalidError.new(@cask, "Each #{stanza} :signal must have 2 elements.") unless pair.length == 2
9595
signal, id = pair
9696
ohai "Signalling '#{signal}' to application ID '#{id}'"
97-
pid_string = @command.run!('/usr/bin/osascript', :args => ['-e', %Q{tell application "System Events" to get the unix id of every process whose bundle identifier is "#{id}"}], :sudo => true)
97+
pid_string = @command.run!('/usr/bin/osascript', :args => ['-e', %Q{tell application "System Events" to get the unix id of every process whose bundle identifier is "#{id}"}], :sudo => true).stdout
9898
if pid_string.match(%r{\A\d+(?:\s*,\s*\d+)*\Z}) # sanity check
9999
pids = pid_string.split(%r{\s*,\s*}).map(&:strip).map(&:to_i)
100100
if pids.length > 0
@@ -116,7 +116,7 @@ def dispatch_uninstall_directives(stanza, expand_tilde=false)
116116
directives_set.select{ |h| h.key?(:kext) }.each do |directives|
117117
Array(directives[:kext]).each do |kext|
118118
ohai "Unloading kernel extension #{kext}"
119-
is_loaded = @command.run!('/usr/sbin/kextstat', :args => ['-l', '-b', kext], :sudo => true)
119+
is_loaded = @command.run!('/usr/sbin/kextstat', :args => ['-l', '-b', kext], :sudo => true).stdout
120120
if is_loaded.length > 1
121121
@command.run!('/sbin/kextunload', :args => ['-b', '--', kext], :sudo => true)
122122
sleep 1
@@ -129,7 +129,7 @@ def dispatch_uninstall_directives(stanza, expand_tilde=false)
129129
executable, script_arguments = self.class.read_script_arguments(directives,
130130
'uninstall',
131131
{:must_succeed => true},
132-
{:sudo => true, :print => true},
132+
{:sudo => true, :print_stdout => true},
133133
:script)
134134
raise CaskInvalidError.new(@cask, "#{stanza} :script without :executable.") if executable.nil?
135135
@command.run(@cask.destination_path.join(executable), script_arguments)
@@ -185,10 +185,10 @@ def dispatch_uninstall_directives(stanza, expand_tilde=false)
185185
next unless directory.exist?
186186
@command.run!('/bin/rm', :args => [ '-f', '--', directory.join('.DS_Store') ],
187187
:sudo => true,
188-
:stderr => :silence)
188+
:print_stderr => false)
189189
@command.run('/bin/rmdir', :args => [ '--', directory ],
190190
:sudo => true,
191-
:stderr => :silence)
191+
:print_stderr => false)
192192
end
193193
end
194194
end

lib/cask/cli/alfred.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def self.alfred_primary_preference(key, value=nil)
154154
@system_command.run('/usr/bin/defaults', :args => ['write', PRIMARY_DOMAIN, key, value.to_s])
155155
else
156156
odebug 'Reading Alfred primary preferences'
157-
@system_command.run('/usr/bin/defaults', :args => ['read', PRIMARY_DOMAIN, key])
157+
@system_command.run('/usr/bin/defaults', :args => ['read', PRIMARY_DOMAIN, key]).stdout
158158
end
159159
end
160160

@@ -168,7 +168,7 @@ def self.alfred_file_preference(files, key, value=nil)
168168
@system_command.run('/usr/bin/defaults', :args => ['write', file, key, value.to_s])
169169
else
170170
odebug 'Reading Alfred local preferences'
171-
@system_command.run('/usr/bin/defaults', :args => ['read', file, key])
171+
@system_command.run('/usr/bin/defaults', :args => ['read', file, key]).stdout
172172
end
173173
# hack/limitation: if there happen to be multiple local preference
174174
# files, we only return the value from the first one.

lib/cask/cli/doctor.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def self.homebrew_origin
6565
HOMEBREW_REPOSITORY.cd do
6666
homebrew_origin = Cask::SystemCommand.run('git',
6767
:args => %w{config --get remote.origin.url},
68-
:stderr => :silence).strip
68+
:print_stderr => false).stdout.strip
6969
end
7070
if homebrew_origin !~ %r{\S}
7171
homebrew_origin = "#{none_string} #{error_string}"

lib/cask/cli/list.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def self.list_installed
5454
if @options[:one]
5555
puts columns
5656
elsif @options[:long]
57-
puts Cask::SystemCommand.run!("/bin/ls", :args => ["-l", Cask.caskroom])
57+
puts Cask::SystemCommand.run!("/bin/ls", :args => ["-l", Cask.caskroom]).stdout
5858
else
5959
puts_columns columns
6060
end

lib/cask/container/criteria.rb

+7-10
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,25 @@ def initialize(path, command)
77
end
88

99
def file
10-
@file ||= @command.run('/usr/bin/file', :args => ['-Izb', '--', path])
10+
@file ||= @command.run('/usr/bin/file', :args => ['-Izb', '--', path]).stdout
1111
end
1212

1313
def imageinfo
1414
@imageinfo ||= @command.run(
1515
'/usr/bin/hdiutil',
1616
# realpath is a failsafe against unusual filenames
1717
:args => ['imageinfo', Pathname.new(path).realpath],
18-
:stderr => :silence,
19-
:print => false
20-
)
18+
:print_stderr => false
19+
).stdout
2120
end
2221

2322
def cabextract
2423
if HOMEBREW_PREFIX.join('bin/cabextract').exist?
2524
@cabextract ||= @command.run(
2625
HOMEBREW_PREFIX.join('bin/cabextract'),
2726
:args => ['-t', '--', path],
28-
:stderr => :silence,
29-
:print => false
30-
)
27+
:print_stderr => false
28+
).stdout
3129
end
3230
end
3331

@@ -36,9 +34,8 @@ def lsar
3634
@lsar ||= @command.run(
3735
HOMEBREW_PREFIX.join('bin/lsar'),
3836
:args => ['-l', '-t', '--', path],
39-
:stderr => :silence,
40-
:print => false
41-
)
37+
:print_stderr => false
38+
).stdout
4239
end
4340
end
4441

lib/cask/container/dmg.rb

+7-8
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ def mount!
2323
plist = @command.run('/usr/bin/hdiutil',
2424
# realpath is a failsafe against unusual filenames
2525
:args => %w[mount -plist -nobrowse -readonly -noidme -mountrandom /tmp] + [Pathname.new(@path).realpath],
26-
:input => %w[y],
27-
:plist => true
28-
)
26+
:input => %w[y]
27+
).plist
2928
@mounts = mounts_from_plist(plist)
3029
end
3130

@@ -38,7 +37,7 @@ def mounts_from_plist(plist)
3837

3938
def assert_mounts_found
4039
if @mounts.empty?
41-
raise CaskError.new "No mounts found in '#{@path}'; perhaps it is a bad DMG?"
40+
raise CaskError.new %Q{No mounts found in '#{@path}'; perhaps it is a bad DMG?}
4241
end
4342
end
4443

@@ -48,13 +47,13 @@ def eject!
4847
mountpath = Pathname.new(mount).realpath
4948
next unless mountpath.exist?
5049
@command.run('/usr/sbin/diskutil',
51-
:args => ['eject', mountpath],
52-
:stderr => :silence)
50+
:args => ['eject', mountpath],
51+
:print_stderr => false)
5352
next unless mountpath.exist?
5453
sleep 1
5554
@command.run('/usr/sbin/diskutil',
56-
:args => ['eject', mountpath],
57-
:stderr => :silence)
55+
:args => ['eject', mountpath],
56+
:print_stderr => false)
5857
next unless mountpath.exist?
5958
raise CaskError.new "Failed to eject #{mountpath}"
6059
end

lib/cask/download_strategy.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def fetch_repo target, url, revision=cask_url.revision, ignore_externals=false
138138
args << '--ignore-externals' if ignore_externals
139139
@command.run!('/usr/bin/svn',
140140
:args => args,
141-
:stderr => :silence)
141+
:print_stderr => false)
142142
end
143143

144144
def tarball_path
@@ -165,7 +165,7 @@ def tarball_path
165165
def compress
166166
Dir.chdir(cached_location) do
167167
@command.run!('/usr/bin/tar', :args => ['-s/^\.//', '--exclude', '.svn', '-cf', Pathname.new(tarball_path), '--', '.'],
168-
:stderr => :silence)
168+
:print_stderr => false)
169169
end
170170
clear_cache
171171
end

lib/cask/fetcher.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def self.head(url)
88
googlecode_fake_head(url)
99
else
1010
Cask::SystemCommand.run("curl",
11-
:args => ["--max-time", TIMEOUT, "--silent", "--location", "--head", url])
11+
:args => ["--max-time", TIMEOUT, "--silent", "--location", "--head", url])
1212
end
1313
end
1414

lib/cask/installer.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def formula_dependencies
106106
print "#{dep_name} ... "
107107
installed = @command.run(HOMEBREW_BREW_FILE,
108108
:args => ['list', '--versions', dep_name],
109-
:stderr => :silence).include?(dep_name)
109+
:print_stderr => false).stdout.include?(dep_name)
110110
if installed
111111
puts "already installed"
112112
else

lib/cask/pkg.rb

+6-7
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ class Cask::Pkg
227227
].map{|x| Pathname.new(x)}
228228

229229
def self.all_matching(regexp, command)
230-
command.run('/usr/sbin/pkgutil', :args => [%Q{--pkgs=#{regexp}}]).split("\n").map do |package_id|
230+
command.run('/usr/sbin/pkgutil', :args => [%Q{--pkgs=#{regexp}}]).stdout.split("\n").map do |package_id|
231231
new(package_id.chomp, command)
232232
end
233233
end
@@ -269,19 +269,19 @@ def forget
269269
def pkgutil_bom_files
270270
@command.run!('/usr/sbin/pkgutil',
271271
:args => ['--only-files', '--files', package_id]
272-
).split("\n").map { |path| root.join(path) }
272+
).stdout.split("\n").map { |path| root.join(path) }
273273
end
274274

275275
def pkgutil_bom_dirs
276276
@command.run!('/usr/sbin/pkgutil',
277277
:args => ['--only-dirs', '--files', package_id]
278-
).split("\n").map { |path| root.join(path) }
278+
).stdout.split("\n").map { |path| root.join(path) }
279279
end
280280

281281
def pkgutil_bom_all
282282
@command.run!('/usr/sbin/pkgutil',
283283
:args => ['--files', package_id]
284-
).split("\n").map { |path| root.join(path) }
284+
).stdout.split("\n").map { |path| root.join(path) }
285285
end
286286

287287
def pkgutil_bom_specials
@@ -294,9 +294,8 @@ def root
294294

295295
def info
296296
@command.run!('/usr/sbin/pkgutil',
297-
:args => ['--pkg-info-plist', package_id],
298-
:plist => true
299-
)
297+
:args => ['--pkg-info-plist', package_id]
298+
).plist
300299
end
301300

302301
def _rmdir(path)

0 commit comments

Comments
 (0)