Class: EndiFeed::CLI

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

Overview

A Simple class for the executable version of the gem

Author:

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CLI

Returns a new instance of CLI.

Parameters:

  • args (Array<String>)

    The command-line arguments



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

def initialize(args)
  @args = args
end

Instance Method Details

#parseString

Parses the command-line arguments and runs the executable

Returns:

  • (String)

    The short url or argument passed



44
45
46
47
48
# File 'lib/endi_feed/cli.rb', line 44

def parse
  opts = OptionParser.new(&method(:set_options))
  opts.parse!(@args)
  get_news
end

#set_options(opts) ⇒ Object

Configures the arguments for the command

Parameters:

  • opts (OptionParser)


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
# File 'lib/endi_feed/cli.rb', line 16

def set_options(opts)
  @total_news  = 25
  opts.version = EndiFeed::VERSION
  opts.banner  = <<MSG
Usage: endifeed [options] [arguments]
Description:
  EndiFeed, get the latest news from endi.com / El Nuevo Dia Newspaper.

Options:
MSG
  opts.set_program_name 'EndiFeed'
  opts.on('-n [total]', Integer, '--news', 'total of news to fetch') do |total|
    @total_news = total
  end

  opts.on_tail('-v', '--version', 'display the version of EndiFeed') do
    puts opts.version
    exit
  end

  opts.on_tail('-h', '--help', 'print this help') do
    puts opts.help
    exit
  end
end