Martin
An ode to the Rat Pack (Dean Martin) with a Sinatra style DSL for creating command line interfaces to your applications
Example
calc.rb
class Calculator
def add(*nums)
nums.reduce(:+)
end
end
app.rb
require File.dirname(__FILE__) + '/calc'
require 'martin'
configure do
@calc = Calculator.new
end
command /add (\d+) to (\d+)/ do |a, b|
puts @calc.add(a.to_i, b.to_i)
end
error do |input|
puts 'Error: command ' + input.split.first + ' not found.'
end
And that's it! Now run ruby app add 15 to 25
and the application
should return 40
This works great coupled with highline
Rubular is a great place to test your regular expressions
Note on Patches/Pull Requests
- Fork the project.
- Make your feature addition or bug fix.
- Add tests for it. This is important so I don't break it in a future version unintentionally.
- Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
- Send me a pull request. Bonus points for topic branches.
Copyright
Copyright (c) 2010 Ryan Lewis. See LICENSE for details.