class Imgfetcha::ArgParser

Attributes

result[RW]

Public Class Methods

new() click to toggle source
# File lib/imgfetcha/arg_parser.rb, line 7
def initialize
  @result = {}
end

Public Instance Methods

run() click to toggle source
# File lib/imgfetcha/arg_parser.rb, line 11
def run
  execute_parser
  @result
end

Private Instance Methods

execute_parser() click to toggle source

rubocop:disable Metrics/MethodLength

# File lib/imgfetcha/arg_parser.rb, line 19
def execute_parser
  OptionParser.new do |opts|
    opts.banner = 'Usage: imgfetcha -i INPUT_FILE -o OUTPUT_DIRECTORY'

    opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
      @result[:verbose] = v
    end

    opts.on('-i INPUT_FILE', '--input=INPUT_FILE', 'Specify input file') do |i|
      @result[:input_file] = i
    end

    opts.on('-o OUTPUT_DIRECTORY', '--output=OUTPUT_DIRECTORY', 'Specify output directory') do |o|
      @result[:output_dir] = o
    end

    opts.on('-V', '--version', 'Print version') do
      puts Imgfetcha::VERSION
      exit
    end

    opts.on('-h', '--help', 'Print this help') do
      puts opts
      exit
    end
  end.parse!
end