class Fanforce::AppFactory::CLI::Scripts include Fanforce::AppFactory::CLI::Utils require_relative '../git' require_relative '../scaffolding' ###################################################################################################################### def status(type, detail_level=nil) type = type.to_sym detail_level = (detail_level||'overview').to_sym if type == :files if [:all,:files].include?(type) if Fanforce::CLI::TYPE == :directory_of_apps files_overview elsif Fanforce::CLI::TYPE == :single_app app = Fanforce::CLI::App.load(Fanforce::CLI::DIR) files_details(app, detail_level) end end if [:all,:git].include?(type) if Fanforce::CLI::TYPE == :directory_of_apps status_git_overview elsif Fanforce::CLI::TYPE == :single_app status_git end end end def status_git_overview app_column_width = Fanforce::CLI::Apps.dir_names.inject(0){|l,d| d.length>l ? d.length : l} log Fanforce::AppFactory::CLI::Git.status_table_header(app_column_width) log divider '======================================================================================================' Fanforce::CLI::Apps.each do |app, current_count, total| log Fanforce::AppFactory::CLI::Git.new(app).status_row(app_column_width) log divider '---------------------------------------------------------------------------------------------------+' end log '' end def status_git exec 'git status' log '' end def files_overview log '' log sprintf('%-12s %-50s %85s', 'FILE STATUS', 'APP NAME', 'STATS OVERVIEW').format(:bold) log divider '======================================================================================================' Fanforce::CLI::Apps.each do |app, current_count, total| missing = 0 diverged = 0 previous = 0 corrupted = 0 is_synced = true Fanforce::AppFactory::CLI::Scaffolding.new(app).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'), app.name, *changed_stats ) log divider '---------------------------------------------------------------------------------------------------+' end puts '' end def files_details(app, detail_level) log '' log sprintf "%-30s %119s\n", "FILES (#{app.dir_name})", 'changes needed during update' log divider '======================================================================================================' Fanforce::AppFactory::CLI::Scaffolding.new(app).metadata.each do |filepath, change| filepath = filepath.gsub(Fanforce::CLI::DIR, '') log sprintf "%s%-8s#{fmt_end} %-95s %22s %22s\n", fmt_start([:previous,:diverged,:missing,:corrupted].include?(change[:status]) ? :red : :green), change[:status].to_s.titleize, filepath, ("#{change[:insertions]} insertions(+)" if change[:insertions].to_i > 0), ("#{change[:deletions]} deletions(-)" if change[:insertions].to_i > 0) if detail_level == :diff and change[:diff] lines = '' change[: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 end