Class: RbsMiniMagick::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs_mini_magick/cli.rb

Overview

RbsMiniMagick::CLI

Instance Method Summary collapse

Constructor Details

#initialize(args, io:) ⇒ void

Parameters:

  • args (Array<String>)
  • io (::IO)


9
10
11
12
13
# File 'lib/rbs_mini_magick/cli.rb', line 9

def initialize(args, io:)
  @args = args
  @options = {}
  @io = io
end

Instance Method Details

#helpString

Returns:

  • (String)


45
46
47
# File 'lib/rbs_mini_magick/cli.rb', line 45

def help
  parser.help
end

#runInteger

Returns:

  • (Integer)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rbs_mini_magick/cli.rb', line 16

def run # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  parse!

  return 0 if help? || version?

  case options[:command]
  when "generate"
    Generator.new(
      mini_magick_version: options[:mini_magick_version],
      output_dir: options[:output_dir]
    ).run
  else
    raise ArgumentError, "Invalid command: #{options[:command]}"
  end

  0
rescue Error => e
  io.puts e.message
  1
rescue OptionParser::InvalidOption, ArgumentError => e
  io.puts e.message
  io.puts help
  1
rescue Interrupt
  io.puts "Bye!"
  1
end