项目作者: kddnewton

项目描述 :
Adds callbacks to thor commands
高级语言: Ruby
项目地址: git://github.com/kddnewton/thor-hollaback.git
创建时间: 2016-09-22T15:34:40Z
项目社区:https://github.com/kddnewton/thor-hollaback

开源协议:MIT License

下载


Thor::Hollaback

Build Status
Gem Version

Adds callbacks to thor commands.

Installation

Add this line to your application’s Gemfile:

  1. gem "thor-hollaback"

And then execute:

  1. $ bundle

Or install it yourself as:

  1. $ gem install thor-hollaback

Usage

Uses the hollaback gem to add callbacks to thor commands. You can set CLI-level callbacks with the macros class_before, class_after, and class_around. You can set command-level callbacks with before, after, and around. Example below.

  1. class CLI < Thor
  2. class_before :say_hello
  3. class_after :say_goodbye
  4. desc "first_test", "First test command"
  5. around :say
  6. def first_test
  7. puts "How are you?"
  8. end
  9. desc "second_test", "Second test command"
  10. def second_test
  11. puts "How are you?"
  12. end
  13. no_commands do
  14. def say_hello
  15. puts "Hello!"
  16. end
  17. def say_goodbye
  18. puts "Goodbye!"
  19. end
  20. def say
  21. puts "Speaking..."
  22. yield
  23. puts "...done."
  24. end
  25. end
  26. end

When invoked, the above CLI results with:

  1. irb(main):001:0> CLI.start(["first_test"])
  2. Hello!
  3. Speaking...
  4. How are you?
  5. ...done.
  6. Goodbye!
  7. => nil

and

  1. irb(main):001:0> CLI.start(["second_test"])
  2. Hello!
  3. How are you?
  4. Goodbye!
  5. => nil

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/kddnewton/thor-hollaback.

License

The gem is available as open source under the terms of the MIT License.