Class: LabelWeaver::CLI::Commands::Diff

Inherits:
Sod::Command
  • Object
show all
Defined in:
lib/label_weaver/cli/commands/diff.rb

Instance Method Summary collapse

Instance Method Details

#callObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/label_weaver/cli/commands/diff.rb', line 17

def call(*)
  @file_path = context.input[:file]

  case context.input[:format] || "unified"
  when "unified"
    TTY::Pager.page do |pager|
      changed_files.each do |repository_file, project_file|
        pager.write <<~EOS
          
          #{"*" * (project_file.to_s.length + 4)}
          * #{project_file} *
          #{"*" * (project_file.to_s.length + 4)}

        EOS

        pager.write Diffy::Diff.new(repository_file.to_s, project_file.to_s, source: "files", context: 3).to_s(:color)
      end
    end
  when "patch"
    changed_files.each do |repository_file, project_file|
      puts Diffy::Diff.new(repository_file.to_s, project_file.to_s, source: "files", context: 0, include_diff_info: true)
    end
  else
    logger.error "Unknown format: #{context.input[:format]}"
  end
end