MCPcopy
hub / github.com/homeport/dyff

github.com/homeport/dyff @v1.12.0 sqlite

repository ↗ · DeepWiki ↗ · release v1.12.0 ↗
215 symbols 688 edges 27 files 54 documented · 25%
README

δyƒƒ /ˈdʏf/

License Go Report Card Tests Codecov Go Reference Release Packaging status

dyff

Description

A diff tool for YAML files, and sometimes JSON.

dyff is inspired by the way the old BOSH v1 deployment output reported changes from one version to another by only showing the parts of a YAML file that change.

Each difference is referenced by its location in the YAML document by using either the Spruce dot-style syntax (some.path.in.the.file) or go-patch path syntax (/some/name=path/in/the/id=file). The output report aims to be as compact as possible to give a clear and simple overview of the change.

Similar to the standard diff tool, it follows the principle of describing the change by going from the from input file to the target to input file.

Input files can be local files (filesystem path), remote files (URI), or the standard input stream (using -).

All orders of keys in hashes are preserved during processing and output to the terminal, most notably in the sub-commands to convert YAML to JSON and vice versa.

Command documentation

See command documentation for details about each command and its flags.

Use cases and examples

  • Show differences between the live configuration of Kubernetes resources and what would be applied (kubectl version >= v1.20.0):

```bash # Setup export KUBECTL_EXTERNAL_DIFF="dyff between --omit-header --set-exit-code"

# Usage kubectl diff [...] ```

dyff between example with kubectl diff

The --set-exit-code flag is required so that the dyff exit code matches kubectl expectations. An exit code 0 refers to no differences, 1 in case differences are detected. Other exit codes are treated as program issues.

Note: Versions of kubectl older than v1.20.0 did not split the environment variable into field, therefore you cannot use command arguments. In this case, you need to wrap the dyff command with its argument into a helper shell script and use this instead.

  • Show the differences between two versions of cf-deployment YAMLs:

    bash dyff between \ https://raw.githubusercontent.com/cloudfoundry/cf-deployment/v1.10.0/cf-deployment.yml \ https://raw.githubusercontent.com/cloudfoundry/cf-deployment/v1.20.0/cf-deployment.yml

    dyff between example

  • Embed dyff into Git for better understandable differences

    ```bash

    Setup...

    git config --local diff.dyff.command 'dyff_between() { dyff --color on between --omit-header "$2" "$5"; }; dyff_between' echo '*.yml diff=dyff' >> .gitattributes

    And have fun, e.g.:

    git log --ext-diff -u git show --ext-diff HEAD ```

    dyff between example of a Git commit

  • Convert a JSON stream to YAML

    bash sometool --json | jq --raw-output '.data' | dyff yaml -

  • Sometimes you end up with YAML or JSON files, where the order of the keys in maps was sorted alphabetically. With dyff you can restructure keys in maps to a more human appealing order:

    bash sometool --export --json | dyff yaml --restructure -

    Or, rewrite a file in place with the restructured order of keys.

    bash dyff yaml --restructure --in-place somefile.yml

  • Just print a YAML (or JSON) file to the terminal to look at it. By default, dyff will use a neat output schema which includes different colors and indent helper lines to improve readability. The colors are roughly based on the default Atom schema and work best on dark terminal backgrounds. The neat output is disabled if the output of dyff is redirected into a pipe, or you can disable it explicitly using the --plain flag.

    bash dyff yaml somefile.yml

  • Convert a YAML file to JSON and vice versa:

    bash dyff json https://raw.githubusercontent.com/cloudfoundry/cf-deployment/v1.19.0/cf-deployment.yml

    The dyff sub-command (yaml, or json) defines the output format, the tool automatically detects the input format itself.

    bash dyff yaml https://raw.githubusercontent.com/homeport/dyff/main/assets/bosh-yaml/manifest.json

Installation

FreeBSD

Install via ports:

cd /usr/ports/textproc/dyff
make install clean

Install via package (pkg):

pkg install dyff

Homebrew

The homeport/tap has macOS and GNU/Linux pre-built binaries available:

brew install homeport/tap/dyff

Mise

Using mise you could do:

mise use -g dyff@latest

MacPorts

On macOS, dyff is also available via MacPorts:

sudo port install dyff

Pre-built binaries in GitHub

Prebuilt binaries can be downloaded from the GitHub Releases section.

Curl To Shell Convenience Script

There is a convenience script to download the latest release for Linux or macOS if you want to need it simple (you need curl and jq installed on your machine):

curl --silent --location https://git.io/JYfAY | bash

Build from Source

Starting with Go 1.17, you can install dyff from source using go install:

go install github.com/homeport/dyff/cmd/dyff@latest

Please note: This will install dyff based on the latest available code base. Even though the goal is that the latest commit on the main branch should always be a stable and usable version, this is not the recommended way to install and use dyff. If you find an issue with this version, please make sure to note the commit SHA or date in the GitHub issue to indicate that it is not based on a released version. The version output will show dyff version (development) for go install based builds.

Contributing

We are happy to have other people contributing to the project. If you decide to do that, here's how to:

  • get Go (dyff requires Go version 1.23 or greater)
  • fork the project
  • create a new branch
  • make your changes
  • open a PR.

Git commit messages should be meaningful and follow the rules nicely written down by Chris Beams:

The seven rules of a great Git commit message

  1. Separate subject from body with a blank line
  2. Limit the subject line to 50 characters
  3. Capitalize the subject line
  4. Do not end the subject line with a period
  5. Use the imperative mood in the subject line
  6. Wrap the body at 72 characters
  7. Use the body to explain what and why vs. how

Running test cases and binaries generation

Run test cases:

ginkgo run ./...

Create binaries:

goreleaser build --clean --snapshot

License

Licensed under MIT License

Extension points exported contracts — how you extend this code

ReportWriter (Interface)
ReportWriter defines the interface required for types that can write reports [3 implementers]
pkg/dyff/models.go
ExitCode (Interface)
ExitCode is an error interface that has exit code (value) details [1 implementers]
internal/cmd/exitcode.go
Colorizer (Interface)
Colorizer is the interface for applying colors to diff output. Implement this to replace the default bunt-based coloring [1 …
pkg/dyff/colors.go
CompareOption (FuncType)
CompareOption sets a specific compare setting for the object comparison
pkg/dyff/core.go

Core symbols most depended-on inside this repo

WriteString
called by 61
pkg/dyff/output_human.go
CompareInputFiles
called by 30
pkg/dyff/core.go
String
called by 26
pkg/dyff/core_identifier.go
followAlias
called by 21
pkg/dyff/core.go
Error
called by 19
internal/cmd/exitcode.go
Yellowf
called by 15
pkg/dyff/colors.go
AsSequenceNode
called by 15
pkg/dyff/core.go
createStringWithPrefix
called by 12
pkg/dyff/output_human.go

Shape

Method 100
Function 89
Struct 20
Interface 5
FuncType 1

Languages

Go100%

Modules by API surface

pkg/dyff/core.go42 symbols
pkg/dyff/colors.go37 symbols
pkg/dyff/output_human.go30 symbols
pkg/dyff/core_suite_test.go30 symbols
pkg/dyff/core_identifier.go12 symbols
internal/cmd/common.go10 symbols
internal/cmd/exitcode.go8 symbols
internal/cmd/cmd_suite_test.go7 symbols
pkg/dyff/reports.go6 symbols
pkg/dyff/output_diff_syntax.go6 symbols
pkg/dyff/models.go5 symbols
internal/cmd/root.go5 symbols

Dependencies from manifests, versioned

github.com/BurntSushi/tomlv1.6.0 · 1×
github.com/Masterminds/semver/v3v3.4.0 · 1×
github.com/caarlos0/env/v11v11.4.0 · 1×
github.com/cpuguy83/go-md2man/v2v2.0.7 · 1×
github.com/davecgh/go-spewv1.1.2-0.20180830191 · 1×
github.com/go-logr/logrv1.4.3 · 1×
github.com/go-task/slim-sprig/v3v3.0.0 · 1×
github.com/gonvenience/buntv1.4.3 · 1×
github.com/gonvenience/idemv0.0.3 · 1×
github.com/gonvenience/neatv1.3.20 · 1×
github.com/gonvenience/termv1.0.5 · 1×
github.com/gonvenience/textv1.0.10 · 1×

For agents

$ claude mcp add dyff \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact