class UpdateRepo::ConsoleOutput

Class : ConsoleOutput. This class has functions to print header, footer and metrics.

Public Class Methods

new(logger, metrics, cmd) click to toggle source

Constructor for the ConsoleOutput class. @param logger [class] Pointer to the Logger class @param metrics [class] Pointer to the Metrics class @param cmd [class] Pointer to the CmdConfig class @return [void] @example

console = ConsoleOutput.new(@log)
# File lib/update_repo/console_output.rb, line 19
def initialize(logger, metrics, cmd)
  @summary = { processed: 'green', updated: 'cyan', skipped: 'yellow',
               failed: 'red', unchanged: 'white', warning: 'light_magenta' }
  @metrics = metrics
  @log = logger
  @cmd = cmd
end

Public Instance Methods

list_exceptions() click to toggle source

Print a list of any defined exceptions that will not be updated. @return [void] @param [none]

# File lib/update_repo/console_output.rb, line 106
def list_exceptions
  exceptions = @cmd['exceptions']
  return unless exceptions

  print_log "\nExclusions:".underline, ' ',
            exceptions.join(', ').yellow, "\n"
end
list_failures() click to toggle source

List any repositories that failed their update, and the error. @param [none] @return [void]

# File lib/update_repo/console_output.rb, line 81
def list_failures
  # ensure we don't have duplicate errors from the same repo
  remove_dups
  puts "\n" unless @cmd[:show_errors]
  print_log "\n!! Note : The following #{@metrics[:failed_list].count}",
            ' repositories ', 'FAILED'.red.underline, ' during this run :'
  # print out any and all errors into a nice list
  @metrics[:failed_list].each do |failed|
    print_log "\n  [", 'x'.red, "] #{failed[:loc]}"
    print_log "\n    -> ", failed[:line].chomp.red
  end
  print_log " \n\n"
end
list_locations() click to toggle source

Print a list of all top-level directories that will be searched and any Git repos contained within updated. @return [void]

# File lib/update_repo/console_output.rb, line 117
def list_locations
  print_log "\nRepo location(s):\n".underline
  @cmd['location'].each do |loc|
    print_log '-> ', loc.cyan, "\n"
  end
end
print_metrics() click to toggle source

Print end-of-run metrics to console / log @return [void] @param [none]

remove_dups() click to toggle source

removes any duplications in the list of failed repos. @param [none] @return [void] modifies the @metrics in place

# File lib/update_repo/console_output.rb, line 98
def remove_dups
  # removes duplicate ':loc' values from the Failed list.
  @metrics[:failed_list].uniq! { |error| error[:loc] }
end
show_header() click to toggle source

Display a simple header to the console @example

show_header

@return [void] @param [none]

# File lib/update_repo/console_output.rb, line 32
def show_header
  unless @cmd[:brief]
    # print an informative header before starting
    print_log "\nGit Repo update utility (v", VERSION, ')',
              " \u00A9 Grant Ramsay <seapagan@gmail.com>\n"
    print_log "Using Configuration from '#{@cmd.getconfig.config_path}'\n"
    # show the logfile location, but only if it is enabled
    show_logfile
    # list out the locations that will be searched
    list_locations
    # list any exceptions that we have from the config file
    list_exceptions
    # save the start time for later display in the footer...
    @metrics[:start_time] = Time.now
  end
  print_log "\n" # blank line before processing starts
end
show_last_errors() click to toggle source

just print out errors from the last run, if any @return [void]

# File lib/update_repo/console_output.rb, line 134
def show_last_errors
  @metrics.load_errors(@cmd.getconfig)
  if @metrics[:failed_list].empty?
    puts "There are#{' No Errors'.green} from last full run.\n\n"
  else
    puts "Showing #{'ERRORS'.red.underline} from last full run :"
    list_failures
  end
end
show_logfile() click to toggle source

print out the logfile name and location, if we are logging to file @return [void]

# File lib/update_repo/console_output.rb, line 126
def show_logfile
  return unless @cmd[:log]

  print_log "\nLogging to file:".underline, " #{@log.logfile}\n".cyan
end