CLI
A CLI app framework
Setup
gem install wojtekmach-cli
Example
Let's say you have a file hello.rb
:
#!/usr/bin/env ruby
require "rubygems"
require "cli"
CLI.app do
name "hello"
version "0.0.1"
option "-m", "--message MSG" do |msg|
[:msg] = msg
end
action "hi" do
puts "Hi, World!"
end
default do
str = [:msg] || "Hello"
puts "#{str}, World!"
end
end
You can now use it like this:
% ruby hello.rb # => Hello, World!
% ruby hello.rb hi # => Hi, World!
% ruby hello.rb -m Bye # => Bye, World!
Alternatively, you can use the cli
binary like that:
#!/usr/bin/env cli
name "hello"
version "0.0.1"
default do
...
end
And run it:
% ./hello.rb
Licence
CLI is Copyright (c) 2011 Wojciech Mach and distributed under the MIT license. See the LICENCE file for more info.