Class: UpdateRepo::ConsoleOutput
- Inherits:
-
Object
- Object
- UpdateRepo::ConsoleOutput
- Includes:
- Helpers
- Defined in:
- lib/update_repo/console_output.rb
Overview
Class : ConsoleOutput. This class has functions to print header, footer and metrics.
Instance Method Summary collapse
-
#initialize(logger, metrics, cmd) ⇒ void
constructor
Constructor for the ConsoleOutput class.
-
#list_exceptions ⇒ void
Print a list of any defined exceptions that will not be updated.
-
#list_failures ⇒ void
List any repositories that failed their update, and the error.
-
#list_locations ⇒ void
Print a list of all top-level directories that will be searched and any Git repos contained within updated.
-
#print_metrics ⇒ void
Print end-of-run metrics to console / log.
-
#remove_dups ⇒ void
removes any duplications in the list of failed repos.
-
#show_footer ⇒ void
print out a brief footer.
-
#show_header ⇒ void
Display a simple header to the console.
-
#show_last_errors ⇒ void
just print out errors from the last run, if any.
-
#show_logfile ⇒ void
print out the logfile name and location, if we are logging to file.
Methods included from Helpers
Constructor Details
#initialize(logger, metrics, cmd) ⇒ void
Constructor for the ConsoleOutput class.
19 20 21 22 23 24 25 |
# 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 |
Instance Method Details
#list_exceptions ⇒ void
This method returns an undefined value.
Print a list of any defined exceptions that will not be updated.
106 107 108 109 110 111 112 |
# 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 ⇒ void
This method returns an undefined value.
List any repositories that failed their update, and the error.
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# 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 ⇒ void
This method returns an undefined value.
Print a list of all top-level directories that will be searched and any Git repos contained within updated.
117 118 119 120 121 122 |
# 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 ⇒ void
This method returns an undefined value.
Print end-of-run metrics to console / log
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/update_repo/console_output.rb', line 67 def print_metrics @summary.each do |metric, color| metric_value = @metrics[metric] output = pluralize(metric_value, metric) print_log ' | ', output.send(color.to_sym) unless metric_value.zero? end print_log ' |' list_failures unless @metrics[:failed_list].empty? @metrics.save_errors(@cmd.getconfig) if @cmd[:save_errors] end |
#remove_dups ⇒ void
This method returns an undefined value.
removes any duplications in the list of failed repos.
98 99 100 101 |
# 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_footer ⇒ void
This method returns an undefined value.
print out a brief footer. This will be expanded later.
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/update_repo/console_output.rb', line 53 def unless @cmd[:brief] duration = Time.now - @metrics[:start_time] print_log "\n\nUpdates completed in ", show_time(duration).cyan print_metrics end print_log " \n\n" # close the log file now as we are done, just to be sure ... @log.close end |
#show_header ⇒ void
This method returns an undefined value.
Display a simple header to the console
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# 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 <[email protected]>\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 ⇒ void
This method returns an undefined value.
just print out errors from the last run, if any
134 135 136 137 138 139 140 141 142 |
# File 'lib/update_repo/console_output.rb', line 134 def show_last_errors @metrics.load_errors(@cmd.getconfig) if !@metrics[:failed_list].empty? puts 'Showing ' + 'ERRORS'.red.underline + ' from last full run :' list_failures else puts 'There are' + ' No Errors'.green + " from last full run.\n\n" end end |
#show_logfile ⇒ void
This method returns an undefined value.
print out the logfile name and location, if we are logging to file
126 127 128 129 130 |
# 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 |