Skip to content

Instantly share code, notes, and snippets.

@rfdonnelly
Created January 13, 2019 00:55
Show Gist options
  • Save rfdonnelly/2e227f3c08a32837bbbe5c94eeecf35f to your computer and use it in GitHub Desktop.
Save rfdonnelly/2e227f3c08a32837bbbe5c94eeecf35f to your computer and use it in GitHub Desktop.
Rake output customization
# Rake output customization example
#
# Rake has two sources of output:
# * Rake::FileUtilsExt::rake_output_message
# * FileUtils::fu_output_message
#
# We can customize Rake output by monkey patching these methods. This example
# monkey patches these methods to pass the message to our transform_message
# method then passing the output to the original output method.
def transform_message(*args)
prefix = 'rake: '
"\e[%dm%s%s\e[0m" % [1, prefix, args.join(' ')]
end
module Rake
module FileUtilsExt
alias :real_rake_output_message :rake_output_message
def rake_output_message(*args, &block)
real_rake_output_message(transform_message(*args), &block)
end
end
end
module FileUtils
alias :real_fu_output_message :fu_output_message
def fu_output_message(msg)
real_fu_output_message transform_message(msg)
end
end
task :default do
touch 'file'
sh 'echo hello world'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment