Skip to content
I didn't like the inflexible nature of OptionParser
Ruby
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
spec Added more specs
.gitignore Added gitignore
.rvmrc First commit
README.markdown Part of the readme was being stripped
parse_options.rb First commit

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.