Class: FindMax::Cli

Inherits:
Object
  • Object
show all
Includes:
Modules::CheckTypes, Modules::Info
Defined in:
lib/find_max/cli.rb

Constant Summary collapse

AVAILABLE_MODES =
['command', 'help', 'version']

Instance Method Summary collapse

Methods included from Modules::Info

#error_message, #info, #result

Methods included from Modules::CheckTypes

#is_number?

Constructor Details

#initialize(argv) ⇒ Cli

Returns a new instance of Cli.



10
11
12
# File 'lib/find_max/cli.rb', line 10

def initialize(argv)
  @argv = argv
end

Instance Method Details

#executeObject



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

def execute

  mode = AVAILABLE_MODES[0]
  OptionParser.new do |opts|
    opts.banner =  I18n.t 'help.use_the_sample'
    opts.separator I18n.t 'help.description'
    opts.on_tail("-h", "--help", I18n.t('help.about_help')) do
      mode = AVAILABLE_MODES[1]
      info(opts.to_s)
    end
    opts.on_tail("-v", "--version", I18n.t('help.version_gem')) do
      mode = AVAILABLE_MODES[1]
      info(FindMax::VERSION)
    end
    opts.parse!
  end

if mode == AVAILABLE_MODES[0]
  result(command)
end

rescue ArgumentError => e
  error_message(e.message + "\n" + I18n.t('help.need_help'))
rescue Exception => e
  error_message(e.message)
end