Merge pull request #8624 from nandahkrishna/tty-fix
utils/tty: handling a TTY stderr
This commit is contained in:
commit
13d14e64cd
@ -256,7 +256,7 @@ class Tap
|
|||||||
return if !full_clone || !shallow?
|
return if !full_clone || !shallow?
|
||||||
end
|
end
|
||||||
|
|
||||||
ohai "Unshallowing #{name}" unless quiet
|
$stderr.ohai "Unshallowing #{name}" unless quiet
|
||||||
args = %w[fetch --unshallow]
|
args = %w[fetch --unshallow]
|
||||||
args << "-q" if quiet
|
args << "-q" if quiet
|
||||||
path.cd { safe_system "git", *args }
|
path.cd { safe_system "git", *args }
|
||||||
@ -265,7 +265,7 @@ class Tap
|
|||||||
|
|
||||||
clear_cache
|
clear_cache
|
||||||
|
|
||||||
ohai "Tapping #{name}" unless quiet
|
$stderr.ohai "Tapping #{name}" unless quiet
|
||||||
args = %W[clone #{requested_remote} #{path}]
|
args = %W[clone #{requested_remote} #{path}]
|
||||||
args << "--depth=1" unless full_clone
|
args << "--depth=1" unless full_clone
|
||||||
args << "-q" if quiet
|
args << "-q" if quiet
|
||||||
@ -291,7 +291,7 @@ class Tap
|
|||||||
link_completions_and_manpages
|
link_completions_and_manpages
|
||||||
|
|
||||||
formatted_contents = contents.presence&.to_sentence&.dup&.prepend(" ")
|
formatted_contents = contents.presence&.to_sentence&.dup&.prepend(" ")
|
||||||
puts "Tapped#{formatted_contents} (#{path.abv})." unless quiet
|
$stderr.puts "Tapped#{formatted_contents} (#{path.abv})." unless quiet
|
||||||
CacheStoreDatabase.use(:descriptions) do |db|
|
CacheStoreDatabase.use(:descriptions) do |db|
|
||||||
DescriptionCacheStore.new(db)
|
DescriptionCacheStore.new(db)
|
||||||
.update_from_formula_names!(formula_names)
|
.update_from_formula_names!(formula_names)
|
||||||
@ -301,7 +301,7 @@ class Tap
|
|||||||
return unless private?
|
return unless private?
|
||||||
return if quiet
|
return if quiet
|
||||||
|
|
||||||
puts <<~EOS
|
$stderr.puts <<~EOS
|
||||||
It looks like you tapped a private repository. To avoid entering your
|
It looks like you tapped a private repository. To avoid entering your
|
||||||
credentials each time you update, you can use git HTTP credential
|
credentials each time you update, you can use git HTTP credential
|
||||||
caching or issue the following command:
|
caching or issue the following command:
|
||||||
@ -321,7 +321,7 @@ class Tap
|
|||||||
require "descriptions"
|
require "descriptions"
|
||||||
raise TapUnavailableError, name unless installed?
|
raise TapUnavailableError, name unless installed?
|
||||||
|
|
||||||
puts "Untapping #{name}..."
|
$stderr.puts "Untapping #{name}..."
|
||||||
|
|
||||||
abv = path.abv
|
abv = path.abv
|
||||||
formatted_contents = contents.presence&.to_sentence&.dup&.prepend(" ")
|
formatted_contents = contents.presence&.to_sentence&.dup&.prepend(" ")
|
||||||
@ -335,7 +335,7 @@ class Tap
|
|||||||
Utils::Link.unlink_completions(path)
|
Utils::Link.unlink_completions(path)
|
||||||
path.rmtree
|
path.rmtree
|
||||||
path.parent.rmdir_if_possible
|
path.parent.rmdir_if_possible
|
||||||
puts "Untapped#{formatted_contents} (#{abv})."
|
$stderr.puts "Untapped#{formatted_contents} (#{abv})."
|
||||||
|
|
||||||
Commands.rebuild_commands_completion_list
|
Commands.rebuild_commands_completion_list
|
||||||
clear_cache
|
clear_cache
|
||||||
@ -625,7 +625,9 @@ class CoreTap < Tap
|
|||||||
|
|
||||||
def install(full_clone: true, quiet: false, clone_target: nil, force_auto_update: nil)
|
def install(full_clone: true, quiet: false, clone_target: nil, force_auto_update: nil)
|
||||||
remote = Homebrew::EnvConfig.core_git_remote
|
remote = Homebrew::EnvConfig.core_git_remote
|
||||||
puts "HOMEBREW_CORE_GIT_REMOTE set: using #{remote} for Homebrew/core Git remote URL." if remote != default_remote
|
if remote != default_remote
|
||||||
|
$stderr.puts "HOMEBREW_CORE_GIT_REMOTE set: using #{remote} for Homebrew/core Git remote URL."
|
||||||
|
end
|
||||||
super(full_clone: full_clone, quiet: quiet, clone_target: remote, force_auto_update: force_auto_update)
|
super(full_clone: full_clone, quiet: quiet, clone_target: remote, force_auto_update: force_auto_update)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -11,8 +11,7 @@ describe "brew tap", :integration_test do
|
|||||||
path = setup_test_tap
|
path = setup_test_tap
|
||||||
|
|
||||||
expect { brew "tap", "--force-auto-update", "--full", "homebrew/bar", path/".git" }
|
expect { brew "tap", "--force-auto-update", "--full", "homebrew/bar", path/".git" }
|
||||||
.to output(/Tapped/).to_stdout
|
.to output(/Tapped/).to_stderr
|
||||||
.and output(/Cloning/).to_stderr
|
|
||||||
.and be_a_success
|
.and be_a_success
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -11,8 +11,8 @@ describe "brew untap", :integration_test do
|
|||||||
setup_test_tap
|
setup_test_tap
|
||||||
|
|
||||||
expect { brew "untap", "homebrew/foo" }
|
expect { brew "untap", "homebrew/foo" }
|
||||||
.to output(/Untapped/).to_stdout
|
.to output(/Untapped/).to_stderr
|
||||||
.and not_to_output.to_stderr
|
.and not_to_output.to_stdout
|
||||||
.and be_a_success
|
.and be_a_success
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -131,11 +131,15 @@ module Kernel
|
|||||||
|
|
||||||
# Print a warning (do this rarely)
|
# Print a warning (do this rarely)
|
||||||
def opoo(message)
|
def opoo(message)
|
||||||
$stderr.puts Formatter.warning(message, label: "Warning")
|
Tty.with($stderr) do |stderr|
|
||||||
|
stderr.puts Formatter.warning(message, label: "Warning")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def onoe(message)
|
def onoe(message)
|
||||||
$stderr.puts Formatter.error(message, label: "Error")
|
Tty.with($stderr) do |stderr|
|
||||||
|
stderr.puts Formatter.error(message, label: "Error")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def ofail(error)
|
def ofail(error)
|
||||||
|
@ -4,8 +4,19 @@
|
|||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
module Tty
|
module Tty
|
||||||
|
@stream = $stdout
|
||||||
|
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
|
def with(stream)
|
||||||
|
previous_stream = @stream
|
||||||
|
@stream = stream
|
||||||
|
|
||||||
|
yield stream
|
||||||
|
ensure
|
||||||
|
@stream = previous_stream
|
||||||
|
end
|
||||||
|
|
||||||
def strip_ansi(string)
|
def strip_ansi(string)
|
||||||
string.gsub(/\033\[\d+(;\d+)*m/, "")
|
string.gsub(/\033\[\d+(;\d+)*m/, "")
|
||||||
end
|
end
|
||||||
@ -78,6 +89,6 @@ module Tty
|
|||||||
return false if Homebrew::EnvConfig.no_color?
|
return false if Homebrew::EnvConfig.no_color?
|
||||||
return true if Homebrew::EnvConfig.color?
|
return true if Homebrew::EnvConfig.color?
|
||||||
|
|
||||||
$stdout.tty?
|
@stream.tty?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user