Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

I didn't like the inflexible nature of OptionParser

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rvmrc
Octocat-spinner-32 README.markdown
Octocat-spinner-32 parse_options.rb
README.markdown

Parse Options

Just like OptionParser in the Ruby Standard Library, but more flexible. With OptionParser, you must set your options with a single or double dash. With ParseOptions, you specify what your options will be.


module Mockup
  class Options

    def self.parse(args)
      options = OpenStruct.new

      ParseOptions.new(args) do |opts|

        opts.value('create') do |name|
          options.name = name
        end

        opts.boolean('convert') do |convert|
          options.convert = !!convert
        end

        opts.value('-l', '--location') do |location|
          options.location = location
        end

        opts.boolean('with-jquery') do |jquery|
          options.jquery = !!jquery
        end

        opts.help('help', '-h') do
          puts "

Usage: mockup create name --location /path/to/mockup

Mockup Options:

create:     The name of the mockup project. 
              e.g. mockup create project
-l:         Specify a location to create your mockup project. 
              e.g. mockup create project -l /path/to/mockup
convert:    Convert an existing Compass project to a mockup project. 
              e.g. mockup convert
with-jquery Install jQuery and jQuery UI
              e.g. mockup create project with-jquery
help        View the Help Screen
version     View the current version of mockup

          "
          exit(0)
        end

        opts.version('-v', 'version') do
          puts "Mockup's current version is #{Mockup.version}"
          exit(0)
        end
      end
      options
    end
  end
end
Something went wrong with that request. Please try again.