Class: Koota::CLI

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

Overview

This class handles the command-line interface to Koota.

Instance Method Summary collapse

Constructor Details

#initialize(program_name: $PROGRAM_NAME, output: $stdout) ⇒ CLI

Returns a new instance of CLI.



25
26
27
28
29
30
# File 'lib/koota/cli.rb', line 25

def initialize(program_name: $PROGRAM_NAME, output: $stdout)
  @file_parser = Koota::FileParser.new
  @generator   = Koota::Generator.new
  @output      = output
  @opts        = build_opts(program_name)
end

Instance Method Details

#call(argv = ARGV) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/koota/cli.rb', line 32

def call(argv = ARGV)
  result = @opts.parse(argv)

  if result.help?
    @output.puts @opts
    return true
  elsif result.version?
    @output.puts "koota v#{VERSION}"
    return true
  end

  raise Slop::Error, 'missing input file(s)' if result.args.empty?

  process(result.args, result.to_h)
rescue Slop::Error => e
  @output.puts "error: #{e.message}"
  @output.puts @opts

  false
end