Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

CLI app framework

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 bin
Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rspec
Octocat-spinner-32 .yardopts
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Guardfile
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 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.