Class: Docscribe::CLI::Formatters::Text

Inherits:
Object
  • Object
show all
Defined in:
lib/docscribe/cli/formatters/text.rb

Overview

Text output formatter preserving the original CLI output format.

Instance Method Summary collapse

Instance Method Details

#format_check_status_line(state) ⇒ void

This method returns an undefined value.

Print check status line.

Parameters:

  • state (Docscribe::CLI::Formatters::state)

    formatter state hash



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/docscribe/cli/formatters/text.rb', line 58

def format_check_status_line(state)
  checked_error = state[:error_paths].size
  type_mismatch_count = state[:type_mismatch_paths].size

  if all_fine?(state, checked_error, type_mismatch_count)
    puts "Docscribe: OK (#{state[:checked_ok]} files checked)"
  elsif mismatch_only?(state, checked_error)
    puts "Docscribe: OK (#{state[:checked_ok]} files checked, #{type_mismatch_count} with type mismatches)"
  else
    puts failure_line(state, type_mismatch_count, checked_error)
  end
end

#format_check_summary(state:, options:) ⇒ void

This method returns an undefined value.

Format and print check summary.

Parameters:

  • state (Docscribe::CLI::Formatters::state)

    formatter state hash

  • options (Docscribe::CLI::Formatters::opts)

    runtime options hash



13
14
15
16
17
18
19
# File 'lib/docscribe/cli/formatters/text.rb', line 13

def format_check_summary(state:, options:)
  puts
  format_fail_paths(state, options)
  format_check_status_line(state)
  format_type_mismatch_paths(state, options)
  format_error_paths(state)
end

#format_corrected_paths(state, options) ⇒ void

This method returns an undefined value.

Print updated file paths.

Parameters:

  • state (Docscribe::CLI::Formatters::state)

    formatter state hash

  • options (Docscribe::CLI::Formatters::opts)

    runtime options hash



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/docscribe/cli/formatters/text.rb', line 93

def format_corrected_paths(state, options)
  state[:corrected_paths].each do |p|
    puts "Updated: #{p}"

    next if options[:verbose] || options[:quiet]

    Array(state[:corrected_changes][p]).each do |change|
      puts "  - #{format_change_reason(change)}"
    end
  end
end

#format_error_paths(state) ⇒ void

This method returns an undefined value.

Print error file messages.

Parameters:

  • state (Docscribe::CLI::Formatters::state)

    formatter state hash



109
110
111
112
113
114
115
116
117
# File 'lib/docscribe/cli/formatters/text.rb', line 109

def format_error_paths(state)
  return if state[:error_paths].empty?

  warn ''
  state[:error_paths].each do |p|
    warn "Error processing: #{p}"
    warn "  #{state[:error_messages][p]}" if state[:error_messages][p]
  end
end

#format_fail_paths(state, options) ⇒ void

This method returns an undefined value.

Print files needing updates.

Parameters:

  • state (Docscribe::CLI::Formatters::state)

    formatter state hash

  • options (Docscribe::CLI::Formatters::opts)

    runtime options hash



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/docscribe/cli/formatters/text.rb', line 42

def format_fail_paths(state, options)
  state[:fail_paths].each do |p|
    puts "Would update: #{p}"

    next if options[:verbose] || options[:quiet]

    Array(state[:fail_changes][p]).each do |change|
      puts "  - #{format_change_reason(change)}"
    end
  end
end

#format_type_mismatch_paths(state, options) ⇒ void

This method returns an undefined value.

Print type mismatch warnings.

Parameters:

  • state (Docscribe::CLI::Formatters::state)

    formatter state hash

  • options (Docscribe::CLI::Formatters::opts)

    runtime options hash



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/docscribe/cli/formatters/text.rb', line 76

def format_type_mismatch_paths(state, options)
  return if options[:quiet]
  return unless options[:verbose] || options[:explain]

  state[:type_mismatch_paths].each do |p|
    warn "Type mismatches: #{p}"
    Array(state[:type_mismatch_changes][p]).each do |change|
      warn "  - #{format_change_reason(change)}"
    end
  end
end

#format_write_summary(state:, options:) ⇒ void

This method returns an undefined value.

Format and print write summary.

Parameters:

  • state (Docscribe::CLI::Formatters::state)

    formatter state hash

  • options (Docscribe::CLI::Formatters::opts)

    runtime options hash



26
27
28
29
30
31
32
33
34
35
# File 'lib/docscribe/cli/formatters/text.rb', line 26

def format_write_summary(state:, options:)
  puts
  puts "Docscribe: updated #{state[:corrected]} file(s)" if state[:corrected].positive?
  format_corrected_paths(state, options)

  return unless state[:had_errors]

  warn "Docscribe: #{state[:error_paths].size} file(s) had errors"
  format_error_paths(state)
end