Sha256: 6b85be7829e7e49da74215ba8ecdafd4a9ef9dc4ade4d5c347b4f569b96dcf84

Contents?: true

Size: 1.48 KB

Versions: 2

Compression:

Stored size: 1.48 KB

Contents

require 'optparse'
require 'pp'

module Rocktumbler
  class Option
    #
    # Return a structure describing the options.
    #
    def self.parse(args)
      # The options specified on the command line will be collected in *options*.
      # We set default values here.
      options = OpenStruct.new
      options.gem_info = false
      options.gem_homepage = false
      options.skip_write = false
      options.verbose = false

      opt_parser = OptionParser.new do |opts|
        opts.banner = "Usage: tumble [options]"

        opts.separator ""
        opts.separator "Specific options:"

        opts.on("-i", "--info", "Display gem info comment.") do
          options.gem_info = true
        end

        opts.on("-d", "--homepage", "Display gem homepage comment.") do
          options.gem_homepage = true
        end

        opts.on("-s", "--skip-write", "Skip writing of Gemfile") do
          options.skip_write = true
        end

        opts.on("-V", "--verbose", "Display formatted output to STDOUT") do
          options.verbose = true
        end

        opts.separator ""
        opts.separator "Common options:"

        # No argument, shows at tail.  This will print an options summary.
        opts.on_tail("-h", "--help", "Show this message") do
          puts opts
          exit
        end

        opts.on_tail("--version", "Show version") do
          puts Rocktumbler::VERSION
          exit
        end
      end

      opt_parser.parse!(args)
      options
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rocktumbler-0.2.2 lib/rocktumbler/option.rb
rocktumbler-0.2.1 lib/rocktumbler/option.rb