Skip to content

Actions

Yuji Hanamura edited this page Aug 20, 2018 · 8 revisions

Thor comes with several actions that help with script and generator tasks. You might be familiar with them since some came from Rails Templates. They are: say, ask, yes?, no?, add_file, remove_file, copy_file, template, directory, inside, run, inject_into_file and a couple more.

To use them, you just need to include Thor::Actions in your Thor classes:

class App < Thor
  include Thor::Actions
  # tasks
end

Some actions like copy file require that a class method called source_root be defined in your class. This is the directory where your templates should be placed. Be sure to check the documentation on Thor::Actions and Thor::Shell::Basic. For instance:

class App < Thor
  include Thor::Actions

  def self.source_root
    File.dirname(__FILE__)
  end
end
Clone this wiki locally