Skip to content

Commit

Permalink
some refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
ceritium committed Mar 17, 2024
1 parent e90a675 commit 556d243
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
12 changes: 3 additions & 9 deletions exe/flatito
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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
8 changes: 8 additions & 0 deletions lib/flatito.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 556d243

Please sign in to comment.