Skip to content

Commit

Permalink
Bundle.system: better way to handle verbose
Browse files Browse the repository at this point in the history
Use Kernel.system instead of our own logic to handle verbose output.
This allows us to show progress bar for downloading.
  • Loading branch information
xu-cheng committed Jun 18, 2016
1 parent f3c2ed8 commit 94ca549
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions lib/bundle/utils.rb
@@ -1,18 +1,19 @@
module Bundle
def self.system(cmd, *args)
verbose = ARGV.verbose?
if ARGV.verbose?
return super cmd, *args
end
logs = []
success = nil
IO.popen([cmd, *args], :err => [:child, :out]) do |pipe|
while buf = pipe.gets
puts buf if verbose
logs << buf
end
Process.wait(pipe.pid)
success = $?.success?
pipe.close
end
puts logs.join unless success || verbose
puts logs.join unless success
success
end

Expand Down
8 changes: 4 additions & 4 deletions spec/utils_spec.rb
Expand Up @@ -4,12 +4,12 @@
context "system call succeed" do
it "omits all stdout output if ARGV.verbose? is false" do
allow(ARGV).to receive(:verbose?).and_return(false)
expect { Bundle.system "echo", "foo" }.to_not output.to_stdout
expect { Bundle.system "echo", "foo" }.to_not output.to_stdout_from_any_process
end

it "emits all stdout output if ARGV.verbose? is true" do
allow(ARGV).to receive(:verbose?).and_return(true)
expect { Bundle.system "echo", "foo" }.to output("foo\n").to_stdout
expect { Bundle.system "echo", "foo" }.to output("foo\n").to_stdout_from_any_process
end
end

Expand All @@ -20,12 +20,12 @@

it "emits all stdout output even if ARGV.verbose? is false" do
allow(ARGV).to receive(:verbose?).and_return(false)
expect { Bundle.system "echo", "foo" }.to output("foo\n").to_stdout
expect { Bundle.system "echo", "foo" }.to output("foo\n").to_stdout_from_any_process
end

it "emits all stdout output only once if ARGV.verbose? is true" do
allow(ARGV).to receive(:verbose?).and_return(true)
expect { Bundle.system "echo", "foo" }.to output("foo\n").to_stdout
expect { Bundle.system "echo", "foo" }.to output("foo\n").to_stdout_from_any_process
end
end

Expand Down

0 comments on commit 94ca549

Please sign in to comment.