class Forgitter::CLI::OptionParser

Attributes

opt_parser[RW]
options[RW]

Public Class Methods

new() click to toggle source
# File lib/forgitter/cli/option_parser.rb, line 10
def initialize
  # The options specified on the command line will be collected in *options*.
  # We set default values here.
  @options = Forgitter::DEFAULT_OPTIONS

  @opt_parser = ::OptionParser.new do |opts|
    opts.banner = 'Usage: forgitter [-l] TAG1 [TAG2 ...]'

    opts.on('-l', '--list',
            'Instead of generating a .gitignore, list the ignorefiles that match the tags.') do
      options[:list] = true
    end

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

    # Another typical switch to print the version.
    opts.on_tail('-v', '--version', 'Show version') do
      puts Forgitter::VERSION
      exit
    end
  end

end

Public Instance Methods

help() click to toggle source
# File lib/forgitter/cli/option_parser.rb, line 39
def help
  opt_parser.help
end
parse(args) click to toggle source

Return a structure describing the options.

# File lib/forgitter/cli/option_parser.rb, line 46
def parse(args)
  begin      
    opt_parser.parse!(args)
  rescue ::OptionParser::InvalidOption => e
    puts help
    exit(1)
  end
  options
end