#!/usr/bin/env ruby require 'pluginscan' require 'pluginscan/version' # TODO: Should this be required in lib/pluginscan? require 'optparse' require 'file_creator' options = {} OptionParser.new do |opts| opts.banner = "Usage: pluginscan plugin/directory/path [options]" opts.on("-s", "--[no-]sloccount", "SLOCCount source lines report (default)") do |s| options[:sloccount] = s end opts.on("-c", "--[no-]cloc", "CLOC source lines report (default)") do |c| options[:cloc] = c end opts.on("-a", "--[no-]advisories", "Advisories report (default)") do |a| options[:advisories] = a end opts.on("-i", "--issues-format FORMAT", [:report, :error_list], "Format of the issues report (report, error_list). Default: 'report'") do |format| options[:issues_format] = format end opts.on("-g", "--[no-]hide-ignores", "Hide/show ignored lines (i.e. matches which are probably safe)") do |g| options[:hide_ignores] = g end opts.on("-e", "--error-list-file FILENAME", "File for outputting the error_list (vim-compatible errorfile)") do |filename| begin options[:error_list_file] = FileCreator.new.create(filename) rescue FileCreator::Error => e puts "[ERROR] Invalid filename: #{e.message}" exit(1) end end # These options exit early: opts.on_tail("-v", "--version", "Show gem version") do puts Pluginscan::VERSION exit end opts.on_tail("-h", "--help", "Show this message") do puts opts exit end end.parse! plugin_directory = ARGV[-1] || '.' if Dir.exist? plugin_directory Pluginscan::Scanner.new(options).scan(plugin_directory) else puts "No such file or directory: #{plugin_directory}" end