bin/lutra
#!/usr/bin/env ruby
require 'optparse'
require 'find'
require 'lutra'
require 'lutra/version'
verbose = false
color = STDOUT.tty?
usage = 'Usage: lutra [OPTIONS] [PATH]'
tags = Lutra::TAGS
comments = Lutra::COMMENTS
formatter_opts = {}
ARGV.options do |o|
o.version = Lutra::VERSION
o.banner = usage
o.on('-t', '--tags=TAG', 'Search for custom tags') do |tag|
tags = tag.split(',').map(&:strip)
end
o.on('-c', '--comments=COM', 'Specify comment lines') do |com|
comments = com.split(',').map(&:strip)
end
o.on('-s', '--text-size=SIZE', 'Set text size for formatter') do |size|
formatter_opts[:text_size] = size.to_i
end
o.on('-v', '--verbose', 'Verbose output') do
verbose = true
end
o.on('--hide-tags', 'Hide tags') do
formatter_opts[:display_tags] = false
end
end
begin
ARGV.options.parse!
paths = if ARGV.empty?
'.'
else
ARGV.select { |path| File.exist?(path) }
end
rescue => e
STDERR.puts "Error: #{e.message}"
STDERR.puts usage
STDERR.puts "Try 'lutra --help' for more information"
exit 1
end
formatter = Lutra::Formatters::Default.new(formatter_opts)
scanner = Lutra::Scanner.new(formatter)
Find.find(*paths) do |path|
unless paths.include?(path)
Find.prune if File.basename(path).start_with?('.')
end
next if File.directory?(path)
begin
scanner.scan_file(path, tags, comments)
rescue Errno::ENOENT => e
STDERR.puts "lutra: #{e.message} (broken symlink?)" if verbose
rescue => e
STDERR.puts "lutra: #{path}: #{e.message}" if verbose
end
end
exit