class CheckPlease::CLI::Parser

Public Class Methods

new(exe_file_name) click to toggle source
# File lib/check_please/cli/parser.rb, line 7
def initialize(exe_file_name)
  @exe_file_name = File.basename(exe_file_name)
end

Public Instance Methods

flags_from_args!(args) click to toggle source

Unfortunately, OptionParser really wants to use closures. I haven't yet figured out how to get around this, but at least it's closing on a local instead of an ivar… progress?

# File lib/check_please/cli/parser.rb, line 14
def flags_from_args!(args)
  flags = Flags.new
  optparse = option_parser(flags: flags)
  optparse.parse!(args) # removes recognized flags from `args`
  return flags
rescue OptionParser::InvalidOption, OptionParser::AmbiguousOption => e
  raise InvalidFlag, e.message, cause: e
end
help() click to toggle source
# File lib/check_please/cli/parser.rb, line 23
def help
  option_parser.help
end

Private Instance Methods

banner() click to toggle source
option_parser(flags: nil) click to toggle source

NOTE: if flags is nil, you'll get something that can print help, but will explode when sent :parse

# File lib/check_please/cli/parser.rb, line 30
def option_parser(flags: nil)
  OptionParser.new.tap do |optparse|
    optparse.banner = banner
    CheckPlease::Flags.each_flag do |flag|
      args = [ flag.cli_short, flag.cli_long, flag.description ].flatten.compact
      optparse.on(*args) do |value|
        flags.send "#{flag.name}=", value
      end
    end
  end
end