module FindSharedLines::CommandLineInterface

Public Class Methods

execute() click to toggle source
# File lib/find_shared_lines/command_line_interface.rb, line 51
def self.execute
  option = parse_options

  if ARGV.empty?
    warn 'At least 1 file should be given.'
  else
    $stdout.puts result(option).sort
  end
end
parse_options() click to toggle source
# File lib/find_shared_lines/command_line_interface.rb, line 14
def self.parse_options
  banner = "USAGE: #{File.basename($PROGRAM_NAME)} [OPTION] [Files]..."
  option = OPTION::SHARED

  OptionParser.new(banner) do |opt|
    opt.on('-e', '--exclude-shared-lines',
           'Exclude lines commonly included in given files') do
      option = OPTION::EXCLUDE
    end

    opt.on('-s', '--shared-lines',
           'Collect lines shared in given files') do
      option = OPTION::SHARED
    end

    opt.on('-j', '--join-lines',
           'Collect all lines in given files') do
      option = OPTION::JOIN
    end

    opt.parse!
  end

  option
end
result(option) click to toggle source
# File lib/find_shared_lines/command_line_interface.rb, line 40
def self.result(option)
  case option
  when OPTION::SHARED
    FindSharedLines.shared_lines(ARGV)
  when OPTION::EXCLUDE
    FindSharedLines.exclude_shared_lines(ARGV)
  when OPTION::JOIN
    FindSharedLines.join(ARGV)
  end
end