Brigadier
Brigadier - Take control of your command line
Installation
Add this line to your application's Gemfile:
gem 'brigadier'
And then execute:
$ bundle
Or install it yourself as:
$ gem install brigadier
Usage
Add the following to basic.rb
:
#!/usr/bin/env ruby
require 'brigadier'
class BasicCommand
extend Brigadier
toggle 'debug', 'Debugging toggle'
toggle 'verbose', 'Verbose mode', default: true
execute do
puts "Inside \#execute - debug?: #{debug?}, verbose?: #{verbose?}"
end
end
Brigadier::Runner.new(ARGV).run(BasicCommand)
Get some help:
$ ruby basic.rb --help
Toggle(s)
--debug Debugging toggle (default: false)
--verbose Verbose mode (default: true)
$ ruby basic.rb --debug --help
Toggle(s)
--debug Debugging toggle (default: false, current: true)
--verbose Verbose mode (default: true)
Run it:
$ ruby basic.rb
Inside #execute - debug?: false, verbose?: true
$ ruby basic.rb --debug --not-verbose
Inside #execute - debug?: true, verbose?: false
Check out the examples directory for more examples.
Contributing
- Fork it ( https://github.com/ashmckenzie/brigadier/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Run
bundle exec rake test
- Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
License
The gem is available as open source under the terms of the MIT License.