Class: FindMax::Cli
- Inherits:
-
Object
- Object
- FindMax::Cli
- Includes:
- Modules::CheckTypes, Modules::Info
- Defined in:
- lib/find_max/cli.rb
Constant Summary collapse
- AVAILABLE_MODES =
['command', 'help', 'version']
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(argv) ⇒ Cli
constructor
A new instance of Cli.
Methods included from Modules::Info
#error_message, #info, #result
Methods included from Modules::CheckTypes
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
#execute ⇒ Object
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. = 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 (e. + "\n" + I18n.t('help.need_help')) rescue Exception => e (e.) end |