Class: AlbaHabla::Cli

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

Overview

Class used to parse command line arguments

Constant Summary collapse

DEFAULT_OPTIONS =
{
  book_path: '',
}.freeze

Class Method Summary collapse

Class Method Details

.parse(args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/alba_habla/cli.rb', line 10

def self.parse(args)
  options = DEFAULT_OPTIONS.dup

  opt_parser = OptionParser.new do |opts|
    opts.banner = 'Usage: alba_habla [options]'

    opts.on('-bBOOK_PATH', '--books=BOOK_PATH', 'Path to folder with book files') do |bp|
      options[:book_path] = bp.end_with?('/') ? bp : "#{bp}/"
    end
  end

  opt_parser.parse!(args)
  options
end