Class: Highlights::CLI

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

Defined Under Namespace

Classes: Options

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CLI

Returns a new instance of CLI.



5
6
7
8
# File 'lib/highlights/cli.rb', line 5

def initialize(args)
  args << '-h' if ARGV.empty?
  @args = args
end

Instance Method Details

#get_optionsObject



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/highlights/cli.rb', line 16

def get_options
  options = Options.new(nil, "notes.md")

  OptionParser.new do |opts|
    opts.banner = "Usage: highlights -f file.csv -o [output file]"

    opts.on("-fFILENAME", "--file=FILENAME", "Kindle notes CSV file") do |f|
      options.filename = f
    end

    opts.on("-oOUTPUT", "--output=OUTPUT", "Output file. Accepts HTML and markdown (default: notes.md)") do |o|
      options.output = o
    end

    opts.on("-h", "--help", "Show help") do
      puts opts
      exit
    end

    opts.on("-v", "--version", "Show version") do
      puts VERSION
      exit
    end
  end.parse!(@args)

  options
end

#runObject



10
11
12
13
14
# File 'lib/highlights/cli.rb', line 10

def run
  options = get_options
  document = Parser.new(options.filename).parse
  Renderer.render(document, options.output)
end