Notes on use of Thor
I was thinking about writing scripts in bash to simulate the Thor inject before/after functionality. This made me very curious about how the Rails generator (which uses thor) "destroy" capability works. That led me to read the source for Thor and its specs to see how this is done. See item 4.
- When you do
thor ex:command
note thatcommand
must match the method name (not the name from thedesc
declaration). - If you have a method with an underscore in it, thor will convert dashes to
underscores in the command name. E.g.,
thor ex:create-force
will work with a methodcreate_force
- There can be surprises if you inject something near the beginning of the file, and then try to inject the same text somewhere near the end. The text at the beginning will be matched so you may not find that the 2nd injection works.
- To revoke an action, you can do
self.behavior = :revoke
. See therevoke
method in the example.
Other actions
say, ask, yes?, no?, add_file, remove_file, copy_file, template, directory, inside, run, inject_into_file
See https://www.rubydoc.info/gems/thor/Thor/Shell/Basic and https://www.rubydoc.info/gems/thor/Thor/Actions