Skip to content

Commit

Permalink
Add Cat subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
ganmacs committed Aug 17, 2016
1 parent 903afaf commit f684641
Showing 1 changed file with 45 additions and 8 deletions.
53 changes: 45 additions & 8 deletions lib/fluent/command/unpacker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def initialize(argv, format)
ret = option_parser.parse(@argv)
@path = ret.first

@v = @v.reduce({}) { |acc, e|
@v = (@v || []).reduce({}) { |acc, e|
k, v = e[1..-1].split("=")
acc.merge(k => v)
}
Expand All @@ -147,12 +147,13 @@ def call
conf = Fluent::Config::Element.new('ROOT', '', @v, [])
@formatter = lookup_formatter(conf)

io = File.open(@path, 'r')
i = 0
unpacker(io).each do |(time, record)|
break if i == @options[:number]
i += 1
puts @formatter.format(@path, time, record) # tag is use for tag
File.open(@path, 'r') do |io|
i = 0
unpacker(io).each do |(time, record)|
break if i == @options[:number]
i += 1
puts @formatter.format(@path, time, record) # tag is use for tag
end
end
end

Expand All @@ -168,7 +169,43 @@ def option_parser
end
end

class Tail < Base
class Cat < Base
def initialize(argv, format)
if i = argv.index("--")
@v = argv[i+1..-1]
argv = argv[0...i]
end

super
@options = {}
ret = option_parser.parse(@argv)
@path = ret.first

@v = (@v || []).reduce({}) { |acc, e|
k, v = e[1..-1].split("=")
acc.merge(k => v)
}

# validate
end

def call
conf = Fluent::Config::Element.new('ROOT', '', @v, [])
@formatter = lookup_formatter(conf)

File.open(@path, 'r') do |io|
unpacker(io).each do |(time, record)|
puts @formatter.format(@path, time, record) # tag is use for tag
end
end
end

def option_parser
@option_parser ||= OptionParser.new do |opt|
opt.banner = 'Usage: fluent-unpacker head [options] files'
opt.separator 'Options:'
end
end
end

class Formats < Base
Expand Down

0 comments on commit f684641

Please sign in to comment.