Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
CLI app framework
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
bin
lib
spec
.gitignore
.rspec
.yardopts
Gemfile
Guardfile
LICENSE
README.md
Rakefile
cli.gemspec

README.md

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|
    options[:msg] = msg
  end

  action "hi" do
    puts "Hi, World!"
  end

  default do
    str = options[: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.

Something went wrong with that request. Please try again.