class Fanforce::PluginFactory::CLI::Scripts include Fanforce::PluginFactory::CLI::Utils require_relative '../lib/git' require_relative '../lib/scaffolding' ###################################################################################################################### def diff(type, detail_level=nil) type = type.to_sym detail_level = (detail_level||'detailed').to_sym if type == :files if [:all,:files].include?(type) if Fanforce::CLI::TYPE == :directory_of_plugins if detail_level == :detailed directory_file_details(detail_level) else directory_file_overview end elsif Fanforce::CLI::TYPE == :single_plugin plugin = Fanforce::CLI::Plugin.load(Fanforce::CLI::DIR) plugin_file_details(plugin, detail_level) end end if [:all,:git].include?(type) if Fanforce::CLI::TYPE == :directory_of_plugins git_overview elsif Fanforce::CLI::TYPE == :single_plugin git_details end end end def directory_file_overview log '' log sprintf('%-12s %-50s %85s', 'FILE STATUS', 'PLUGIN NAME', 'STATS OVERVIEW').format(:bold) log divider '======================================================================================================' Fanforce::CLI::Plugins.each do |plugin, current_count, total| missing = 0 diverged = 0 previous = 0 corrupted = 0 is_synced = true Fanforce::PluginFactory::CLI::Scaffolding.new(plugin).metadata.each do |filepath, change| if change[:status] == :missing is_synced = false next missing += 1 elsif change[:status] == :diverged is_synced = false next diverged += 1 elsif change[:status] == :previous is_synced = false next previous += 1 elsif change[:status] == :corrupted is_synced = false next corrupted += 1 end end changed_stats = [ "#{missing} files missing", "#{previous} files previous", "#{diverged} files diverged", "#{corrupted} files corrupted" ] puts sprintf("%s%-12s#{fmt_end} %-41s %23s %23s %23s %23s", fmt_start(is_synced ? :green : :red), (is_synced ? 'Synced' : 'Changed'), plugin.name, *changed_stats ) log divider '---------------------------------------------------------------------------------------------------+' end puts '' end def directory_file_details(detail_level) Fanforce::CLI::Plugins.each do |plugin, current_count, total| log divider '+===================================================================================================' has_files_to_update = false Fanforce::PluginFactory::CLI::Scaffolding.new(plugin).metadata.each do |filepath, metadata| next if ![:previous,:diverged,:missing,:corrupted].include?(metadata[:status]) has_files_to_update = true filepath = filepath.gsub(Fanforce::CLI::DIR, '') log sprintf "%s%-8s#{fmt_end} %-95s %22s %22s\n", fmt_start([:previous,:diverged,:missing,:corrupted].include?(metadata[:status]) ? :red : :green), metadata[:status].to_s.titleize, filepath, ("#{metadata[:insertions]} insertions(+)" if metadata[:insertions].to_i > 0), ("#{metadata[:deletions]} deletions(-)" if metadata[:insertions].to_i > 0) if detail_level == :detailed and metadata[:diff] lines = '' metadata[:diff].lines do |line| line = line.format(:red) if line[0] == '-' line = line.format(:green) if line[0] == '+' line = (' '*3) + line lines += line end log divider ' -----------------------------------------------------------------------------------------------' log ' THE FOLLOWING CHANGES WILL OCCUR DURING UPDATE:' log ' -----------------------------------------------' log "\n" + lines + "\n" end log divider '---------------------------------------------------------------------------------------------------+' end log 'NO FILES TO UPDATE' if !has_files_to_update end end def plugin_file_details(plugin, detail_level) log '' log sprintf "%-30s %119s\n", "FILES (#{plugin.dir_name})", 'changes needed during update' log divider '======================================================================================================' Fanforce::PluginFactory::CLI::Scaffolding.new(plugin).metadata.each do |filepath, metadata| filepath = filepath.gsub(Fanforce::CLI::DIR, '') log sprintf "%s%-8s#{fmt_end} %-95s %22s %22s\n", fmt_start([:previous,:diverged,:missing,:corrupted].include?(metadata[:status]) ? :red : :green), metadata[:status].to_s.titleize, filepath, ("#{metadata[:insertions]} insertions(+)" if metadata[:insertions].to_i > 0), ("#{metadata[:deletions]} deletions(-)" if metadata[:insertions].to_i > 0) if detail_level == :detailed and metadata[:diff] lines = '' metadata[:diff].lines do |line| line = line.format(:red) if line[0] == '-' line = line.format(:green) if line[0] == '+' line = (' '*3) + line lines += line end log divider ' -----------------------------------------------------------------------------------------------' log ' THE FOLLOWING CHANGES WILL OCCUR DURING UPDATE:' log ' -----------------------------------------------' log "\n" + lines + "\n" end log divider '---------------------------------------------------------------------------------------------------+' end puts '' end def git_overview plugin_column_width = Fanforce::CLI::Plugins.dir_names.inject(0){|l,d| d.length>l ? d.length : l} log Fanforce::PluginFactory::CLI::Git.status_table_header(plugin_column_width) log divider '======================================================================================================' Fanforce::CLI::Plugins.each do |plugin, current_count, total| log Fanforce::PluginFactory::CLI::Git.new(plugin).status_row(plugin_column_width) log divider '---------------------------------------------------------------------------------------------------+' end log '' end def git_details exec 'git status' log '' end end