Pregunta

I have a Rakefile which, on my own-built Ruby 1.9.3 installation, correctly outputs the Unix shell equivalent when I use a FileUtils method such as cp, mkdir etc.

However, on the stock Ruby that ships with Mac OS X (specifically 10.5), which is version 1.8.6, they don't do this.

I'd like them to output the commands as they're performed. Is there a way to enable this in OS X's 1.8.6 Ruby, short of adding :verbose => true to every call? (Which may not even work.)

The Rakefile in question is: https://github.com/dpkendal/tools-osx/blob/master/Rakefile

¿Fue útil?

Solución

That doesn't make sense. 1.9.3 should not do :verbose unless explicitly told to do so. You can look at the implementation of mkdir in the 1.9.3 lib for example:

  def mkdir(list, options = {})
    fu_check_options options, OPT_TABLE['mkdir']
    list = fu_list(list)
    fu_output_message "mkdir #{options[:mode] ? ('-m %03o ' % options[:mode]) : ''}#{list.join ' '}" if options[:verbose]
    return if options[:noop]

    list.each do |dir|
      fu_mkdir dir, options[:mode]
    end
  end

There you can see that the message is not generated unless the :verbose option is explicitly supplied.

However to enable :verbose across all FileUtils methods you can simply include FileUtils::Verbose into your namespace. This works in both 1.8 and 1.9 ruby:

irb(main):001:0> RUBY_VERSION
=> "1.8.7"
irb(main):002:0> include FileUtils::Verbose
=> Object
irb(main):003:0> mkdir 'fooof'
mkdir fooof
=> ["fooof"]

BTW, it might be that Rake already does this in 1.9.3, which would explain why it does what it does in 1.9.3 and not in 1.8.6. I did not check this, but that's the only explanation I can think of.


Rake provides its own FileUtils extension called Rake::FileUtilsExt. This module has a verbose flag. To activate it simply add this to the top of the Rakefile:

Rake::FileUtilsExt.verbose(true)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top