diff --git a/exe/flatito b/exe/flatito index 836b891..ab33aa1 100755 --- a/exe/flatito +++ b/exe/flatito @@ -6,7 +6,7 @@ require "flatito" require "optparse" # If no arguments are given, print help -stdin = STDIN.read unless STDIN.tty? +stdin = $stdin.read unless $stdin.tty? ARGV << "-h" if ARGV.empty? && !stdin options = {} @@ -45,13 +45,7 @@ OptionParser.new do |opts| end.parse! if stdin - items = Flatito::FlattenYaml.items_from_content(stdin) - renderer = Flatito::Renderer.build(options) - Flatito::PrintItems.call(renderer, options[:search], items) + Flatito.flat_content(stdin, options) else - begin - Flatito.search(ARGV, options) - rescue Interrupt - warn "\nInterrupted" - end + Flatito.search(ARGV, options) end diff --git a/lib/flatito.rb b/lib/flatito.rb index b968e2a..763e5a4 100644 --- a/lib/flatito.rb +++ b/lib/flatito.rb @@ -14,5 +14,13 @@ module Flatito def self.search(paths, options) Finder.new(paths, options).call + rescue Interrupt + warn "\nInterrupted" + end + + def self.flat_content(content, options) + items = FlattenYaml.items_from_content(content) + renderer = Renderer.build(options) + PrintItems.call(renderer, options[:search], items) end end