From 3e608ca7802fbefec1858064209b29f83c711715 Mon Sep 17 00:00:00 2001 From: schneems Date: Mon, 2 Jul 2018 20:35:14 -0500 Subject: [PATCH 1/4] Colorize buildpack failures --- bin/support/ruby_compile | 11 +---------- bin/support/ruby_test-compile | 12 ++---------- lib/language_pack/shell_helpers.rb | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/bin/support/ruby_compile b/bin/support/ruby_compile index 2ab37427d..fe82b57b0 100755 --- a/bin/support/ruby_compile +++ b/bin/support/ruby_compile @@ -22,14 +22,5 @@ begin end end rescue Exception => e - Kernel.puts " !" - e.message.split("\n").each do |line| - Kernel.puts " ! #{line.strip}" - end - Kernel.puts " !" - if e.is_a?(BuildpackError) - exit 1 - else - raise e - end + LanguagePack::ShellHelpers.display_error_and_exit(e) end diff --git a/bin/support/ruby_test-compile b/bin/support/ruby_test-compile index 34e59463e..81b007c01 100755 --- a/bin/support/ruby_test-compile +++ b/bin/support/ruby_test-compile @@ -16,6 +16,7 @@ $:.unshift File.expand_path("../../../lib", __FILE__) require "language_pack" require "language_pack/shell_helpers" require "language_pack/test" +include LanguagePack::ShellHelpers begin LanguagePack::Instrument.trace 'test_compile', 'app.test_compile' do @@ -28,14 +29,5 @@ begin end end rescue Exception => e - Kernel.puts " !" - e.message.split("\n").each do |line| - Kernel.puts " ! #{line.strip}" - end - Kernel.puts " !" - if e.is_a?(BuildpackError) - exit 1 - else - raise e - end + LanguagePack::ShellHelpers.display_error_and_exit(e) end diff --git a/lib/language_pack/shell_helpers.rb b/lib/language_pack/shell_helpers.rb index f9992bb9d..9c9d36539 100644 --- a/lib/language_pack/shell_helpers.rb +++ b/lib/language_pack/shell_helpers.rb @@ -62,6 +62,22 @@ def self.initialize_env(path) end end + # Should only be used once in the top level script + # for example $ bin/support/ruby_compile + def self.display_error_and_exit(e) + Kernel.puts "\e[1m\e[31m" + Kernel.puts " !" + e.message.split("\n").each do |line| + Kernel.puts " ! #{line.strip}" + end + Kernel.puts " !\e[0m" + if e.is_a?(BuildpackError) + exit 1 + else + raise e + end + end + # run a shell command (deferring to #run), and raise an error if it fails # @param [String] command to be run # @return [String] result of #run From 451f9d53f7852c50ec0fcf2062afef622c412640 Mon Sep 17 00:00:00 2001 From: schneems Date: Mon, 2 Jul 2018 20:49:57 -0500 Subject: [PATCH 2/4] Warn yellow --- lib/language_pack/base.rb | 3 ++- lib/language_pack/shell_helpers.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/language_pack/base.rb b/lib/language_pack/base.rb index 82e38e316..3b758bd99 100644 --- a/lib/language_pack/base.rb +++ b/lib/language_pack/base.rb @@ -81,7 +81,7 @@ def default_process_types def compile write_release_yaml instrument 'base.compile' do - Kernel.puts "" + Kernel.puts "\e[1m\e[33m" # Bold yellow warnings.each do |warning| Kernel.puts "###### WARNING:\n" puts warning @@ -91,6 +91,7 @@ def compile topic "DEPRECATIONS:" puts @deprecations.join("\n") end + Kernel.puts "\e[0m" end mcount "success" end diff --git a/lib/language_pack/shell_helpers.rb b/lib/language_pack/shell_helpers.rb index 9c9d36539..4d9e8e2a1 100644 --- a/lib/language_pack/shell_helpers.rb +++ b/lib/language_pack/shell_helpers.rb @@ -65,7 +65,7 @@ def self.initialize_env(path) # Should only be used once in the top level script # for example $ bin/support/ruby_compile def self.display_error_and_exit(e) - Kernel.puts "\e[1m\e[31m" + Kernel.puts "\e[1m\e[31m" # Bold Red Kernel.puts " !" e.message.split("\n").each do |line| Kernel.puts " ! #{line.strip}" From 65cf344b74c1b9a891b068db9155b64c68d344a2 Mon Sep 17 00:00:00 2001 From: schneems Date: Tue, 3 Jul 2018 12:53:43 -0500 Subject: [PATCH 3/4] Make inline warnings yellow too. --- lib/language_pack/shell_helpers.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/language_pack/shell_helpers.rb b/lib/language_pack/shell_helpers.rb index 4d9e8e2a1..d4d6ee39e 100644 --- a/lib/language_pack/shell_helpers.rb +++ b/lib/language_pack/shell_helpers.rb @@ -259,9 +259,10 @@ def puts(message) def warn(message, options = {}) if options.key?(:inline) ? options[:inline] : false - Kernel.puts "###### WARNING:" + Kernel.puts "\e[1m\e[33m" # Bold yellow + Kernel.puts "###### WARNING:\n" puts message - Kernel.puts "" + Kernel.puts "\e[0m" end warnings << message end From c81a2422c0548ee435c1180ced4d233929b7d94a Mon Sep 17 00:00:00 2001 From: schneems Date: Tue, 3 Jul 2018 14:13:10 -0500 Subject: [PATCH 4/4] Only highlight warning header --- lib/language_pack/base.rb | 7 ++++--- lib/language_pack/shell_helpers.rb | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/language_pack/base.rb b/lib/language_pack/base.rb index 3b758bd99..f95287388 100644 --- a/lib/language_pack/base.rb +++ b/lib/language_pack/base.rb @@ -81,9 +81,10 @@ def default_process_types def compile write_release_yaml instrument 'base.compile' do - Kernel.puts "\e[1m\e[33m" # Bold yellow + Kernel.puts "" warnings.each do |warning| - Kernel.puts "###### WARNING:\n" + Kernel.puts "\e[1m\e[33m###### WARNING:\e[0m"# Bold yellow + Kernel.puts "" puts warning Kernel.puts "" end @@ -91,7 +92,7 @@ def compile topic "DEPRECATIONS:" puts @deprecations.join("\n") end - Kernel.puts "\e[0m" + Kernel.puts "" end mcount "success" end diff --git a/lib/language_pack/shell_helpers.rb b/lib/language_pack/shell_helpers.rb index d4d6ee39e..52ab522d4 100644 --- a/lib/language_pack/shell_helpers.rb +++ b/lib/language_pack/shell_helpers.rb @@ -259,10 +259,11 @@ def puts(message) def warn(message, options = {}) if options.key?(:inline) ? options[:inline] : false - Kernel.puts "\e[1m\e[33m" # Bold yellow - Kernel.puts "###### WARNING:\n" + Kernel.puts "" + Kernel.puts "\e[1m\e[33m###### WARNING:\e[0m" # Bold yellow + Kernel.puts "" puts message - Kernel.puts "\e[0m" + Kernel.puts "" end warnings << message end