Sha256: 0edd5e073c31dd9b7142f6f3d0ef2e6de2513a8884cd782a2503ae9b1ab6783e
Contents?: true
Size: 1.6 KB
Versions: 2
Compression:
Stored size: 1.6 KB
Contents
require "optparse" module AnnotateGem class Options attr_accessor :options, :options_parser def initialize @options = {} @options_parser = OptionParser.new do |opts| add_banner(opts) add_tail_options(opts) add_info_options(opts) add_gemfile_comment_options(opts) end end def parse!(args) options_parser.parse!(args) validate_options options end private def validate_options info_flags = options[:website_only] && options[:description_only] raise ArgumentError, "Cannot set both --website-only and --description-only flags" if info_flags end def add_info_options(opts) opts.on("--website-only", "Only output the website") do options[:website_only] = true end opts.on("--description-only", "Only output the description") do options[:description_only] = true end end def add_gemfile_comment_options(opts) opts.on("--new-comments-only", "Only add a comment to gemfile if there isn't a comment already") do options[:new_comments_only] = true end end def add_banner(opts) opts.banner = <<-BANNER.gsub(/\A\s{8}/, '') #{AnnotateGem::DESCRIPTION} Usage: #{opts.program_name} [options] #{opts.program_name} [gem name] BANNER end def add_tail_options(opts) opts.on_tail("-h", "--help", "Show this message") do puts opts exit end opts.on_tail("-v", "--version", "Show version") do puts AnnotateGem::VERSION exit end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
annotate_gem-0.0.10 | lib/annotate_gem/options.rb |
annotate_gem-0.0.8 | lib/annotate_gem/options.rb |