Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Don't print LOCAL/REMOTE on gem query if stdout is not a TTY.

git-svn-id: http://rubygems.rubyforge.org/svn/trunk@1835 3d4018f9-ac1a-0410-99e9-8a154d859a19
  • Loading branch information...
commit a1cd0f559aef1eeba17ea5f7a5b98b680e3ecee5 1 parent 75e700f
drbrain authored
View
2  ChangeLog
@@ -5,6 +5,8 @@
DependencyInstaller's source_index so reinstallation via -i does not
fail.
* lib/rubygems/uninstaller.rb: Add #gem_home, #bin_dir for hooks.
+ * lib/rubygems/commands/query_command.rb: Don't print LOCAL/REMOTE
+ gems if stdout is not a TTY.
2008-06-30 Eric Hodel <drbrain@segment7.net>
View
16 lib/rubygems/commands/query_command.rb
@@ -70,9 +70,11 @@ def execute
end
if local? then
- say
- say "*** LOCAL GEMS ***"
- say
+ if ui.outs.tty? then
+ say
+ say "*** LOCAL GEMS ***"
+ say
+ end
specs = Gem.source_index.search name
@@ -84,9 +86,11 @@ def execute
end
if remote? then
- say
- say "*** REMOTE GEMS ***"
- say
+ if ui.outs.tty? then
+ say
+ say "*** REMOTE GEMS ***"
+ say
+ end
all = options[:all]
View
24 test/mockgemui.rb
@@ -12,8 +12,28 @@
class MockGemUi < Gem::StreamUI
class TermError < RuntimeError; end
- def initialize(input="")
- super(StringIO.new(input), StringIO.new, StringIO.new)
+ module TTY
+
+ attr_accessor :tty
+
+ def tty?()
+ @tty = true if @tty.nil?
+ @tty
+ end
+
+ end
+
+ def initialize(input = "")
+ ins = StringIO.new input
+ outs = StringIO.new
+ errs = StringIO.new
+
+ ins.extend TTY
+ outs.extend TTY
+ errs.extend TTY
+
+ super ins, outs, errs
+
@terminated = false
end
View
39 test/test_gem_commands_query_command.rb
@@ -265,6 +265,27 @@ def test_execute_local_details
assert_equal '', @ui.error
end
+ def test_execute_local_notty
+ @cmd.handle_options %w[]
+
+ @ui.outs.tty = false
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ expected = <<-EOF
+a (2, 1)
+a_evil (9)
+b (2)
+c (1.2)
+pl (1)
+ EOF
+
+ assert_equal expected, @ui.output
+ assert_equal '', @ui.error
+ end
+
def test_execute_no_versions
@cmd.handle_options %w[-r --no-versions]
@@ -284,5 +305,23 @@ def test_execute_no_versions
assert_equal '', @ui.error
end
+ def test_execute_notty
+ @cmd.handle_options %w[-r]
+
+ @ui.outs.tty = false
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ expected = <<-EOF
+a (2)
+pl (1)
+ EOF
+
+ assert_equal expected, @ui.output
+ assert_equal '', @ui.error
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.