#!/usr/bin/env ruby

require_relative '../lib/color'
require_relative '../lib/const'
require_relative '../lib/package'

failed = nil
property_line = `grep -n "case property" ../commands/help.rb | cut -d: -f1`.to_i
help_lines = `wc -l ../commands/help.rb`.to_i
tail_lines = help_lines - property_line
help_commands = `head -#{property_line} ../commands/help.rb | grep "  when '" | cut -d"'" -f2`.split("\n")
help_properties = `tail -#{tail_lines} ../commands/help.rb | grep "  when '" | cut -d"'" -f2`.split("\n")
package_properties = Package.available_boolean_properties
if (CREW_COMMANDS.length - help_commands.length).positive?
  puts 'Help is missing for the crew commands in commands/help.rb below:'.yellow
  missing_commands = CREW_COMMANDS - help_commands
  missing_commands.each do |command|
    puts command.yellow
  end
  failed = true
end
if (package_properties.length - help_properties.length).positive?
  puts 'Help is missing for the properties in commands/help.rb below:'.yellow
  missing_properties = package_properties - help_properties
  missing_properties.each do |property|
    puts property.yellow
  end
  failed = true
end
if failed
  puts 'Help test failed.'.lightred
else
  puts 'Help test passed.'.lightgreen
end
