Module: Lich::Util::Update::StatusReporter Private
- Defined in:
- documented/common/update/status_reporter.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Utilities for rendering update status messages and tables.
Provides monospace-aware response wrapper and Terminal::Table formatting for sync summaries.
Class Method Summary collapse
-
.render_sync_summary(repo_name, script_count, downloaded_scripts, downloaded_other, subdir_names, failed_scripts = [], failed_other = {}, held_scripts = []) ⇒ void
private
Renders sync results as Terminal::Table.
-
.respond_github_failure(error, consequence, subject: nil) ⇒ void
private
Reports a failed GitHub request as one message stating what was not done and whether the user needs to act.
-
.respond_mono(text) ⇒ void
private
Outputs text with monospace formatting if available.
Class Method Details
.render_sync_summary(repo_name, script_count, downloaded_scripts, downloaded_other, subdir_names, failed_scripts = [], failed_other = {}, held_scripts = []) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Renders sync results as Terminal::Table.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'documented/common/update/status_reporter.rb', line 74 def self.render_sync_summary(repo_name, script_count, downloaded_scripts, downloaded_other, subdir_names, failed_scripts = [], failed_other = {}, held_scripts = []) total_downloaded = downloaded_scripts.length + downloaded_other.values.flatten.length total_failed = failed_scripts.length + failed_other.values.flatten.length if total_downloaded == 0 && total_failed == 0 && held_scripts.empty? table = Terminal::Table.new( title: "#{repo_name} Sync", rows: [ ['Scripts', "#{script_count} checked, all up to date"], *subdir_names.map { |s| [s.capitalize, 'up to date'] } ] ) respond_mono(table.to_s) return end table_rows = [] table_rows << ['Category', 'File', 'Status'] table_rows << :separator downloaded_scripts.each { |f| table_rows << ['script', f, 'downloaded'] } failed_scripts.each { |f| table_rows << ['script', f, 'FAILED (will retry next login)'] } held_scripts.each { |f, required| table_rows << ['script', f, "needs Lich #{required}+ (not updated)"] } downloaded_other.each do |subdir, files| files.each { |f| table_rows << [subdir, f, 'downloaded'] } end failed_other.each do |subdir, files| files.each { |f| table_rows << [subdir, f, 'FAILED (will retry next login)'] } end subdir_names.each do |s| next if downloaded_other.key?(s) || failed_other.key?(s) table_rows << [s, '--', 'up to date'] end if downloaded_scripts.empty? && failed_scripts.empty? && held_scripts.empty? table_rows << ['scripts', '--', "#{script_count} checked, all up to date"] end table_rows << :separator summary = "Total: #{total_downloaded} updated" summary += ", #{total_failed} failed" if total_failed > 0 summary += ", #{held_scripts.length} need newer Lich" unless held_scripts.empty? table_rows << [{ value: summary, colspan: 3 }] table = Terminal::Table.new(title: "#{repo_name} Sync", rows: table_rows) respond_mono(table.to_s) end |
.respond_github_failure(error, consequence, subject: nil) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Reports a failed GitHub request as one message stating what was not done and whether the user needs to act.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'documented/common/update/status_reporter.rb', line 47 def self.respond_github_failure(error, consequence, subject: nil) = case error&.kind when :rate_limited reset = error.reset_at ? ", resets at #{error.reset_at.strftime('%H:%M')}" : '' "GitHub check failed (rate limit reached#{reset}). #{consequence} This is temporary and will clear once the limit resets." when :not_found "GitHub check failed (#{subject || 'repository'} not found). #{consequence} Check that the repository and branch exist." when :rejected "GitHub check failed (GitHub refused access to #{subject || 'the repository'}). #{consequence} Check that the repository and branch exist and are public." else "GitHub check failed. #{consequence} This is a temporary error that should resolve itself by your next login." end respond_mono("[lich5-update: #{}]") end |
.respond_mono(text) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Outputs text with monospace formatting if available.
30 31 32 33 34 35 36 37 38 |
# File 'documented/common/update/status_reporter.rb', line 30 def self.respond_mono(text) if defined?(Lich::Messaging) && Lich::Messaging.respond_to?(:mono) Lich::Messaging.mono(text) else # respond is a top-level method (private on Object). Bare `respond` # can't be called from a module class method without send. send(:respond, text) end end |