-
Notifications
You must be signed in to change notification settings - Fork 554
Actions
Rafael Mendonça França edited this page Jun 20, 2023
·
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