Class: Krackle::CLI

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

Instance Method Summary collapse

Constructor Details

#initialize(args = ARGV) ⇒ CLI

Returns a new instance of CLI.



65
66
67
# File 'lib/krackle.rb', line 65

def initialize(args=ARGV)
  @expression, @path = args
end

Instance Method Details

#runObject



69
70
71
72
73
74
75
76
# File 'lib/krackle.rb', line 69

def run
  io = if @path
    File.open(@path, 'r')
  else
    $stdin.tty? ? raise("Specify a file path") : $stdin
  end
  Engine.new(YAML.load(io.read)).query(@expression).join("\n")
end