Skip to content

Add diff subcommand for comparing labeled database snapshots - #37

Merged
Boomatang merged 10 commits into
mainfrom
dev
Jun 27, 2026
Merged

Add diff subcommand for comparing labeled database snapshots#37
Boomatang merged 10 commits into
mainfrom
dev

Conversation

@Boomatang

@Boomatang Boomatang commented Jun 26, 2026

Copy link
Copy Markdown
Owner

Closes #31

Summary

  • Adds a diff subcommand that compares two labeled snapshots stored in a SQLite database and categorises resources as added, updated, or removed between labels
  • Refactors the CLI from a single-command design into a subcommand architecture (get and diff)
  • Extracts shared concerns into dedicated modules: logging (log.zig), argument definitions (args.zig), and exclude matching (utils.zig)
  • Improves the --exclude flag to use case-insensitive full-string matching against both CRD resource name and resolved Kind name
  • Supports both TTY (table) and JSON output formats for the diff command
  • Fixes JSON output to include kind and apiVersion fields, and properly quotes resourceVersion
  • Fixes a null pointer issue when resourceVersion is absent

Acceptance Criteria

The issue asks for the ability to compare database results when two labels are passed, showing resources that are in one label but not the other, and printing the table of added or removed resources.

  • Compare results from database with two labels: The diff subcommand accepts two positional LABEL arguments and a --database flag, querying the SQLite database for differences between the two snapshots.
  • Show resources in one but not the other: The database layer implements added_sql and deleted_sql queries using NOT EXISTS subqueries to find resources present in one label but missing from the other.
  • Print table of added/removed resources: TTY output renders three colour-coded sections (Added, Updated, Removed) using the existing table renderer, with consistent column widths across all sections.
  • Beyond the original scope: The PR also detects updated resources (same identity, different resourceVersion or generation) and supports JSON output via --output=json.

Test Plan

  • Run diff with a database containing two labels and verify added, updated, and removed resources appear in the correct sections
  • Run diff --output=json and verify the JSON blob contains added, updated, and deleted arrays
  • Run diff with --exclude and verify case-insensitive Kind filtering works
  • Run get subcommand and verify existing functionality is unchanged
  • Run zig build test to confirm unit tests pass (table width and exclude matching)
  • Verify --help output at the top level shows get and diff subcommands
  • Verify diff --help shows diff-specific flags

The null pointers finally bit me, so they are now fixed.

Signed-off-by: Jim Fitzpatrick <jimfity@gmail.com>
Do a refactor that adds the basic set up for a diff command.

Signed-off-by: Jim Fitzpatrick <jimfity@gmail.com>
The logging configuration has being refactor to allow setting the
--log-level at any point in a command call.

Signed-off-by: Jim Fitzpatrick <jimfity@gmail.com>
Signed-off-by: Jim Fitzpatrick <jimfity@gmail.com>
Signed-off-by: Jim Fitzpatrick <jimfity@gmail.com>
Signed-off-by: Jim Fitzpatrick <jimfity@gmail.com>
This is the first attempt at the diff function. It currently only
supports printing to tty.

Signed-off-by: Jim Fitzpatrick <jimfity@gmail.com>
Signed-off-by: Jim Fitzpatrick <jimfity@gmail.com>
In the adding of the exclude flag to the diff command, the exclude
function on the get command was also improved.

Signed-off-by: Jim Fitzpatrick <jimfity@gmail.com>
A number of comments added in the pre-review process.

Signed-off-by: Jim Fitzpatrick <jimfity@gmail.com>
@Boomatang Boomatang changed the title Work in progess: Add diff command Add diff subcommand for comparing labeled database snapshots Jun 27, 2026
@Boomatang
Boomatang marked this pull request as ready for review June 27, 2026 01:53
@Boomatang
Boomatang merged commit b02bc1d into main Jun 27, 2026
2 checks passed
@Boomatang
Boomatang deleted the dev branch June 27, 2026 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Database diffs

1 participant