module

Tdiff

Tdiff is a CLI utility for comparing tree-like files (json/yaml).

You can check out the source code at github: https://github.com/aleandros/tdiff

There are three main layers to the structure of the application:

  • Tdiff::Arguments is in charge of handling user input and properly parse the given input files. The resulting data structure that's of interest is Tdiff::Tree, which is a general representation of a tree input source that ultimately feeds the core of the comparison algorithm.

  • Tdiff::Core handles the output from the Arguments layer and executes the appropriate comparisons, ultimately returning an Array(Tdiff::Core::Result). An individual Tdiff::Core::Result object contains the difference between the two leafs and the path that lead to them.

  • Tdiff::Presentation uses the array of result objects for presenting the data to the user, depending on the desired format.

This file serves as an entrypoint for the application, and essentially handles the arguments with OptionParser and connects the aforementioned layers.

Constants

VERSION = "0.2.1"

Class methods

compare(source : IO, target : IO)

This is the main entrypoint for using Tdiff as a library. It just requires a couple of IO objects, containing the YAML or JSON data, and returns a list of Tdiff:Core::Result objects.

require 'tdiff'

comparator = Tdiff.compare(File.open('target_1.yml'), File.open('target_2.yml'))
comparator.compare
comparator.results.each do |result|
  puts "#{result.path.join(".")}: #{result.difference.reason}"
end

If any of the inputs cannot be parsed, this method will raise a Tdiff::Exception error.

fail_with_help(message : String, parser : OptionParser)

Prints usage error in the program arguments and terminates the program.

A utility function that simply prints an error to STDERR and the program's help (since this should be used for indicating an error by the user in the provided) parameters.

main

This method is intended to be used for the CLI program. The reason is that by encapsulating it, tdiff can be required as a library, and the main.cr file actually calls this function.

Nested types