module Tdiff

Overview

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:

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

Defined in:

exception.cr
tdiff.cr

Constant Summary

VERSION = "0.2.1"

Class Method Summary

Class Method Detail

def self.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.


[View source]
def self.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.


[View source]
def self.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.


[View source]