Class: Uniword::DiffCLI

Inherits:
Thor
  • Object
show all
Includes:
CLIHelpers
Defined in:
lib/uniword/cli/diff_cli.rb

Overview

Diff subcommands for Uniword CLI.

Provides commands for comparing two DOCX files at the document level (text, formatting, structure) and package level (ZIP parts, XML structure, OPC validation).

Instance Method Summary collapse

Methods included from CLIHelpers

included

Instance Method Details

#compare(old_path, new_path) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/uniword/cli/diff_cli.rb', line 37

def compare(old_path, new_path)
  old_doc = load_document(old_path)
  new_doc = load_document(new_path)

  differ = Uniword::Diff::DocumentDiffer.new(
    old_doc, new_doc,
    options: build_differ_options
  )
  result = differ.diff

  formatter = Uniword::Diff::Formatter.new
  if options[:json]
    puts formatter.json(result)
  else
    puts formatter.terminal(result, verbose: options[:verbose])
  end

  exit result.empty? ? 0 : 1
rescue Uniword::Error => e
  handle_error(e)
rescue StandardError => e
  handle_error(e, verbose: options[:verbose])
end

#package(old_path, new_path) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/uniword/cli/diff_cli.rb', line 86

def package(old_path, new_path)
  validate_file_exists(old_path)
  validate_file_exists(new_path)

  differ = Uniword::Diff::PackageDiffer.new(
    old_path, new_path,
    canon: options[:canon]
  )
  result = differ.diff

  if options[:json]
    puts result.to_json
  else
    puts format_package_diff(result, verbose: options[:verbose])
  end

  exit result.empty? ? 0 : 1
rescue StandardError => e
  handle_error(e, verbose: options[:verbose])
end